diff options
| author | Jerome Martin <jxm@risingtidesystems.com> | 2011-06-04 11:34:40 +0200 |
|---|---|---|
| committer | Jerome Martin <jxm@risingtidesystems.com> | 2011-06-04 13:21:57 +0200 |
| commit | 5491acd5416e589307336f35b3d1f379ee0a2317 (patch) | |
| tree | 707f9ddec2780bed777c57366d63f0ae1c523ef6 /rtsadmin | |
| parent | c68f4265a2810906227bb7e5f37bee711fb5b813 (diff) | |
| download | targetcli-5491acd5416e589307336f35b3d1f379ee0a2317.tar.gz | |
Merged UIAttributes/UIParameters to UIRTSLibNode.
* As a result all UIRTSLibNode have the capabilities to use attributes and
parameters.
* Added a couple of checks to actually enable the feature only if the
underlying rtslib node has attributes/parameters.
* Added the writable flag to the Attributes/Parameters.
Diffstat (limited to 'rtsadmin')
| -rw-r--r-- | rtsadmin/ui_backstore.py | 5 | ||||
| -rw-r--r-- | rtsadmin/ui_backstore_legacy.py | 5 | ||||
| -rw-r--r-- | rtsadmin/ui_node.py | 96 | ||||
| -rw-r--r-- | rtsadmin/ui_target.py | 10 |
4 files changed, 53 insertions, 63 deletions
diff --git a/rtsadmin/ui_backstore.py b/rtsadmin/ui_backstore.py index 2d4282f..af91e5c 100644 --- a/rtsadmin/ui_backstore.py +++ b/rtsadmin/ui_backstore.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ''' -from ui_node import UINode, UIAttributes, UIRTSLibNode +from ui_node import UINode, UIRTSLibNode from rtslib import RTSRoot from rtslib import FileIOBackstore, IBlockBackstore from rtslib import PSCSIBackstore, RDDRBackstore, RDMCPBackstore @@ -389,13 +389,12 @@ class UIIBlockBackstore(UIBackstore): % (name, dev)) return self.new_node(ui_so) -class UIStorageObject(UIRTSLibNode, UIAttributes): +class UIStorageObject(UIRTSLibNode): ''' A storage object UI. ''' def __init__(self, storage_object): UIRTSLibNode.__init__(self, storage_object) - UIAttributes.__init__(self, storage_object) self.name = storage_object.name self.cfs_cwd = storage_object.path self.refresh() diff --git a/rtsadmin/ui_backstore_legacy.py b/rtsadmin/ui_backstore_legacy.py index 828e49b..12c2cc1 100644 --- a/rtsadmin/ui_backstore_legacy.py +++ b/rtsadmin/ui_backstore_legacy.py @@ -7,7 +7,7 @@ Jerome Martin <jxm@risingtidesystems.com> Implements the rtsadmin backstores related UI. ''' -from ui_node import UINode, UIAttributes, UIRTSLibNode +from ui_node import UINode, UIRTSLibNode from rtslib import RTSRoot from rtslib import FileIOBackstore, IBlockBackstore from rtslib import PSCSIBackstore, RDDRBackstore, RDMCPBackstore @@ -476,13 +476,12 @@ class UIIBlockBackstoreLegacy(UIBackstoreLegacy): % (name, dev)) return self.new_node(ui_so) -class UIStorageObjectLegacy(UIRTSLibNode, UIAttributes): +class UIStorageObjectLegacy(UIRTSLibNode): ''' A storage object UI. ''' def __init__(self, storage_object): UIRTSLibNode.__init__(self, storage_object) - UIAttributes.__init__(self, storage_object) self.name = storage_object.name self.cfs_cwd = storage_object.path self.refresh() diff --git a/rtsadmin/ui_node.py b/rtsadmin/ui_node.py index 677d31c..d83f7d2 100644 --- a/rtsadmin/ui_node.py +++ b/rtsadmin/ui_node.py @@ -144,6 +144,34 @@ class UIRTSLibNode(UINode): UINode.__init__(self) self.rtsnode = rtslib_object + # If the rtsnode has parameters, use them + parameters = self.rtsnode.list_parameters() + parameters_ro = self.rtsnode.list_parameters(writable=False) + if parameters: + self._configuration_groups['parameter'] = {} + for parameter in parameters: + if parameter in parameters_ro: + writable = False + else: + writable = True + self._configuration_groups['parameter'][parameter] = \ + [self.ui_type_string, "The %s parameter." % parameter, + writable] + + # If the rtsnode has attributes, enable them + attributes = self.rtsnode.list_attributes() + attributes_ro = self.rtsnode.list_attributes(writable=False) + if attributes: + self._configuration_groups['attribute'] = {} + for attribute in attributes: + if attribute in attributes_ro: + writable = False + else: + writable = True + self._configuration_groups['attribute'][attribute] = \ + [self.ui_type_string, "The %s attribute." % attribute, + writable] + def execute_command(self, command, pparams=[], kparams={}): ''' Overrides the parent's execute_command() to check if the underlying @@ -158,22 +186,26 @@ class UIRTSLibNode(UINode): else: return UINode.execute_command(self, command, pparams, kparams) -class UIParameters(object): - ''' - A completely virtual class to implement UI methods for setting/getting - rtslib object parameters. Requires a set cfs_object parameter and calling - __init__(self, cfs_object, ). - ''' - def __init__(self, rtslib_object): + def ui_getgroup_attribute(self, attribute): ''' - Call from the class that inherits this, with the rtslib object that - should be queried for parameters. + This is the backend method for getting attributes. + @param attribute: The attribute to get the value of. + @type attribute: str + @return: The attribute's value + @rtype: arbitrary ''' - self.rtsnode = rtslib_object - self._configuration_groups['parameter'] = {} - for parameter in self.rtsnode.list_parameters(): - self._configuration_groups['parameter'][parameter] = \ - [self.ui_type_string, "The %s parameter." % parameter] + return self.rtsnode.get_attribute(attribute) + + def ui_setgroup_attribute(self, attribute, value): + ''' + This is the backend method for setting attributes. + @param attribute: The attribute to set the value of. + @type attribute: str + @param value: The attribute's value + @type value: arbitrary + ''' + self.assert_root() + self.rtsnode.set_attribute(attribute, value) def ui_getgroup_parameter(self, parameter): ''' @@ -196,40 +228,4 @@ class UIParameters(object): self.assert_root() self.rtsnode.set_parameter(parameter, value) -class UIAttributes(object): - ''' - A completely virtual class to implement UI methods for setting/getting - rtslib object attributes. Requires a set cfs_object attribute and calling - __init__(self, cfs_object, ). - ''' - def __init__(self, rtslib_object): - ''' - Call from the class that inherits this, with the rtslib object that - should be queried for attributes. - ''' - self.rtsnode = rtslib_object - self._configuration_groups['attribute'] = {} - for attribute in self.rtsnode.list_attributes(): - self._configuration_groups['attribute'][attribute] = \ - [self.ui_type_string, "The %s attribute." % attribute] - def ui_getgroup_attribute(self, attribute): - ''' - This is the backend method for getting attributes. - @param attribute: The attribute to get the value of. - @type attribute: str - @return: The attribute's value - @rtype: arbitrary - ''' - return self.rtsnode.get_attribute(attribute) - - def ui_setgroup_attribute(self, attribute, value): - ''' - This is the backend method for setting attributes. - @param attribute: The attribute to set the value of. - @type attribute: str - @param value: The attribute's value - @type value: arbitrary - ''' - self.assert_root() - self.rtsnode.set_attribute(attribute, value) diff --git a/rtsadmin/ui_target.py b/rtsadmin/ui_target.py index 523e6d3..e09f900 100644 --- a/rtsadmin/ui_target.py +++ b/rtsadmin/ui_target.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ''' -from ui_node import UINode, UIRTSLibNode, UIAttributes, UIParameters +from ui_node import UINode, UIRTSLibNode from ui_backstore import dedup_so_name from rtslib import RTSLibError, RTSLibBrokenLink, utils from rtslib import NodeACL, NetworkPortal, MappedLUN @@ -282,14 +282,12 @@ class UIMultiTPGTarget(UIRTSLibNode): else: return completions -class UITPG(UIRTSLibNode, UIAttributes, UIParameters): +class UITPG(UIRTSLibNode): ''' A generic TPG UI. ''' def __init__(self, tpg): UIRTSLibNode.__init__(self, tpg) - UIAttributes.__init__(self, tpg) - UIParameters.__init__(self, tpg) self.name = "tpgt%d" % tpg.tag self.cfs_cwd = tpg.path self.refresh() @@ -465,14 +463,12 @@ class UINodeACLs(UINode): else: return completions -class UINodeACL(UIRTSLibNode, UIAttributes, UIParameters): +class UINodeACL(UIRTSLibNode): ''' A generic UI for a node ACL. ''' def __init__(self, node_acl): UIRTSLibNode.__init__(self, node_acl) - UIAttributes.__init__(self, node_acl) - UIParameters.__init__(self, node_acl) self.name = node_acl.node_wwn self.cfs_cwd = node_acl.path |
