From 1f211ca7775f542cfcd501a160f72a35911f06ab Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Sun, 1 Mar 2015 21:08:32 +0100 Subject: [PATCH] python: fix pep8 E302, add missing lines Signed-off-by: Danny Al-Gaaf --- src/pybind/ceph_argparse.py | 35 ++++++++++++++++++++++++++++++++++- src/pybind/ceph_rest_api.py | 9 ++++++++- src/pybind/cephfs.py | 15 +++++++++++++++ src/pybind/rados.py | 31 ++++++++++++++++++++++++++++++- src/pybind/rbd.py | 24 ++++++++++++++++++++++++ src/script/perf-watch.py | 1 + 6 files changed, 112 insertions(+), 3 deletions(-) diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 3d202da5bcdef..6976f2e978dcc 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -20,48 +20,56 @@ import sys import types import uuid + class ArgumentError(Exception): """ Something wrong with arguments """ pass + class ArgumentNumber(ArgumentError): """ Wrong number of a repeated argument """ pass + class ArgumentFormat(ArgumentError): """ Argument value has wrong format """ pass + class ArgumentValid(ArgumentError): """ Argument value is otherwise invalid (doesn't match choices, for instance) """ pass + class ArgumentTooFew(ArgumentError): """ Fewer arguments than descriptors in signature; may mean to continue the search, so gets a special exception type """ + class ArgumentPrefix(ArgumentError): """ Special for mismatched prefix; less severe, don't report by default """ pass + class JsonFormat(Exception): """ some syntactic or semantic issue with the JSON """ pass + class CephArgtype(object): """ Base class for all Ceph argument types @@ -110,6 +118,7 @@ class CephArgtype(object): """ return '<{0}>'.format(self.__class__.__name__) + class CephInt(CephArgtype): """ range-limited integers, [+|-][0-9]+ or 0x[0-9a-f]+ @@ -178,6 +187,7 @@ class CephFloat(CephArgtype): r = '[{0}-{1}]'.format(self.range[0], self.range[1]) return ''.format(r) + class CephString(CephArgtype): """ String; pretty generic. goodchars is a RE char class of valid chars @@ -207,6 +217,7 @@ class CephString(CephArgtype): b += '(goodchars {0})'.format(self.goodchars) return ''.format(b) + class CephSocketpath(CephArgtype): """ Admin socket path; check that it's readable and S_ISSOCK @@ -220,6 +231,7 @@ class CephSocketpath(CephArgtype): def __str__(self): return '' + class CephIPAddr(CephArgtype): """ IP address (v4 or v6) with optional port @@ -273,6 +285,7 @@ class CephIPAddr(CephArgtype): def __str__(self): return '' + class CephEntityAddr(CephIPAddr): """ EntityAddress, that is, IP address[/nonce] @@ -300,6 +313,7 @@ class CephEntityAddr(CephIPAddr): def __str__(self): return '' + class CephPoolname(CephArgtype): """ Pool name; very little utility @@ -307,6 +321,7 @@ class CephPoolname(CephArgtype): def __str__(self): return '' + class CephObjectname(CephArgtype): """ Object name. Maybe should be combined with Pool name as they're always @@ -315,6 +330,7 @@ class CephObjectname(CephArgtype): def __str__(self): return '' + class CephPgid(CephArgtype): """ pgid, in form N.xxx (N = pool number, xxx = hex pgnum) @@ -334,6 +350,7 @@ class CephPgid(CephArgtype): def __str__(self): return '' + class CephName(CephArgtype): """ Name (type.id) where: @@ -369,6 +386,7 @@ class CephName(CephArgtype): def __str__(self): return '' + class CephOsdName(CephArgtype): """ Like CephName, but specific to osds: allow alone @@ -401,6 +419,7 @@ class CephOsdName(CephArgtype): def __str__(self): return '' + class CephChoices(CephArgtype): """ Set of string literals; init with valid choices @@ -429,6 +448,7 @@ class CephChoices(CephArgtype): else: return '{0}'.format('|'.join(self.strings)) + class CephFilepath(CephArgtype): """ Openable file @@ -444,6 +464,7 @@ class CephFilepath(CephArgtype): def __str__(self): return '' + class CephFragment(CephArgtype): """ 'Fragment' ??? XXX @@ -588,12 +609,14 @@ class argdesc(object): s = '{' + s + '}' return s + def concise_sig(sig): """ Return string representation of sig useful for syntax reference in help """ return ' '.join([d.helpstr() for d in sig]) + def descsort(sh1, sh2): """ sort descriptors by prefixes, defined as the concatenation of all simple @@ -601,6 +624,7 @@ def descsort(sh1, sh2): """ return cmp(concise_sig(sh1['sig']), concise_sig(sh2['sig'])) + def parse_funcsig(sig): """ parse a single descriptor (array of strings or dicts) into a @@ -693,6 +717,7 @@ def parse_json_funcsigs(s, consumer): sigdict[cmdtag] = cmd return sigdict + def validate_one(word, desc, partial=False): """ validate_one(word, desc, partial=False) @@ -707,6 +732,7 @@ def validate_one(word, desc, partial=False): if desc.N: desc.n = desc.numseen + 1 + def matchnum(args, signature, partial=False): """ matchnum(s, signature, partial=False) @@ -748,6 +774,7 @@ def matchnum(args, signature, partial=False): matchcnt += 1 return matchcnt + def get_next_arg(desc, args): ''' Get either the value matching key 'desc.name' or the next arg in @@ -773,6 +800,7 @@ def get_next_arg(desc, args): arg = arg[0] return arg + def store_arg(desc, d): ''' Store argument described by, and held in, thanks to valid(), @@ -797,6 +825,7 @@ def store_arg(desc, d): # if first CephPrefix or any other type, just set it d[desc.name] = desc.instance.val + def validate(args, signature, partial=False): """ validate(args, signature, partial=False) @@ -891,11 +920,13 @@ def validate(args, signature, partial=False): # Finally, success return d + def cmdsiglen(sig): sigdict = sig.values() assert len(sigdict) == 1 return len(sig.values()[0]['sig']) + def validate_command(sigdict, args, verbose=False): """ turn args into a valid dictionary ready to be sent off as JSON, @@ -976,6 +1007,7 @@ def validate_command(sigdict, args, verbose=False): return valid_dict + def find_cmd_target(childargs): """ Using a minimal validation, figure out whether the command @@ -1043,6 +1075,7 @@ def find_cmd_target(childargs): return 'mon', '' + def send_command(cluster, target=('mon', ''), cmd=None, inbuf='', timeout=0, verbose=False): """ @@ -1121,6 +1154,7 @@ def send_command(cluster, target=('mon', ''), cmd=None, inbuf='', timeout=0, return ret, outbuf, outs + def json_command(cluster, target=('mon', ''), prefix=None, argdict=None, inbuf='', timeout=0, verbose=False): """ @@ -1164,4 +1198,3 @@ def json_command(cluster, target=('mon', ''), prefix=None, argdict=None, return ret, outbuf, outs - diff --git a/src/pybind/ceph_rest_api.py b/src/pybind/ceph_rest_api.py index 77adbe7f9dc88..0e1473ab95e2d 100755 --- a/src/pybind/ceph_rest_api.py +++ b/src/pybind/ceph_rest_api.py @@ -41,6 +41,7 @@ LOGLEVELS = { 'debug':logging.DEBUG, } + def find_up_osd(app): ''' Find an up OSD. Return the last one that's up. @@ -62,6 +63,7 @@ def find_up_osd(app): METHOD_DICT = {'r':['GET'], 'w':['PUT', 'DELETE']} + def api_setup(app, conf, cluster, clientname, clientid, args): ''' This is done globally, and cluster connection kept open for @@ -247,7 +249,6 @@ def generate_url_and_params(app, sig, flavor): # # end setup (import-time) functions, begin request-time functions # - def concise_sig_for_uri(sig, flavor): ''' Return a generic description of how one would send a REST request for sig @@ -267,6 +268,7 @@ def concise_sig_for_uri(sig, flavor): ret += '?' + '&'.join(args) return ret + def show_human_help(prefix): ''' Dump table showing commands matching prefix @@ -301,6 +303,7 @@ def show_human_help(prefix): else: return '' + @app.before_request def log_request(): ''' @@ -309,10 +312,12 @@ def log_request(): app.logger.info(flask.request.url + " from " + flask.request.remote_addr + " " + flask.request.user_agent.string) app.logger.debug("Accept: %s", flask.request.accept_mimetypes.values()) + @app.route('/') def root_redir(): return flask.redirect(app.ceph_baseurl) + def make_response(fmt, output, statusmsg, errorcode): ''' If formatted output, cobble up a response object that contains the @@ -356,6 +361,7 @@ def make_response(fmt, output, statusmsg, errorcode): return flask.make_response(response, errorcode) + def handler(catchall_path=None, fmt=None, target=None): ''' Main endpoint handler; generic for every endpoint, including catchall. @@ -488,6 +494,7 @@ def handler(catchall_path=None, fmt=None, target=None): response.headers['Content-Type'] = contenttype return response + # # Main entry point from wrapper/WSGI server: call with cmdline args, # get back the WSGI app entry point diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index 574846fdc017a..b452be0d0b381 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -6,33 +6,43 @@ from ctypes import CDLL, c_char_p, c_size_t, c_void_p, c_int, c_long, c_uint, c_ from ctypes.util import find_library import errno + class Error(Exception): pass + class PermissionError(Error): pass + class ObjectNotFound(Error): pass + class NoData(Error): pass + class ObjectExists(Error): pass + class IOError(Error): pass + class NoSpace(Error): pass + class IncompleteWriteError(Error): pass + class LibCephFSStateError(Error): pass + def make_ex(ret, msg): """ Translate a libcephfs return code into an exception. @@ -58,6 +68,7 @@ def make_ex(ret, msg): else: return Error(msg + (": error code %d" % ret)) + class cephfs_statvfs(Structure): _fields_ = [("f_bsize", c_uint), ("f_frsize", c_uint), @@ -71,6 +82,7 @@ class cephfs_statvfs(Structure): ("f_flag", c_uint), ("f_namemax", c_uint)] + # struct timespec { # long int tv_sec; # long int tv_nsec; @@ -79,6 +91,7 @@ class cephfs_timespec(Structure): _fields_ = [('tv_sec', c_long), ('tv_nsec', c_long)] + # struct stat { # unsigned long st_dev; # unsigned long st_ino; @@ -115,6 +128,7 @@ class cephfs_stat(Structure): ('__unused2', c_long), ('__unused3', c_long) ] + def load_libcephfs(): """ Load the libcephfs shared library. @@ -130,6 +144,7 @@ def load_libcephfs(): except OSError as e: raise EnvironmentError("Unable to load libcephfs: %s" % e) + class LibCephFS(object): """libcephfs python wrapper""" def require_state(self, *args): diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 4caa269392651..d66d8763700f2 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -23,66 +23,82 @@ LIBRADOS_OP_FLAG_FADVISE_WILLNEED = 0x10 LIBRADOS_OP_FLAG_FADVISE_DONTNEED = 0x20 LIBRADOS_OP_FLAG_FADVISE_NOCACHE = 0x40 + class Error(Exception): """ `Error` class, derived from `Exception` """ pass + class InterruptedOrTimeoutError(Error): """ `InterruptedOrTimeoutError` class, derived from `Error` """ pass + class PermissionError(Error): """ `PermissionError` class, derived from `Error` """ pass + class ObjectNotFound(Error): """ `ObjectNotFound` class, derived from `Error` """ pass + class NoData(Error): """ `NoData` class, derived from `Error` """ pass + class ObjectExists(Error): """ `ObjectExists` class, derived from `Error` """ pass + class ObjectBusy(Error): """ `ObjectBusy` class, derived from `Error` """ pass + class IOError(Error): """ `IOError` class, derived from `Error` """ pass + class NoSpace(Error): """ `NoSpace` class, derived from `Error` """ pass + class IncompleteWriteError(Error): """ `IncompleteWriteError` class, derived from `Error` """ pass + class RadosStateError(Error): """ `RadosStateError` class, derived from `Error` """ pass + class IoctxStateError(Error): """ `IoctxStateError` class, derived from `Error` """ pass + class ObjectStateError(Error): """ `ObjectStateError` class, derived from `Error` """ pass + class LogicError(Error): """ `` class, derived from `Error` """ pass + class TimedOut(Error): """ `TimedOut` class, derived from `Error` """ pass + def make_ex(ret, msg): """ Translate a librados return code into an exception. @@ -111,6 +127,7 @@ def make_ex(ret, msg): else: return Error(msg + (": errno %s" % errno.errorcode[ret])) + class rados_pool_stat_t(Structure): """ Usage information for a pool """ _fields_ = [("num_bytes", c_uint64), @@ -126,6 +143,7 @@ class rados_pool_stat_t(Structure): ("num_wr", c_uint64), ("num_wr_kb", c_uint64)] + class rados_cluster_stat_t(Structure): """ Cluster-wide usage information """ _fields_ = [("kb", c_uint64), @@ -133,6 +151,7 @@ class rados_cluster_stat_t(Structure): ("kb_avail", c_uint64), ("num_objects", c_uint64)] + class timeval(Structure): _fields_ = [("tv_sec", c_long), ("tv_usec", c_long)] @@ -147,6 +166,7 @@ class Version(object): def __str__(self): return "%d.%d.%d" % (self.major, self.minor, self.extra) + class RadosThread(threading.Thread): def __init__(self, target, args=None): self.args = args @@ -159,6 +179,7 @@ class RadosThread(threading.Thread): # time in seconds between each call to t.join() for child thread POLL_TIME_INCR = 0.5 + def run_in_thread(target, args, timeout=0): interrupt = False @@ -194,6 +215,7 @@ def run_in_thread(target, args, timeout=0): t.retval = -errno.EINTR return t.retval + class Rados(object): """librados python wrapper""" def require_state(self, *args): @@ -784,6 +806,7 @@ Rados object in state %s." % self.state) if ret < 0: raise make_ex(ret, "error blacklisting client '%s'" % client_address) + class ObjectIterator(object): """rados.Ioctx Object iterator""" def __init__(self, ioctx): @@ -817,6 +840,7 @@ class ObjectIterator(object): def __del__(self): run_in_thread(self.ioctx.librados.rados_nobjects_list_close, (self.ctx,)) + class XattrIterator(object): """Extended attribute iterator""" def __init__(self, ioctx, it, oid): @@ -851,6 +875,7 @@ in '%s'" % self.oid) def __del__(self): run_in_thread(self.ioctx.librados.rados_getxattrs_end, (self.it,)) + class SnapIterator(object): """Snapshot iterator""" def __init__(self, ioctx): @@ -900,6 +925,7 @@ ioctx '%s'" % self.ioctx.name) self.cur_snap = self.cur_snap + 1 return snap + class Snap(object): """Snapshot object""" def __init__(self, ioctx, name, snap_id): @@ -925,6 +951,7 @@ class Snap(object): raise make_ex(ret, "rados_ioctx_snap_get_stamp error") return datetime.fromtimestamp(snap_time.value) + class Completion(object): """completion object""" def __init__(self, ioctx, rados_comp, oncomplete, onsafe, @@ -1020,6 +1047,7 @@ class Completion(object): RADOS_CB = CFUNCTYPE(c_int, c_void_p, c_void_p) + class Ioctx(object): """rados.Ioctx object""" def __init__(self, name, librados, io): @@ -1922,7 +1950,6 @@ returned %d, but should return zero on success." % (self.name, ret)) raise make_ex(ret, "Ioctx.rados_lock_exclusive(%s): failed to set lock %s on %s" % (self.name, name, key)) - def set_object_locator(func): def retfunc(self, *args, **kwargs): if self.locator_key is not None: @@ -1935,6 +1962,7 @@ def set_object_locator(func): return func(self, *args, **kwargs) return retfunc + def set_object_namespace(func): def retfunc(self, *args, **kwargs): if self.nspace is None: @@ -1946,6 +1974,7 @@ def set_object_namespace(func): return retval return retfunc + class Object(object): """Rados object wrapper, makes the object look like a file""" def __init__(self, ioctx, key, locator_key=None, nspace=None): diff --git a/src/pybind/rbd.py b/src/pybind/rbd.py index 334e4c750103c..8ce6adad50ab7 100644 --- a/src/pybind/rbd.py +++ b/src/pybind/rbd.py @@ -31,54 +31,71 @@ RBD_FEATURE_EXCLUSIVE_LOCK = 4 RBD_FLAG_OBJECT_MAP_INVALID = 1 + class Error(Exception): pass + class PermissionError(Error): pass + class ImageNotFound(Error): pass + class ImageExists(Error): pass + class IOError(Error): pass + class NoSpace(Error): pass + class IncompleteWriteError(Error): pass + class InvalidArgument(Error): pass + class LogicError(Error): pass + class ReadOnlyImage(Error): pass + class ImageBusy(Error): pass + class ImageHasSnapshots(Error): pass + class FunctionNotSupported(Error): pass + class ArgumentOutOfRange(Error): pass + class ConnectionShutdown(Error): pass + class Timeout(Error): pass + def make_ex(ret, msg): """ Translate a librbd return code into an exception. @@ -110,6 +127,7 @@ def make_ex(ret, msg): else: return Error(msg + (": error code %d" % ret)) + class rbd_image_info_t(Structure): _fields_ = [("size", c_uint64), ("obj_size", c_uint64), @@ -119,11 +137,13 @@ class rbd_image_info_t(Structure): ("parent_pool", c_int64), ("parent_name", c_char * 96)] + class rbd_snap_info_t(Structure): _fields_ = [("id", c_uint64), ("size", c_uint64), ("name", c_char_p)] + def load_librbd(): """ Load the librbd shared library. @@ -139,6 +159,7 @@ def load_librbd(): except OSError as e: raise EnvironmentError("Unable to load librbd: %s" % e) + class RBD(object): """ This class wraps librbd CRUD functions. @@ -320,6 +341,7 @@ class RBD(object): if ret != 0: raise make_ex(ret, 'error renaming image') + class Image(object): """ This class represents an RBD image. It is used to perform I/O on @@ -980,6 +1002,7 @@ written." % (self.name, ret, length)) if ret < 0: raise make_ex(ret, 'error unlocking image') + class DiffIterateCB(object): def __init__(self, cb): self.cb = cb @@ -988,6 +1011,7 @@ class DiffIterateCB(object): self.cb(offset, length, exists == 1) return 0 + class SnapIterator(object): """ Iterator over snapshot info for an image. diff --git a/src/script/perf-watch.py b/src/script/perf-watch.py index 826d4a499d7fe..0add1a9edd115 100755 --- a/src/script/perf-watch.py +++ b/src/script/perf-watch.py @@ -6,6 +6,7 @@ import logging import time import commands + def parse_args(): parser = argparse.ArgumentParser(description='watch ceph perf') parser.add_argument( -- 2.39.5