def get_target_info(self, volume): LOG.debug("Searching first iscsi port ip without wan in K2.") iscsi_ip_rs = self.client.search("system/net_ips") iscsi_portals = target_iqns = None if hasattr(iscsi_ip_rs, 'hits') and iscsi_ip_rs.total != 0: iscsi_portals = [ '%s:%s' % (ip.ip_address, ISCSI_TCP_PORT) for ip in iscsi_ip_rs.hits if not ip.wan_port ] if not iscsi_portals: msg = _("Unable to get ISCSI IP address from K2.") LOG.error(msg) raise common.KaminarioCinderDriverException(reason=msg) LOG.debug("Searching system state for target iqn in K2.") sys_state_rs = self.client.search("system/state") if hasattr(sys_state_rs, 'hits') and sys_state_rs.total != 0: iqn = sys_state_rs.hits[0].iscsi_qualified_target_name target_iqns = [iqn] * len(iscsi_portals) if not target_iqns: msg = _("Unable to get target iqn from K2.") LOG.error(msg) raise common.KaminarioCinderDriverException(reason=msg) return iscsi_portals, target_iqns
def _get_host_object(self, connector): host_name = self.get_initiator_host_name(connector) LOG.debug("Searching initiator hostname: %s in K2.", host_name) host_rs = self.client.search("hosts", name=host_name) """Create a host if not exists.""" if host_rs.total == 0: try: LOG.debug("Creating initiator hostname: %s in K2.", host_name) host = self.client.new("hosts", name=host_name, type="Linux").save() LOG.debug("Adding iqn: %(iqn)s to host: %(host)s in K2.", { 'iqn': connector['initiator'], 'host': host_name }) iqn = self.client.new("host_iqns", iqn=connector['initiator'], host=host) iqn.save() except Exception as ex: self._delete_host_by_name(host_name) LOG.exception("Unable to create host: %s in K2.", host_name) raise common.KaminarioCinderDriverException(reason=ex) else: LOG.debug("Use existing initiator hostname: %s in K2.", host_name) host = host_rs.hits[0] return host, host_rs, host_name
def _get_host_object(self, connector): host_name = self.get_initiator_host_name(connector) LOG.debug("Searching initiator hostname: %s in K2.", host_name) host_rs = self.client.search("hosts", name=host_name) host_wwpns = connector['wwpns'] if host_rs.total == 0: try: LOG.debug("Creating initiator hostname: %s in K2.", host_name) host = self.client.new("hosts", name=host_name, type="Linux").save() except Exception as ex: LOG.exception("Unable to create host : %s in K2.", host_name) raise common.KaminarioCinderDriverException(reason=ex) else: # Use existing host. LOG.debug("Use existing initiator hostname: %s in K2.", host_name) host = host_rs.hits[0] # Adding host wwpn. for wwpn in host_wwpns: wwpn = ":".join([wwpn[i:i + 2] for i in range(0, len(wwpn), 2)]) if self.client.search("host_fc_ports", pwwn=wwpn, host=host).total == 0: LOG.debug("Adding wwpn: %(wwpn)s to host: " "%(host)s in K2.", { 'wwpn': wwpn, 'host': host_name }) try: self.client.new("host_fc_ports", pwwn=wwpn, host=host).save() except Exception as ex: if host_rs.total == 0: self._delete_host_by_name(host_name) LOG.exception( "Unable to add wwpn : %(wwpn)s to " "host: %(host)s in K2.", { 'wwpn': wwpn, 'host': host_name }) raise common.KaminarioCinderDriverException(reason=ex) return host, host_rs, host_name
def get_target_info(self, volume): LOG.debug("Searching target wwpns in K2.") fc_ports_rs = self.client.search("system/fc_ports") target_wwpns = [] if hasattr(fc_ports_rs, 'hits') and fc_ports_rs.total != 0: for port in fc_ports_rs.hits: if port.pwwn: target_wwpns.append((port.pwwn).replace(':', '')) if not target_wwpns: msg = _("Unable to get FC target wwpns from K2.") LOG.error(msg) raise common.KaminarioCinderDriverException(reason=msg) return target_wwpns