diff options
author | Andy Grover <agrover@redhat.com> | 2014-06-23 15:12:15 -0700 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2014-06-23 15:12:15 -0700 |
commit | 3ce39b02d167b169a44a276d70f3929733f7118e (patch) | |
tree | 2397b412d452f84f7176ea04be1e9294e47e306b | |
parent | 31dbea4ad06675257855f5e6acab94b8c7f6b584 (diff) | |
download | rtslib-fb-3ce39b02d167b169a44a276d70f3929733f7118e.tar.gz |
Consolidate two mapping dicts into one
The storageobjects and "mapping" dict in so_from_path are almost the same,
except for name/path divergences due to alt_dirprefix. Consolidate these
into one list, which works with a few duplicate entries.
Put the new so_mapping dict next to bs_params dict, so the places to touch
for new backstores are a little more centralized.
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | rtslib/root.py | 12 | ||||
-rw-r--r-- | rtslib/tcm.py | 20 |
2 files changed, 15 insertions, 17 deletions
diff --git a/rtslib/root.py b/rtslib/root.py index 391c35d..74e3a1b 100644 --- a/rtslib/root.py +++ b/rtslib/root.py @@ -25,18 +25,10 @@ import json from node import CFSNode from target import Target from fabric import FabricModule -from tcm import (StorageObject, FileIOStorageObject, BlockStorageObject, - PSCSIStorageObject, RDMCPStorageObject) +from tcm import so_mapping, StorageObject from utils import RTSLibError, RTSLibBrokenLink, modprobe, mount_configfs from utils import dict_remove, set_attributes -storageobjects = dict( - fileio=FileIOStorageObject, - block=BlockStorageObject, - pscsi=PSCSIStorageObject, - ramdisk=RDMCPStorageObject, - ) - default_save_file = "/etc/target/saveconfig.json" class RTSRoot(CFSNode): @@ -186,7 +178,7 @@ class RTSRoot(CFSNode): err_func("'name' not defined in storage object %d" % index) continue try: - so_cls = storageobjects[so['plugin']] + so_cls = so_mapping[so['plugin']] except KeyError: err_func("'plugin' not defined or invalid in storageobject %s" % so['name']) continue diff --git a/rtslib/tcm.py b/rtslib/tcm.py index 78aa422..9895517 100644 --- a/rtslib/tcm.py +++ b/rtslib/tcm.py @@ -107,15 +107,9 @@ class StorageObject(CFSNode): ''' Build a StorageObject of the correct type from a configfs path. ''' - mapping = dict( - fileio=FileIOStorageObject, - pscsi=PSCSIStorageObject, - iblock=BlockStorageObject, - rd_mcp=RDMCPStorageObject, - ) so_name = os.path.basename(path) so_type = path.split("/")[-2].rsplit("_", 1)[0] - return mapping[so_type](so_name) + return so_mapping[so_type](so_name) def _get_wwn(self): self._check_self() @@ -757,6 +751,18 @@ class StorageObjectFactory(object): raise RTSLibError("Can't create storageobject from path: %s" % path) +# Used to convert either dirprefix or plugin to the SO. Instead of two +# almost-identical dicts we just have some duplicate entries. +so_mapping = { + "pscsi": PSCSIStorageObject, + "rd_mcp": RDMCPStorageObject, + "ramdisk": RDMCPStorageObject, + "fileio": FileIOStorageObject, + "iblock": BlockStorageObject, + "block": BlockStorageObject, +} + + bs_params = { PSCSIStorageObject: dict(name='pscsi'), RDMCPStorageObject: dict(name='ramdisk', alt_dirprefix='rd_mcp'), |