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 _initialize_connection_fc(self, volume, connector): volume_name = self._make_volume_name(volume) infinidat_volume = self._get_infinidat_volume_by_name(volume_name) ports = [wwn.WWN(wwpn) for wwpn in connector['wwpns']] for port in ports: infinidat_host = self._get_or_create_host(port) mapping = self._get_or_create_mapping(infinidat_host, infinidat_volume) lun = mapping.get_lun() # Create initiator-target mapping. target_wwpns = list(self._get_online_fc_ports()) target_wwpns, init_target_map = self._build_initiator_target_map( connector, target_wwpns) return dict(driver_volume_type='fibre_channel', data=dict(target_discovered=False, target_wwn=target_wwpns, target_lun=lun, initiator_target_map=init_target_map))
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