diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2012-07-16 13:44:08 -0400 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-07-18 12:45:10 -0700 |
commit | 67a85803b58ece292bbf50125b39b9e10db45320 (patch) | |
tree | 269a79fbbf66b5b491a2c6c707819053b8f15be3 /api/examples | |
parent | b324e317311974fbbb9ba13548364213a7a7a41a (diff) |
Example of using libglfs from Python.
Change-Id: I081582c457428d55db8ec1ed6d90f1e439f51f0d
BUG: 839950
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.com/3675
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'api/examples')
-rw-r--r-- | api/examples/gfapi.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/api/examples/gfapi.py b/api/examples/gfapi.py new file mode 100644 index 00000000000..e71a9866e65 --- /dev/null +++ b/api/examples/gfapi.py @@ -0,0 +1,29 @@ +import ctypes +import os +import sys + +# Looks like ctypes is having trouble with dependencies, so just force them to +# load with RTLD_GLOBAL until I figure that out. +glfs = ctypes.CDLL("libglusterfs.so",ctypes.RTLD_GLOBAL) +xdr = ctypes.CDLL("libgfxdr.so",ctypes.RTLD_GLOBAL) +api = ctypes.CDLL("api/libgfapi.so",ctypes.RTLD_GLOBAL) + +fs = api.glfs_new(sys.argv[1]) +api.glfs_set_logging(fs,"/dev/stderr",7) +api.glfs_set_volfile_server(fs,"socket","localhost",24007) +api.glfs_init(fs) +print "Initialized volume" + +fd = api.glfs_creat(fs,sys.argv[2],os.O_RDWR,0644) +print "Created file" + +# Read anything that's there from before. +rbuf = ctypes.create_string_buffer(32) +if api.glfs_read(fd,rbuf,32,0) > 0: + print "old data = %s" % rbuf.value + +# Write some new data. +api.glfs_lseek(fd,0,os.SEEK_SET) +wrote = api.glfs_write(fd,sys.argv[3],len(sys.argv[3]),0) +if wrote > 0: + print "wrote %d bytes" % wrote |