-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use libgfapi, or fall back to the gluster CLI to fetch the volfile
- Loading branch information
Joe Julian
committed
Feb 24, 2015
1 parent
3181687
commit 4f9a2d1
Showing
4 changed files
with
57 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/python | ||
|
||
import ctypes | ||
import ctypes.util | ||
import subprocess | ||
|
||
def cli_get_volfile (host, volume): | ||
res = subprocess.check_output(["/usr/sbin/gluster","--remote-host={}".format(host), | ||
"system","getspec",volume]) | ||
return res | ||
|
||
def api_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] | ||
|
||
api = ctypes.CDLL(ctypes.util.find_library("gfapi")) | ||
try: | ||
api.glfs_get_volfile.argtypes = [ctypes.c_void_p, | ||
ctypes.c_void_p, | ||
ctypes.c_ulong] | ||
api.glfs_get_volfile.restype = ctypes.c_long; | ||
get_volfile = api_get_volfile | ||
except: | ||
get_volfile = cli_get_volfile | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
try: | ||
res = apply(get_volfile,sys.argv[1:3]) | ||
except: | ||
print "fetching volfile failed (volume not started?)" | ||
raise | ||
|
||
try: | ||
for line in res.split('\n'): | ||
print line | ||
except: | ||
print "bad return value %s" % res | ||
raise |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
# | ||
# Copyright 2014, Joe Julian <[email protected]> | ||
# | ||
import rpc.fetchvol | ||
import rpc | ||
import os,sys,re | ||
import tempfile | ||
import subprocess | ||
|
@@ -50,7 +50,7 @@ def main(): | |
print 'of that directory, or choose another directory.' | ||
exit(1) | ||
|
||
orig_vol = rpc.fetchvol.fetch_volfile(server, volume) | ||
orig_vol = rpc.get_volfile(server, volume) | ||
regex = re.compile(r'(^volume\s.+?end-volume)', re.VERBOSE|re.MULTILINE|re.DOTALL) | ||
graph = [ x.strip("\n") for x in regex.split(orig_vol) if x.strip("\n") ] | ||
newgraph = [] | ||
|