diff options
author | Andy Grover <agrover@redhat.com> | 2014-10-01 14:58:41 -0700 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2014-10-01 14:58:41 -0700 |
commit | 3eb8920363201a425e8d77a9aa53efce9cffaf12 (patch) | |
tree | 5e76c36d91f77c566431ea467b4ce82e45a59422 | |
parent | 60d12a17883b584b0bc390f2acef89548d9c2088 (diff) | |
download | targetcli-3eb8920363201a425e8d77a9aa53efce9cffaf12.tar.gz |
Support for user-backed storage objects
Add support for defining user-backed storage objects.
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | targetcli/ui_backstore.py | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py index 623d5b9..227a91e 100644 --- a/targetcli/ui_backstore.py +++ b/targetcli/ui_backstore.py @@ -20,7 +20,7 @@ under the License. from ui_node import UINode, UIRTSLibNode from rtslib import RTSRoot from rtslib import FileIOStorageObject, BlockStorageObject -from rtslib import PSCSIStorageObject, RDMCPStorageObject +from rtslib import PSCSIStorageObject, RDMCPStorageObject, UserBackedStorageObject from rtslib import RTSLibError from rtslib.utils import get_block_type from configshell import ExecutionError @@ -108,6 +108,7 @@ class UIBackstores(UINode): UIRDMCPBackstore(self) UIFileIOBackstore(self) UIBlockBackstore(self) + UIUserBackedBackstore(self) class UIBackstore(UINode): @@ -249,6 +250,7 @@ class UIRDMCPBackstore(UIBackstore): % (name, size)) return self.new_node(ui_so) + class UIFileIOBackstore(UIBackstore): ''' FileIO backstore UI. @@ -366,6 +368,7 @@ class UIFileIOBackstore(UIBackstore): completions = [completions[0] + ' '] return completions + class UIBlockBackstore(UIBackstore): ''' Block backstore UI. @@ -401,6 +404,51 @@ class UIBlockBackstore(UIBackstore): completions = [completions[0] + ' '] return completions + +class UIUserBackedBackstore(UIBackstore): + ''' + User backstore UI. + ''' + def __init__(self, parent): + self.so_cls = UIUserBackedStorageObject + super(UIUserBackedBackstore, self).__init__('user', parent) + + def ui_command_create(self, name, size, config, level): + ''' + Creates a User-backed storage object. + + SIZE SYNTAX + =========== + - If size is an int, it represents a number of bytes. + - If size is a string, the following units can be used: + - B{B} or no unit present for bytes + - B{k}, B{K}, B{kB}, B{KB} for kB (kilobytes) + - B{m}, B{M}, B{mB}, B{MB} for MB (megabytes) + - B{g}, B{G}, B{gB}, B{GB} for GB (gigabytes) + - B{t}, B{T}, B{tB}, B{TB} for TB (terabytes) + + 'config' is a string that is used to configure which userspace handler + should be used for this object, and any additional configuration + information for that handler. For example, 'file/disk1.img' would + pass 'disk.img' to the 'file' handler, indicating the backing file + to use. + 'level' configures how many commands will be forwarded to the userspace + handler, versus being emulated in the kernel. '0' will result in + almost all SCSI opcodes being passed-through. '1' causes only I/O- + related opcodes to be passed-through, and the rest emulated. + ''' + + level = self.ui_eval_param(level, 'number', 0) + + size = human_to_bytes(size) + so = UserBackedStorageObject(name, size=size, config=config, level=level) + ui_so = UIUserBackedStorageObject(so, self) + self.setup_model_alias(so) + self.shell.log.info("Created user-backed storage object %s size %d." + % (name, size)) + return self.new_node(ui_so) + + class UIStorageObject(UIRTSLibNode): ''' A storage object UI. @@ -465,3 +513,15 @@ class UIBlockStorageObject(UIStorageObject): return ("%s (%s) %s%s %s" % (so.udev_path, bytes_to_human(so.size), ro_str, wb_str, so.status), True) + + +class UIUserBackedStorageObject(UIStorageObject): + def summary(self): + so = self.rtsnode + + if not so.config: + config_str = "(no config)" + else: + config_str = so.config + + return ("%s (%s) %s" % (config_str, bytes_to_human(so.size), so.status), True) |