if mode not in ['any', 'lookup', 'create']:
raise CFSError("Invalid mode: %s" % mode)
if self.exists and mode == 'create':
- raise CFSError("This %s already exists in configFS"
- % self.__class__.__name__)
+ raise CFSError("This %s already exists in configFS" %
+ self.__class__.__name__)
elif not self.exists and mode == 'lookup':
- raise CFSNotFound("No such %s in configfs: %s"
- % (self.__class__.__name__, self.path))
+ raise CFSNotFound("No such %s in configfs: %s" %
+ (self.__class__.__name__, self.path))
if not self.exists:
try:
os.mkdir(self.path)
except:
- raise CFSError("Could not create %s in configFS"
- % self.__class__.__name__)
+ raise CFSError("Could not create %s in configFS" %
+ self.__class__.__name__)
def _exists(self):
return os.path.isdir(self.path)
def _check_self(self):
if not self.exists:
- raise CFSNotFound("This %s does not exist in configFS"
- % self.__class__.__name__)
+ raise CFSNotFound("This %s does not exist in configFS" %
+ self.__class__.__name__)
def list_attrs(self, group, writable=None):
'''
with open(path, 'w') as file_fd:
file_fd.write(str(value))
except Exception as e:
- raise CFSError("Cannot enable attribute %s: %s (%s)" % (self.path, e, value))
+ raise CFSError("Cannot enable attribute %s: %s (%s)" %
+ (self.path, e, value))
self._enable = value
def delete(self):
os.rmdir(self.path)
path = property(_get_path,
- doc="Get the configFS object path.")
+ doc="Get the configFS object path.")
exists = property(_exists,
doc="Is True as long as the underlying configFS object exists. "
+ "If the underlying configFS objects gets deleted "
if not os.path.isdir(self.configfs_dir):
raise CFSError("%s does not exist. Giving up." %
- self.configfs_dir)
+ self.configfs_dir)
self._path = self.configfs_dir
self._create_in_cfs('lookup')
yield Subsystem(d, 'lookup')
subsystems = property(_list_subsystems,
- doc="Get the list of Subsystems.")
+ doc="Get the list of Subsystems.")
def save_to_file(self, savefile=None):
'''
return errors
def restore_from_file(self, savefile=None, clear_existing=True,
- abort_on_error=False):
+ abort_on_error=False):
'''
Restore the configuration from a file in json format.
Returns a list of non-fatal errors. If abort_on_error is set,
super(Subsystem, self).delete()
namespaces = property(_list_namespaces,
- doc="Get the list of Namespaces for the Subsystem.")
+ doc="Get the list of Namespaces for the Subsystem.")
@classmethod
def setup(cls, t, err_func):
self._nsid = nsid
self._path = "%s/namespaces/%d" % (self.subsystem.path, self.nsid)
self._create_in_cfs(mode)
- self.get_enable() # XXX should move to baseclass
+ self.get_enable() # XXX should move to baseclass
def _get_subsystem(self):
return self._subsystem
return self._nsid
subsystem = property(_get_subsystem,
- doc="Get the parent Subsystem object.")
- nsid = property(_get_nsid,
- doc="Get the NSID as an int.")
+ doc="Get the parent Subsystem object.")
+ nsid = property(_get_nsid, doc="Get the NSID as an int.")
@classmethod
def setup(cls, subsys, n, err_func):
def _init_group(self, group):
setattr(self.__class__, "ui_getgroup_%s" % group,
- lambda self, attr: self.cfnode.get_attr(group, attr))
-
+ lambda self, attr:
+ self.cfnode.get_attr(group, attr))
setattr(self.__class__, "ui_setgroup_%s" % group,
- lambda self, attr, value: self.cfnode.set_attr(group, attr, value))
+ lambda self, attr, value:
+ self.cfnode.set_attr(group, attr, value))
attrs = self.cfnode.list_attrs(group)
attrs_ro = self.cfnode.list_attrs(group, writable=False)
name = "ui_desc_%s" % group
t, d = getattr(self.__class__, name, {}).get(attr, ('string', ''))
self.define_config_group_param(group, attr, t, d, writable)
-
+
def refresh(self):
self._children = set([])
class UIRootNode(UINode):
def __init__(self, shell):
- UINode.__init__(self, '/', parent=None, cfnode=nvme.Root(), shell=shell)
+ UINode.__init__(self, '/', parent=None, cfnode=nvme.Root(),
+ shell=shell)
def refresh(self):
self._children = set([])
shell = configshell.shell.ConfigShell('~/.nvmetcli')
UIRootNode(shell)
except Exception as msg:
- shell.log.error(str(msg))
- return
+ shell.log.error(str(msg))
+ return
while not shell._exit:
try: