diff options
author | Andy Grover <agrover@redhat.com> | 2012-06-11 12:06:52 -0700 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2012-06-11 12:06:52 -0700 |
commit | 02991e97e856297388d4c8523a7c7629263c2e03 (patch) | |
tree | 09e2c1e6adce2a929268e22f26cdc747abe5cbb8 | |
parent | 558e2c017cbaec46cca3a30dee5e9edb73a4fa33 (diff) | |
download | rtslib-fb-02991e97e856297388d4c8523a7c7629263c2e03.tar.gz |
Centralize .spec handling in target.py
Move spec_dir to target.py from node.py:CFSNode
Add an all() classmethod to return all FabricModules
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | rtslib/node.py | 2 | ||||
-rw-r--r-- | rtslib/root.py | 6 | ||||
-rw-r--r-- | rtslib/target.py | 16 |
3 files changed, 15 insertions, 9 deletions
diff --git a/rtslib/node.py b/rtslib/node.py index bc5f0ec..c234dfc 100644 --- a/rtslib/node.py +++ b/rtslib/node.py @@ -24,8 +24,6 @@ from utils import fread, fwrite, RTSLibError, RTSLibNotInCFS class CFSNode(object): - # Where do we store the fabric modules spec files ? - spec_dir = "/var/lib/target/fabric" # Where is the configfs base LIO directory ? configfs_dir = '/sys/kernel/config/target' diff --git a/rtslib/root.py b/rtslib/root.py index f391f14..25f992b 100644 --- a/rtslib/root.py +++ b/rtslib/root.py @@ -136,10 +136,8 @@ class RTSRoot(CFSNode): def _list_fabric_modules(self): self._check_self() - mod_names = [mod_name[:-5] for mod_name in os.listdir(self.spec_dir) - if mod_name.endswith('.spec')] - for name in mod_names: - yield FabricModule(name) + for mod in FabricModule.all(): + yield mod def __str__(self): return "rtslib" diff --git a/rtslib/target.py b/rtslib/target.py index 7bd3fd6..a4318fb 100644 --- a/rtslib/target.py +++ b/rtslib/target.py @@ -32,6 +32,9 @@ from utils import is_ipv6_address, is_ipv4_address from utils import fread, fwrite, generate_wwn, is_valid_wwn, exec_argv from utils import dict_remove, set_attributes, set_parameters +# Where do we store the fabric modules spec files ? +spec_dir = "/var/lib/target/fabric" + class FabricModule(CFSNode): ''' This is an interface to RTS Target Fabric Modules. @@ -45,6 +48,14 @@ class FabricModule(CFSNode): discovery_auth_attributes = set(["discovery_auth"]) target_names_excludes = version_attributes | discovery_auth_attributes + @classmethod + def all(cls): + mod_names = [mod_name[:-5] for mod_name in os.listdir(spec_dir) + if mod_name.endswith('.spec')] + for name in mod_names: + yield FabricModule(name) + + # FabricModule private stuff def __init__(self, name): ''' @@ -55,7 +66,7 @@ class FabricModule(CFSNode): ''' super(FabricModule, self).__init__() self.name = str(name) - self.spec = self._parse_spec() + self.spec = self._parse_spec(spec_dir+name+".spec") self._path = "%s/%s" % (self.configfs_dir, self.spec['configfs_group']) # FabricModule public stuff @@ -91,7 +102,7 @@ class FabricModule(CFSNode): # Create the configfs group self._create_in_cfs_ine('any') - def _parse_spec(self): + def _parse_spec(self, spec_file): ''' Parses the fabric module spec file. ''' @@ -106,7 +117,6 @@ class FabricModule(CFSNode): wwn_from_cmds_filter='', wwn_type='free') - spec_file = "%s/%s.spec" % (self.spec_dir, self.name) spec = ConfigObj(spec_file).dict() if spec: self.spec_file = spec_file |