/usr/share/pyshared/rtslib/root.py is in python-rtslib 2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | '''
Implements the RTSRoot class.
This file is part of RTSLib Community Edition.
Copyright (c) 2011 by RisingTide Systems LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3 (AGPLv3).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import re
import os
import glob
from node import CFSNode
from target import Target, FabricModule
from tcm import FileIOBackstore, IBlockBackstore
from tcm import PSCSIBackstore, RDDRBackstore, RDMCPBackstore
from utils import RTSLibError, RTSLibBrokenLink, flatten_nested_list, modprobe
class RTSRoot(CFSNode):
'''
This is an interface to the root of the configFS object tree.
Is allows one to start browsing Target and Backstore objects,
as well as helper methods to return arbitrary objects from the
configFS tree.
>>> import rtslib.root as root
>>> rtsroot = root.RTSRoot()
>>> rtsroot.path
'/sys/kernel/config/target'
>>> rtsroot.exists
True
>>> rtsroot.targets # doctest: +ELLIPSIS
[...]
>>> rtsroot.backstores # doctest: +ELLIPSIS
[...]
>>> rtsroot.tpgs # doctest: +ELLIPSIS
[...]
>>> rtsroot.storage_objects # doctest: +ELLIPSIS
[...]
>>> rtsroot.network_portals # doctest: +ELLIPSIS
[...]
'''
# The core target/tcm kernel module
target_core_mod = 'target_core_mod'
# RTSRoot private stuff
def __init__(self):
'''
Instanciate an RTSRoot object. Basically checks for configfs setup and
base kernel modules (tcm )
'''
super(RTSRoot, self).__init__()
modprobe(self.target_core_mod)
self._create_in_cfs_ine('any')
def _list_targets(self):
self._check_self()
targets = set([])
for fabric_module in self.fabric_modules:
targets.update(fabric_module.targets)
return targets
def _list_backstores(self):
self._check_self()
backstores = set([])
if os.path.isdir("%s/core" % self.path):
backstore_dirs = glob.glob("%s/core/*_*" % self.path)
for backstore_dir in [os.path.basename(path)
for path in backstore_dirs]:
regex = re.search("([a-z]+[_]*[a-z]+)(_)([0-9]+)",
backstore_dir)
if regex:
if regex.group(1) == "fileio":
backstores.add(
FileIOBackstore(int(regex.group(3)), 'lookup'))
elif regex.group(1) == "pscsi":
backstores.add(
PSCSIBackstore(int(regex.group(3)), 'lookup'))
elif regex.group(1) == "iblock":
backstores.add(
IBlockBackstore(int(regex.group(3)), 'lookup'))
elif regex.group(1) == "rd_dr":
backstores.add(
RDDRBackstore(int(regex.group(3)), 'lookup'))
elif regex.group(1) == "rd_mcp":
backstores.add(
RDMCPBackstore(int(regex.group(3)), 'lookup'))
return backstores
def _list_storage_objects(self):
self._check_self()
return set(flatten_nested_list([backstore.storage_objects
for backstore in self.backstores]))
def _list_tpgs(self):
self._check_self()
return set(flatten_nested_list([t.tpgs for t in self.targets]))
def _list_node_acls(self):
self._check_self()
return set(flatten_nested_list([t.node_acls for t in self.tpgs]))
def _list_network_portals(self):
self._check_self()
return set(flatten_nested_list([t.network_portals for t in self.tpgs]))
def _list_luns(self):
self._check_self()
return set(flatten_nested_list([t.luns for t in self.tpgs]))
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')]
modules = [FabricModule(mod_name) for mod_name in mod_names]
return modules
def _list_loaded_fabric_modules(self):
return [fm for fm in self._list_fabric_modules() if fm.exists]
def __str__(self):
return "rtsadmin"
# RTSRoot public stuff
backstores = property(_list_backstores,
doc="Get the list of Backstore objects.")
targets = property(_list_targets,
doc="Get the list of Target objects.")
tpgs = property(_list_tpgs,
doc="Get the list of all the existing TPG objects.")
node_acls = property(_list_node_acls,
doc="Get the list of all the existing NodeACL objects.")
network_portals = property(_list_network_portals,
doc="Get the list of all the existing Network Portal objects.")
storage_objects = property(_list_storage_objects,
doc="Get the list of all the existing Storage objects.")
luns = property(_list_luns,
doc="Get the list of all existing LUN objects.")
fabric_modules = property(_list_fabric_modules,
doc="Get the list of all FabricModule objects.")
loaded_fabric_modules = property(_list_loaded_fabric_modules,
doc="Get the list of all loaded FabricModule objects.")
def _test():
'''Run the doctests.'''
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
|