pystorcli.enclosure
StorCLI enclosure python module
1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2018, Martin Dojcak <martin@dojcak.sk> 4# Copyright (c) 2022, Rafael Leira & Naudit HPCN S.L. <rafael.leira@naudit.es> 5# See LICENSE for details. 6 7'''StorCLI enclosure python module 8''' 9 10from . import StorCLI 11from . import common 12from . import controller 13from . import drive 14from . import exc 15 16 17class Enclosure(object): 18 """StorCLI enclosure 19 20 Instance of this class represents enclosure in StorCLI hierarchy 21 22 Args: 23 ctl_id (str): controller id 24 encl_id (str): enclosure id 25 binary (str): storcli binary or full path to the binary 26 27 Properties: 28 id (str): enclosure id 29 name (str): enclosure cmd name 30 facts (dict): raw enclosure facts 31 ctl_id (str): enclosure controller 32 ctl (:obj:controller.Controller): enclosure controller 33 has_drives (bool): true if enclosure has drives 34 drives (list of :obj:drive.Drive): enclosure drives 35 """ 36 37 def __init__(self, ctl_id, encl_id, binary='storcli64'): 38 """Constructor - create StorCLI Enclosure object 39 40 Args: 41 ctl_id (str): controller id 42 encl_id (str): enclosure id 43 binary (str): storcli binary or full path to the binary 44 """ 45 self._ctl_id = ctl_id 46 self._encl_id = encl_id 47 self._binary = binary 48 self._storcli = StorCLI(binary) 49 self._name = '/c{0}/e{1}'.format(self._ctl_id, self._encl_id) 50 51 self._exist() 52 53 def _run(self, args, **kwargs): 54 args = args[:] 55 args.insert(0, self._name) 56 return self._storcli.run(args, **kwargs) 57 58 def _exist(self): 59 try: 60 self._run(['show']) 61 except exc.StorCliCmdError: 62 raise exc.StorCliMissingError( 63 self.__class__.__name__, self._name) from None 64 65 @property 66 def id(self): 67 """(str): enclosure id 68 """ 69 return self._encl_id 70 71 @property 72 def name(self): 73 """(str): enclosure cmd name 74 """ 75 return self._name 76 77 @property 78 def facts(self): 79 """(dict): raw enclosure facts 80 """ 81 args = [ 82 'show', 83 'all' 84 ] 85 return common.response_data(self._run(args)) 86 87 @property 88 def ctl_id(self): 89 """(str): enclosure controller id 90 """ 91 return self._ctl_id 92 93 @property 94 def ctl(self): 95 """(:obj:controller.Controller): enclosure controller 96 """ 97 return controller.Controller(ctl_id=self._ctl_id, binary=self._binary) 98 99 @property 100 def has_drives(self): 101 """(bool): true if enclosure has drives 102 """ 103 args = [ 104 'show' 105 ] 106 107 pds = common.response_data(self._run(args))['Properties'][0]['PD'] 108 if pds == 0: 109 return False 110 return True 111 112 @property 113 def _slot_ids(self): 114 args = [ 115 '/c{0}/e{1}/sall'.format(self._ctl_id, self._encl_id), 116 'show' 117 ] 118 119 if not self.has_drives: 120 return [] 121 122 drives = common.response_data(self._storcli.run(args))[ 123 'Drive Information'] 124 return [drive['EID:Slt'].split(':')[1] for drive in drives] 125 126 @property 127 def drives(self): 128 """(list of :obj:drive.Drive): enclosure drives 129 """ 130 drives = [] 131 for slot_id in self._slot_ids: 132 drives.append( 133 drive.Drive( 134 ctl_id=self._ctl_id, 135 encl_id=self._encl_id, 136 slot_id=slot_id, 137 binary=self._binary 138 ) 139 ) 140 return drives 141 142 143class Enclosures(object): 144 """StorCLI enclosures 145 146 Instance of this class is iterable with :obj:Enclosure as item 147 148 Args: 149 ctl_id (str): controller id 150 binary (str): storcli binary or full path to the binary 151 152 Properties: 153 ids (list of str): list of enclosures id 154 ctl_id (str): enclosures controller id 155 ctl (:obj:controller.Controller): enclosures controller 156 157 158 Methods: 159 get_encl (:obj:Enclosure): return enclosure object by id 160 """ 161 162 def __init__(self, ctl_id, binary='storcli64'): 163 """Constructor - create StorCLI Enclosures object 164 165 Args: 166 ctl_id (str): controller id 167 binary (str): storcli binary or full path to the binary 168 """ 169 self._ctl_id = ctl_id 170 self._binary = binary 171 self._storecli = StorCLI(binary) 172 173 @property 174 def _encl_ids(self): 175 args = [ 176 '/c{0}/eall'.format(self._ctl_id), 177 'show' 178 ] 179 180 out = self._storecli.run(args) 181 return [encl['EID'] for encl in common.response_data(out)['Properties']] 182 183 @property 184 def _encls(self): 185 for encl_id in self._encl_ids: 186 yield Enclosure(ctl_id=self._ctl_id, encl_id=encl_id, binary=self._binary) 187 188 def __iter__(self): 189 return self._encls 190 191 @property 192 def ids(self): 193 """(list of str): list of enclosures id 194 """ 195 return self._encl_ids 196 197 @property 198 def ctl_id(self): 199 """(str): enclosures controller id 200 """ 201 return self._ctl_id 202 203 @property 204 def ctl(self): 205 """(:obj:controller.Controller): enclosures controller 206 """ 207 return controller.Controller(ctl_id=self._ctl_id, binary=self._binary) 208 209 def get_encl(self, encl_id): 210 """Get enclosure object by id 211 212 Args: 213 encl_id (str): enclosure id 214 215 Returns: 216 (None): no enclosure with id 217 (:obj:Enclosure): enclosure object 218 """ 219 for encl in self: 220 if encl.id == encl_id: 221 return encl 222 return None
18class Enclosure(object): 19 """StorCLI enclosure 20 21 Instance of this class represents enclosure in StorCLI hierarchy 22 23 Args: 24 ctl_id (str): controller id 25 encl_id (str): enclosure id 26 binary (str): storcli binary or full path to the binary 27 28 Properties: 29 id (str): enclosure id 30 name (str): enclosure cmd name 31 facts (dict): raw enclosure facts 32 ctl_id (str): enclosure controller 33 ctl (:obj:controller.Controller): enclosure controller 34 has_drives (bool): true if enclosure has drives 35 drives (list of :obj:drive.Drive): enclosure drives 36 """ 37 38 def __init__(self, ctl_id, encl_id, binary='storcli64'): 39 """Constructor - create StorCLI Enclosure object 40 41 Args: 42 ctl_id (str): controller id 43 encl_id (str): enclosure id 44 binary (str): storcli binary or full path to the binary 45 """ 46 self._ctl_id = ctl_id 47 self._encl_id = encl_id 48 self._binary = binary 49 self._storcli = StorCLI(binary) 50 self._name = '/c{0}/e{1}'.format(self._ctl_id, self._encl_id) 51 52 self._exist() 53 54 def _run(self, args, **kwargs): 55 args = args[:] 56 args.insert(0, self._name) 57 return self._storcli.run(args, **kwargs) 58 59 def _exist(self): 60 try: 61 self._run(['show']) 62 except exc.StorCliCmdError: 63 raise exc.StorCliMissingError( 64 self.__class__.__name__, self._name) from None 65 66 @property 67 def id(self): 68 """(str): enclosure id 69 """ 70 return self._encl_id 71 72 @property 73 def name(self): 74 """(str): enclosure cmd name 75 """ 76 return self._name 77 78 @property 79 def facts(self): 80 """(dict): raw enclosure facts 81 """ 82 args = [ 83 'show', 84 'all' 85 ] 86 return common.response_data(self._run(args)) 87 88 @property 89 def ctl_id(self): 90 """(str): enclosure controller id 91 """ 92 return self._ctl_id 93 94 @property 95 def ctl(self): 96 """(:obj:controller.Controller): enclosure controller 97 """ 98 return controller.Controller(ctl_id=self._ctl_id, binary=self._binary) 99 100 @property 101 def has_drives(self): 102 """(bool): true if enclosure has drives 103 """ 104 args = [ 105 'show' 106 ] 107 108 pds = common.response_data(self._run(args))['Properties'][0]['PD'] 109 if pds == 0: 110 return False 111 return True 112 113 @property 114 def _slot_ids(self): 115 args = [ 116 '/c{0}/e{1}/sall'.format(self._ctl_id, self._encl_id), 117 'show' 118 ] 119 120 if not self.has_drives: 121 return [] 122 123 drives = common.response_data(self._storcli.run(args))[ 124 'Drive Information'] 125 return [drive['EID:Slt'].split(':')[1] for drive in drives] 126 127 @property 128 def drives(self): 129 """(list of :obj:drive.Drive): enclosure drives 130 """ 131 drives = [] 132 for slot_id in self._slot_ids: 133 drives.append( 134 drive.Drive( 135 ctl_id=self._ctl_id, 136 encl_id=self._encl_id, 137 slot_id=slot_id, 138 binary=self._binary 139 ) 140 ) 141 return drives
StorCLI enclosure
Instance of this class represents enclosure in StorCLI hierarchy
Args: ctl_id (str): controller id encl_id (str): enclosure id binary (str): storcli binary or full path to the binary
Properties: id (str): enclosure id name (str): enclosure cmd name facts (dict): raw enclosure facts ctl_id (str): enclosure controller ctl (controller.Controller): enclosure controller has_drives (bool): true if enclosure has drives drives (list of drive.Drive): enclosure drives
38 def __init__(self, ctl_id, encl_id, binary='storcli64'): 39 """Constructor - create StorCLI Enclosure object 40 41 Args: 42 ctl_id (str): controller id 43 encl_id (str): enclosure id 44 binary (str): storcli binary or full path to the binary 45 """ 46 self._ctl_id = ctl_id 47 self._encl_id = encl_id 48 self._binary = binary 49 self._storcli = StorCLI(binary) 50 self._name = '/c{0}/e{1}'.format(self._ctl_id, self._encl_id) 51 52 self._exist()
Constructor - create StorCLI Enclosure object
Args: ctl_id (str): controller id encl_id (str): enclosure id binary (str): storcli binary or full path to the binary
144class Enclosures(object): 145 """StorCLI enclosures 146 147 Instance of this class is iterable with :obj:Enclosure as item 148 149 Args: 150 ctl_id (str): controller id 151 binary (str): storcli binary or full path to the binary 152 153 Properties: 154 ids (list of str): list of enclosures id 155 ctl_id (str): enclosures controller id 156 ctl (:obj:controller.Controller): enclosures controller 157 158 159 Methods: 160 get_encl (:obj:Enclosure): return enclosure object by id 161 """ 162 163 def __init__(self, ctl_id, binary='storcli64'): 164 """Constructor - create StorCLI Enclosures object 165 166 Args: 167 ctl_id (str): controller id 168 binary (str): storcli binary or full path to the binary 169 """ 170 self._ctl_id = ctl_id 171 self._binary = binary 172 self._storecli = StorCLI(binary) 173 174 @property 175 def _encl_ids(self): 176 args = [ 177 '/c{0}/eall'.format(self._ctl_id), 178 'show' 179 ] 180 181 out = self._storecli.run(args) 182 return [encl['EID'] for encl in common.response_data(out)['Properties']] 183 184 @property 185 def _encls(self): 186 for encl_id in self._encl_ids: 187 yield Enclosure(ctl_id=self._ctl_id, encl_id=encl_id, binary=self._binary) 188 189 def __iter__(self): 190 return self._encls 191 192 @property 193 def ids(self): 194 """(list of str): list of enclosures id 195 """ 196 return self._encl_ids 197 198 @property 199 def ctl_id(self): 200 """(str): enclosures controller id 201 """ 202 return self._ctl_id 203 204 @property 205 def ctl(self): 206 """(:obj:controller.Controller): enclosures controller 207 """ 208 return controller.Controller(ctl_id=self._ctl_id, binary=self._binary) 209 210 def get_encl(self, encl_id): 211 """Get enclosure object by id 212 213 Args: 214 encl_id (str): enclosure id 215 216 Returns: 217 (None): no enclosure with id 218 (:obj:Enclosure): enclosure object 219 """ 220 for encl in self: 221 if encl.id == encl_id: 222 return encl 223 return None
StorCLI enclosures
Instance of this class is iterable with Enclosure as item
Args: ctl_id (str): controller id binary (str): storcli binary or full path to the binary
Properties: ids (list of str): list of enclosures id ctl_id (str): enclosures controller id ctl (controller.Controller): enclosures controller
Methods: get_encl (Enclosure): return enclosure object by id
163 def __init__(self, ctl_id, binary='storcli64'): 164 """Constructor - create StorCLI Enclosures object 165 166 Args: 167 ctl_id (str): controller id 168 binary (str): storcli binary or full path to the binary 169 """ 170 self._ctl_id = ctl_id 171 self._binary = binary 172 self._storecli = StorCLI(binary)
Constructor - create StorCLI Enclosures object
Args: ctl_id (str): controller id binary (str): storcli binary or full path to the binary
210 def get_encl(self, encl_id): 211 """Get enclosure object by id 212 213 Args: 214 encl_id (str): enclosure id 215 216 Returns: 217 (None): no enclosure with id 218 (:obj:Enclosure): enclosure object 219 """ 220 for encl in self: 221 if encl.id == encl_id: 222 return encl 223 return None
Get enclosure object by id
Args: encl_id (str): enclosure id
Returns: (None): no enclosure with id (Enclosure): enclosure object