diff options
Diffstat (limited to 'glusterfs')
-rwxr-xr-x | glusterfs/api.py | 15 | ||||
-rwxr-xr-x | glusterfs/gfapi.py | 62 |
2 files changed, 73 insertions, 4 deletions
diff --git a/glusterfs/api.py b/glusterfs/api.py index 7f22b4e..803a778 100755 --- a/glusterfs/api.py +++ b/glusterfs/api.py @@ -269,6 +269,15 @@ glfs_stat = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p, glfs_fstat = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.POINTER( Stat))(('glfs_fstat', client)) +glfs_chmod = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_void_p, + ctypes.c_char_p, + ctypes.c_ushort)(('glfs_chmod', client)) + +glfs_fchmod = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_void_p, + ctypes.c_ushort)(('glfs_fchmod', client)) + glfs_chown = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p, @@ -366,6 +375,12 @@ glfs_rmdir = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p)(('glfs_rmdir', client)) +glfs_setfsuid = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_uint)(('glfs_setfsuid', client)) + +glfs_setfsgid = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_uint)(('glfs_setfsgid', client)) + # TODO: creat and open fails on test_create_file_already_exists & test_open_file_not_exist functional testing, # noqa # when defined via function prototype.. Need to find RCA. For time being, using it from 'api.glfs_' # noqa diff --git a/glusterfs/gfapi.py b/glusterfs/gfapi.py index fc6bb27..42c4aef 100755 --- a/glusterfs/gfapi.py +++ b/glusterfs/gfapi.py @@ -65,6 +65,19 @@ class File(object): raise OSError(err, os.strerror(err)) return ret + def fchmod(self, mode): + """ + Change this file's mode + + :param mode: new mode + :returns: 0 if success, raises OSError if it fails + """ + ret = api.glfs_fchmod(self.fd, mode) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + def fchown(self, uid, gid): """ Change this file's owner and group id @@ -91,6 +104,12 @@ class File(object): raise OSError(err, os.strerror(err)) return ret + def fgetsize(self): + """ + Return the size of a file, reported by fstat() + """ + return self.fstat().st_size + def fstat(self): """ Returns Stat object for this file. @@ -124,9 +143,18 @@ class File(object): """ return api.glfs_lseek(self.fd, pos, how) - def read(self, buflen, flags=0): + def read(self, buflen=-1): + """ + read file + + :param buflen: length of read buffer. If less than 0, then whole + file is read. Default is -1. + :returns: buffer of size buflen + """ + if buflen < 0: + buflen = self.fgetsize() rbuf = ctypes.create_string_buffer(buflen) - ret = api.glfs_read(self.fd, rbuf, buflen, flags) + ret = api.glfs_read(self.fd, rbuf, buflen, 0) if ret > 0: return rbuf elif ret < 0: @@ -177,8 +205,6 @@ class Dir(object): class Volume(object): - # Housekeeping functions. - def __init__(self, host, volid, proto="tcp", port=24007): # Add a reference so the module-level variable "api" doesn't # get yanked out from under us (see comment above File def'n). @@ -196,6 +222,20 @@ class Volume(object): def mount(self): return api.glfs_init(self.fs) + def chmod(self, path, mode): + """ + Change mode of path + + :param path: the item to be modified + :mode: new mode + :returns: 0 if success, raises OSError if it fails + """ + ret = api.glfs_chmod(self.fs, path, mode) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + def chown(self, path, uid, gid): """ Change owner and group id of path @@ -441,6 +481,20 @@ class Volume(object): except OSError as e: onerror(self.rmdir, path, e) + def setfsuid(self, uid): + ret = api.glfs_setfsuid(uid) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + + def setfsgid(self, gid): + ret = api.glfs_setfsgid(gid) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + def setxattr(self, path, key, value, vlen): ret = api.glfs_setxattr(self.fs, path, key, value, vlen, 0) if ret < 0: |