diff options
Diffstat (limited to 'rtslib/tcm.py')
-rw-r--r-- | rtslib/tcm.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/rtslib/tcm.py b/rtslib/tcm.py index a408b73..377f576 100644 --- a/rtslib/tcm.py +++ b/rtslib/tcm.py @@ -18,6 +18,7 @@ under the License. ''' import os +import stat import re import glob import resource @@ -740,6 +741,25 @@ class BlockStorageObject(StorageObject): return d +class StorageObjectFactory(object): + """ + Create a storage object based on a given path. + Only works for file & block. + """ + + def __new__(cls, path): + path = os.path.realpath(path) + name = path.strip("/").replace("/", "-") + if os.path.exists(path): + s = os.stat(path) + if stat.S_ISBLK(s.st_mode): + return BlockStorageObject(name=name, dev=path) + elif stat.S_ISREG(s.st_mode): + return FileIOStorageObject(name=name, dev=path, size=s.st_size) + + raise RTSLibError("Can't create storageobject from path: %s" % path) + + bs_params = { PSCSIStorageObject: dict(name='pscsi'), RDMCPStorageObject: dict(name='ramdisk', alt_dirprefix='rd_mcp'), |