def disconnect_volume_fc(self, volume, connector): """Delete map between a volume and a host for FC.""" lun_id, _ = huawei_utils.get_volume_lun_id(self.rmt_client, volume) lungroup_id = None if connector is None or 'host' not in connector: host_name, wwns = huawei_utils.get_fc_mapping_info( self.rmt_client, lun_id) else: host_name = connector['host'] wwns = connector['wwpns'] LOG.info( 'terminate_connection_fc: volume: %(id)s, wwpns: %(wwns)s, ' 'lun_id: %(lunid)s.', { 'id': volume.id, 'wwns': wwns, 'lunid': lun_id }, ) hostid = huawei_utils.get_host_id(self.rmt_client, host_name) if hostid: mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid view_id = self.rmt_client.find_mapping_view(mapping_view_name) if view_id: lungroup_id = self.rmt_client.find_lungroup_from_map(view_id) if lun_id and self.rmt_client.check_lun_exist(lun_id): if lungroup_id: lungroup_ids = self.rmt_client.get_lungroupids_by_lunid(lun_id) if lungroup_id in lungroup_ids: self.rmt_client.remove_lun_from_lungroup( lungroup_id, lun_id) else: LOG.warning( "Lun is not in lungroup. " "Lun id: %(lun_id)s, " "lungroup id: %(lungroup_id)s", { "lun_id": lun_id, "lungroup_id": lungroup_id })
def connect_volume_fc(self, volume, connector): """Create map between a volume and a host for FC.""" wwns = connector['wwpns'] LOG.info( _LI('initialize_connection_fc, initiator: %(wwpns)s,' 'volume id: %(id)s.'), { 'wwpns': wwns, 'id': volume.id }) lun_id, _ = huawei_utils.get_volume_lun_id(self.rmt_client, volume) if not lun_id: msg = _("Can't get volume id. Volume name: %s.") % volume.id LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) original_host_name = connector['host'] # Create hostgroup if not exist. host_id = self.rmt_client.add_host_with_check(original_host_name) online_wwns_in_host = ( self.rmt_client.get_host_online_fc_initiators(host_id)) online_free_wwns = self.rmt_client.get_online_free_wwns() fc_initiators_on_array = self.rmt_client.get_fc_initiator_on_array() wwns = [i for i in wwns if i in fc_initiators_on_array] for wwn in wwns: if (wwn not in online_wwns_in_host and wwn not in online_free_wwns): wwns.remove(wwn) if (self.configuration.rmt_min_fc_ini_online == constants.DEFAULT_MINIMUM_FC_INITIATOR_ONLINE): wwns_in_host = ( self.rmt_client.get_host_fc_initiators(host_id)) iqns_in_host = ( self.rmt_client.get_host_iscsi_initiators(host_id)) if not (wwns_in_host or iqns_in_host): self.rmt_client.remove_host(host_id) msg = (("Can't add FC initiator %(wwn)s to host %(host)s," " please check if this initiator has been added " "to other host or isn't present on array.") % { "wwn": wwn, "host": host_id }) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) if len(wwns) < self.configuration.rmt_min_fc_ini_online: msg = (("The number of online fc initiator %(wwns)s less than" " the set %(set)s number.") % { "wwns": wwns, "set": self.configuration.rmt_min_fc_ini_online }) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) for wwn in wwns: self.rmt_client.ensure_fc_initiator_added(wwn, host_id, connector['host']) (tgt_port_wwns, init_targ_map) = (self.rmt_client.get_init_targ_map(wwns)) # Add host into hostgroup. hostgroup_id = self.rmt_client.add_host_to_hostgroup(host_id) map_info = self.rmt_client.do_mapping(lun_id, hostgroup_id, host_id, hypermetro_lun=True) if not map_info: msg = _('Map info is None due to array version ' 'not supporting hypermetro.') LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) host_lun_id = self.rmt_client.get_host_lun_id(host_id, lun_id) # Return FC properties. fc_info = { 'driver_volume_type': 'fibre_channel', 'data': { 'target_lun': int(host_lun_id), 'target_discovered': True, 'target_wwn': tgt_port_wwns, 'volume_id': volume.id, 'initiator_target_map': init_targ_map, 'map_info': map_info }, } LOG.info(_LI('Remote return FC info is: %s.'), fc_info) return fc_info
def disconnect_volume_fc(self, volume, connector): """Delete map between a volume and a host for FC.""" wwns = connector['wwpns'] lun_id, lun_wwn = huawei_utils.get_volume_lun_id( self.rmt_client, volume) host_name = connector['host'] left_lunnum = -1 lungroup_id = None view_id = None LOG.info( 'terminate_connection_fc: volume: %(id)s, ' 'wwpns: %(wwns)s, ' 'lun_id: %(lunid)s.', { 'id': volume.id, 'wwns': wwns, 'lunid': lun_id }, ) hostid = huawei_utils.get_host_id(self.rmt_client, host_name) if hostid: mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid view_id = self.rmt_client.find_mapping_view(mapping_view_name) if view_id: lungroup_id = self.rmt_client.find_lungroup_from_map(view_id) if lun_id and self.rmt_client.check_lun_exist(lun_id): if lungroup_id: lungroup_ids = self.rmt_client.get_lungroupids_by_lunid(lun_id) if lungroup_id in lungroup_ids: self.rmt_client.remove_lun_from_lungroup( lungroup_id, lun_id) else: LOG.warning( "Lun is not in lungroup. " "Lun id: %(lun_id)s, " "lungroup id: %(lungroup_id)s", { "lun_id": lun_id, "lungroup_id": lungroup_id }) (tgt_port_wwns, init_targ_map) = (self.rmt_client.get_init_targ_map(wwns)) hostid = huawei_utils.get_host_id(self.rmt_client, host_name) if hostid: mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid view_id = self.rmt_client.find_mapping_view(mapping_view_name) if view_id: lungroup_id = self.rmt_client.find_lungroup_from_map(view_id) if lungroup_id: left_lunnum = self.rmt_client.get_obj_count_from_lungroup( lungroup_id) if int(left_lunnum) > 0: info = {'driver_volume_type': 'fibre_channel', 'data': {}} else: info = { 'driver_volume_type': 'fibre_channel', 'data': { 'target_wwn': tgt_port_wwns, 'initiator_target_map': init_targ_map }, } return info
def connect_volume_fc(self, volume, connector): """Create map between a volume and a host for FC.""" wwns = connector['wwpns'] LOG.info( 'initialize_connection_fc, initiator: %(wwpns)s, ' 'volume id: %(id)s.', { 'wwpns': wwns, 'id': volume.id }) lun_id, lun_wwn = huawei_utils.get_volume_lun_id( self.rmt_client, volume) if lun_id is None: msg = _("Can't get volume id. Volume name: %s.") % volume.id LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) original_host_name = connector['host'] host_id = self.client.add_host_with_check(original_host_name) # Create hostgroup if not exist. host_id = self.rmt_client.add_host_with_check(original_host_name) online_wwns_in_host = ( self.rmt_client.get_host_online_fc_initiators(host_id)) online_free_wwns = self.rmt_client.get_online_free_wwns() for wwn in wwns: if (wwn not in online_wwns_in_host and wwn not in online_free_wwns): wwns_in_host = ( self.rmt_client.get_host_fc_initiators(host_id)) iqns_in_host = ( self.rmt_client.get_host_iscsi_initiators(host_id)) if not (wwns_in_host or iqns_in_host): self.rmt_client.remove_host(host_id) msg = _('Can not add FC port to host.') LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) for wwn in wwns: if wwn in online_free_wwns: self.rmt_client.add_fc_port_to_host(host_id, wwn) (tgt_port_wwns, init_targ_map) = (self.rmt_client.get_init_targ_map(wwns)) # Add host into hostgroup. hostgroup_id = self.rmt_client.add_host_to_hostgroup(host_id) map_info = self.rmt_client.do_mapping(lun_id, hostgroup_id, host_id, hypermetro_lun=True) if not map_info: msg = _('Map info is None due to array version ' 'not supporting hypermetro.') LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) host_lun_id = self.rmt_client.get_host_lun_id(host_id, lun_id) # Return FC properties. fc_info = { 'driver_volume_type': 'fibre_channel', 'data': { 'target_lun': int(host_lun_id), 'target_discovered': True, 'target_wwn': tgt_port_wwns, 'volume_id': volume.id, 'initiator_target_map': init_targ_map, 'map_info': map_info }, } LOG.info('Remote return FC info is: %s.', fc_info) return fc_info