def terminate_connection(self, volume, connector, **kwargs): """Unmap an InfiniBox volume from the host""" infinidat_volume = self._get_infinidat_volume(volume) if self._protocol == 'FC': volume_type = 'fibre_channel' ports = [wwn.WWN(wwpn) for wwpn in connector['wwpns']] else: volume_type = 'iscsi' ports = [iqn.IQN(connector['initiator'])] result_data = dict() for port in ports: host_name = self._make_host_name(port) host = self._system.hosts.safe_get(name=host_name) if host is None: # not found. ignore. continue # unmap try: host.unmap_volume(infinidat_volume) except KeyError: continue # volume mapping not found # check if the host now doesn't have mappings if host is not None and len(host.get_luns()) == 0: host.safe_delete() if self._protocol == 'FC': # Create initiator-target mapping to delete host entry target_wwpns = list(self._get_online_fc_ports()) target_wwpns, target_map = self._build_initiator_target_map( connector, target_wwpns) result_data = dict(target_wwn=target_wwpns, initiator_target_map=target_map) return dict(driver_volume_type=volume_type, data=result_data)
def _get_ports_from_connector(self, infinidat_volume, connector): if connector is None: # If no connector was provided it is a force-detach - remove all # host connections for the volume if self._protocol == 'FC': port_cls = wwn.WWN else: port_cls = iqn.IQN ports = [] for lun_mapping in infinidat_volume.get_logical_units(): host_ports = lun_mapping.get_host().get_ports() host_ports = [port for port in host_ports if isinstance(port, port_cls)] ports.extend(host_ports) elif self._protocol == 'FC': ports = [wwn.WWN(wwpn) for wwpn in connector['wwpns']] else: ports = [iqn.IQN(connector['initiator'])] return ports
def _initialize_connection_iscsi(self, volume, connector): volume_name = self._make_volume_name(volume) infinidat_volume = self._get_infinidat_volume_by_name(volume_name) port = iqn.IQN(connector['initiator']) infinidat_host = self._get_or_create_host(port) if self.configuration.use_chap_auth: chap_username = (self.configuration.chap_username or vol_utils.generate_username()) chap_password = (self.configuration.chap_password or vol_utils.generate_password()) infinidat_host.update_fields( security_method='CHAP', security_chap_inbound_username=chap_username, security_chap_inbound_secret=chap_password) mapping = self._get_or_create_mapping(infinidat_host, infinidat_volume) lun = mapping.get_lun() netspace_names = self.configuration.infinidat_iscsi_netspaces target_portals = [] target_iqns = [] target_luns = [] for netspace_name in netspace_names: netspace = self._get_iscsi_network_space(netspace_name) target_portals.append(self._get_iscsi_portal(netspace)) target_iqns.append(netspace.get_properties().iscsi_iqn) target_luns.append(lun) result_data = dict(target_discovered=True, target_portal=target_portals[0], target_iqn=target_iqns[0], target_lun=target_luns[0]) if len(target_portals) > 1: # multiple network spaces defined result_data.update( dict(target_portals=target_portals, target_iqns=target_iqns, target_luns=target_luns)) if self.configuration.use_chap_auth: result_data.update( dict(auth_method='CHAP', auth_username=chap_username, auth_password=chap_password)) return dict(driver_volume_type='iscsi', data=result_data)