diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-03-04 16:53:33 +0000 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2014-03-05 21:29:42 -0800 |
commit | 1fbffa0aa45560889e29a74c4c6ff16d526de700 (patch) | |
tree | e723a7d539ba40812bdb98149ef2435d2ead175e /api/examples | |
parent | d6c1468b2779b6247e44b75276436021a3469a59 (diff) |
api: add glfs_get_volfile
From the API-header description:
> Sometimes it's useful e.g. for scripts to see the volfile, so that
> they can parse it and find subvolumes to do things like split-brain
> resolution or custom layouts. The API here was specifically intended
> to make access e.g. from Python as simple as possible.
>
> Note that the volume must be started (not necessarily mounted) for
> this to work.
Change-Id: If3f55ee9611cdf4b77aa53659f0af0d21957817d
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/7183
Reviewed-by: Anand Avati <avati@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'api/examples')
-rwxr-xr-x | api/examples/getvolfile.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/examples/getvolfile.py b/api/examples/getvolfile.py new file mode 100755 index 00000000000..82d9db05510 --- /dev/null +++ b/api/examples/getvolfile.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import ctypes +import ctypes.util + +api = ctypes.CDLL(ctypes.util.find_library("gfapi")) +api.glfs_get_volfile.argtypes = [ctypes.c_void_p, + ctypes.c_void_p, + ctypes.c_ulong] +api.glfs_get_volfile.restype = ctypes.c_long; + +def get_volfile (host, volume): + # This is set to a large value to exercise the "buffer not big enough" + # path. More realistically, you'd just start with a huge buffer. + BUF_LEN = 0 + fs = api.glfs_new(volume) + #api.glfs_set_logging(fs,"/dev/stderr",7) + api.glfs_set_volfile_server(fs,"tcp",host,24007) + api.glfs_init(fs) + vbuf = ctypes.create_string_buffer(BUF_LEN) + vlen = api.glfs_get_volfile(fs,vbuf,BUF_LEN) + if vlen < 0: + vlen = BUF_LEN - vlen + vbuf = ctypes.create_string_buffer(vlen) + vlen = api.glfs_get_volfile(fs,vbuf,vlen) + api.glfs_fini(fs) + if vlen <= 0: + return vlen + return vbuf.value[:vlen] + +if __name__ == "__main__": + import sys + + try: + res = apply(get_volfile,sys.argv[1:3]) + except: + print "fetching volfile failed (volume not started?)" + + try: + for line in res.split('\n'): + print line + except: + print "bad return value %s" % res |