(k, v) for k, v in vars().items()
if k != 'self' and v is not None)
+class Command(dict):
+ """
+ Helper class to declare options for COMMANDS list.
+
+ It also allows to specify prefix and args separately, as well as storing a
+ handler callable.
+
+ Usage:
+ >>> Command(prefix="example",
+ ... args="name=arg,type=CephInt",
+ ... perm='w',
+ ... desc="Blah")
+ {'poll': False, 'cmd': 'example name=arg,type=CephInt', 'perm': 'w', 'desc': 'Blah'}
+ """
+
+ def __init__(
+ self,
+ prefix,
+ args=None,
+ perm="rw",
+ desc=None,
+ poll=False,
+ handler=None
+ ):
+ super(Command, self).__init__(
+ cmd=prefix + (' ' + args if args else ''),
+ perm=perm,
+ desc=desc,
+ poll=poll)
+ self.prefix = prefix
+ self.args = args
+ self.handler = handler
+
+ def register(self, instance=False):
+ """
+ Register a CLICommand handler. It allows an instance to register bound
+ methods. In that case, the mgr instance is not passed, and it's expected
+ to be available in the class instance.
+ It also uses HandleCommandResult helper to return a wrapped a tuple of 3
+ items.
+ """
+ return CLICommand(
+ prefix=self.prefix,
+ args=self.args,
+ desc=self['desc'],
+ perm=self['perm']
+ )(
+ func=lambda mgr, *args, **kwargs: HandleCommandResult(*self.handler(
+ *((instance or mgr,) + args), **kwargs))
+ )
+
class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
"""