def iscsi_chap_auth(self, init_id, in_user, in_password, out_user, out_password, flags=FLAG_RSVD): """ Register a user/password for the specified initiator for CHAP authentication. """ AccessGroup.initiator_id_verify(init_id, AccessGroup.INIT_TYPE_ISCSI_IQN, raise_exception=True) return self._tp.rpc('iscsi_chap_auth', _del_self(locals()))
def access_group_create(self, name, init_id, init_type, system, flags=0): """ Creates of access group """ if system.id != self.system.id: raise LsmError(ErrorNumber.NOT_FOUND_SYSTEM, "System %s not found" % system.id) if init_type != AccessGroup.INIT_TYPE_ISCSI_IQN: raise LsmError(ErrorNumber.NO_SUPPORT, "Nstor only support iSCSI Access Group") # Check that init_id is not a part of another hostgroup for ag in self.access_groups(): if init_id in ag.init_ids: raise LsmError( ErrorNumber.EXISTS_INITIATOR, "%s is already part of %s access group" % (init_id, ag.name)) if name == ag.name: raise LsmError(ErrorNumber.NAME_CONFLICT, "Access group with name exists!") self._request("create_hostgroup", "stmf", [name]) self._add_initiator(name, init_id) return AccessGroup(name, name, [init_id], init_type, system.id)
def access_group_initiator_add(self, access_group, init_id, init_type, flags=FLAG_RSVD): """ Adds an initiator to an access group """ init_type, init_id = AccessGroup.initiator_id_verify( init_id, init_type, raise_exception=True)[1:] return self._tp.rpc('access_group_initiator_add', _del_self(locals()))
def access_group_initiator_delete(self, access_group, init_id, init_type, flags=FLAG_RSVD): """ Deletes an initiator from an access group """ init_id = AccessGroup.initiator_id_verify(init_id, None, raise_exception=True)[2] return self._tp.rpc('access_group_initiator_delete', _del_self(locals()))
def access_group_create(self, name, init_id, init_type, system, flags=FLAG_RSVD): """ Creates an access group and add the specified initiator id, init_type and desired access. """ init_type, init_id = AccessGroup.initiator_id_verify( init_id, init_type, raise_exception=True)[1:] return self._tp.rpc('access_group_create', _del_self(locals()))
def lsm_init_id_to_snia(lsm_init_id): """ If lsm_init_id is a WWPN, convert it to SNIA format: [0-9A-F]{16} If not, return original directly. """ val, init_type, init_id = AccessGroup.initiator_id_verify(lsm_init_id) if val and init_type == AccessGroup.INIT_TYPE_WWPN: return lsm_init_id.replace(':', '').upper() return lsm_init_id
def cim_init_mg_to_lsm_ag(smis_common, cim_init_mg, system_id): """ Convert CIM_InitiatorMaskingGroup to lsm.AccessGroup """ ag_name = cim_init_mg['ElementName'] ag_id = md5(cim_init_mg['InstanceID']) cim_inits = cim_init_of_cim_init_mg_path(smis_common, cim_init_mg.path) (init_ids, init_type) = _init_id_and_type_of(cim_inits) plugin_data = cim_path_to_path_str(cim_init_mg.path) return AccessGroup(ag_id, ag_name, init_ids, init_type, system_id, plugin_data)
def cim_spc_to_lsm_ag(smis_common, cim_spc, system_id): """ Convert CIM_SCSIProtocolController to lsm.AccessGroup """ ag_id = md5(cim_spc['DeviceID']) ag_name = cim_spc['ElementName'] cim_inits = cim_init_of_cim_spc_path(smis_common, cim_spc.path) (init_ids, init_type) = _init_id_and_type_of(cim_inits) plugin_data = cim_path_to_path_str(cim_spc.path) return AccessGroup(ag_id, ag_name, init_ids, init_type, system_id, plugin_data)
def parse_convert_init(init_id): """ If init_id is a WWPN, convert it into LSM standard version: (?:[0-9a-f]{2}:){7}[0-9a-f]{2} Return (converted_init_id, lsm_init_type) """ valid, init_type, init_id = AccessGroup.initiator_id_verify(init_id) if valid: return (init_id, init_type) raise ArgError("--init-id %s is not a valid WWPN or iSCSI IQN" % init_id)
def access_groups(self, search_key=None, search_value=None, flags=0): """ Returns a list of access groups """ hg_list = self._request("list_hostgroups", "stmf", []) ag_list = [] for hg in hg_list: init_ids = self._request("list_hostgroup_members", "stmf", [hg]) ag_list.append( AccessGroup(hg, hg, init_ids, AccessGroup.INIT_TYPE_ISCSI_IQN, self.system.id)) return search_property(ag_list, search_key, search_value)
def access_group_initiator_delete(self, access_group, init_id, init_type, flags=0): """ Deletes an initiator from an access group """ init_ids = self._access_group_initiators(access_group) if init_id not in init_ids: # Already removed from requested group. return copy.deepcopy(access_group) self._add_initiator(access_group.name, init_id, True) init_ids = self._request("list_hostgroup_members", "stmf", [access_group.name]) return AccessGroup(access_group.id, access_group.name, init_ids, AccessGroup.INIT_TYPE_ISCSI_IQN, self.system.id)
def access_group_initiator_add(self, access_group, init_id, init_type, flags=0): """ Adds an initiator to an access group """ if init_type != AccessGroup.INIT_TYPE_ISCSI_IQN: raise LsmError(ErrorNumber.NO_SUPPORT, "Nstor only support iSCSI Access Group") init_ids = self._access_group_initiators(access_group) if init_id in init_ids: # Already in requested group. return copy.deepcopy(access_group) self._add_initiator(access_group.name, init_id) init_ids = self._request("list_hostgroup_members", "stmf", [access_group.name]) return AccessGroup(access_group.id, access_group.name, init_ids, AccessGroup.INIT_TYPE_ISCSI_IQN, self.system.id)
def access_groups(self, search_key=None, search_value=None, flags=0): """ Returns a list of access groups """ hg_list = self._request("list_hostgroups", "stmf", []) ag_list = [] for hg in hg_list: # The host group could get deleted out from under us, lets not # add this entry to the returned access groups if we error while # trying to retrieve the initiator IDs. try: init_ids = self._request("list_hostgroup_members", "stmf", [hg]) ag_list.append( AccessGroup(hg, hg, init_ids, AccessGroup.INIT_TYPE_ISCSI_IQN, self.system.id)) except LsmError as e: error('nstor:access_groups: %s' % str(e)) pass return search_property(ag_list, search_key, search_value)
def _tgt_init_to_lsm(tgt_init, sys_id): return AccessGroup( "%s%s" % (TargetdStorage._FAKE_AG_PREFIX, md5(tgt_init['init_id'])), 'N/A', [tgt_init['init_id']], AccessGroup.INIT_TYPE_ISCSI_IQN, sys_id)
def _tgt_ag_to_lsm(tgt_ag, sys_id): return AccessGroup(tgt_ag['name'], tgt_ag['name'], tgt_ag['init_ids'], AccessGroup.INIT_TYPE_ISCSI_IQN, sys_id)