diff options
author | Andy Grover <agrover@redhat.com> | 2015-02-03 16:55:20 -0800 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2015-02-03 16:55:20 -0800 |
commit | 0c3685df8d5dfb8b5cca3b5b47d2c7a722010688 (patch) | |
tree | 199b5414fc36e07568ade55d0c898dc53cf35aec /targetcli/ui_backstore.py | |
parent | eb801f5b5db0b10990094dfd179a8e2bd1c14ca4 (diff) | |
download | targetcli-user-backstore-poc.tar.gz |
proof-of-concept of dynamically loading a backstore instanceuser-backstore-poc
Diffstat (limited to 'targetcli/ui_backstore.py')
-rw-r--r-- | targetcli/ui_backstore.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py index 90708d9..a8b8b12 100644 --- a/targetcli/ui_backstore.py +++ b/targetcli/ui_backstore.py @@ -29,6 +29,8 @@ import os import stat import re +dynload_backstore_path = "/home/agrover/git/targetcli-fb/targetcli/dynbs_*" + def human_to_bytes(hsize, kilo=1024): ''' This function converts human-readable amounts of bytes to bytes. @@ -93,6 +95,7 @@ def complete_path(path, stat_fn): return sorted(filtered, key=lambda s: '~'+s if s.endswith('/') else s) + class UIBackstores(UINode): ''' The backstores container UI. @@ -107,7 +110,9 @@ class UIBackstores(UINode): UIRDMCPBackstore(self) UIFileIOBackstore(self) UIBlockBackstore(self) - UIUserBackedBackstore(self) + + for entry in dyn_bs_list: + entry(self) class UIBackstore(UINode): @@ -182,6 +187,21 @@ class UIBackstore(UINode): " emulate_model_alias\n not supported by kernel.") +class UIUserBackstore(UIBackstore): + ''' + Common code for user-backed backstores + Abstract Base Class, do not instantiate. + ''' + def summary(self): + return ("User-backed Storage Objects: %d" % len(self._children), None) + + def refresh(self): + self._children = set([]) + for so in RTSRoot().storage_objects: + if so.plugin == 'user' and so.config.startswith(self.name + '/'): + ui_so = self.so_cls(so, self) + + class UIPSCSIBackstore(UIBackstore): ''' PSCSI backstore UI. @@ -552,3 +572,11 @@ class UIUserBackedStorageObject(UIStorageObject): config_str = so.config return ("%s (%s) %s" % (config_str, bytes_to_human(so.size), so.status), True) + + +dyn_bs_list = [] +def new_backstore(bs_cls): + dyn_bs_list.append(bs_cls) + +for file in glob.iglob(dynload_backstore_path): + execfile(file) |