def set_discovery_auth_lio(chap_str, chap_mutual_str): iscsi_fabric = ISCSIFabricModule() if chap_str == '': iscsi_fabric.clear_discovery_auth_settings() else: chap = CHAP(chap_str) chap_mutual = CHAP(chap_mutual_str) iscsi_fabric.discovery_userid = chap.user iscsi_fabric.discovery_password = chap.password iscsi_fabric.discovery_mutual_userid = chap_mutual.user iscsi_fabric.discovery_mutual_password = chap_mutual.password iscsi_fabric.discovery_enable_auth = True
def get_client_info(target_iqn, client_iqn): result = { "alias": '', "state": '', "ip_address": [] } iscsi_fabric = ISCSIFabricModule() try: target = Target(iscsi_fabric, target_iqn, 'lookup') except RTSLibNotInCFS: return result for tpg in target.tpgs: if tpg.enable: for client in tpg.node_acls: if client.node_wwn != client_iqn: continue session = client.session if session is None: break result['alias'] = session.get('alias') state = session.get('state').upper() result['state'] = state ips = set() if state == 'LOGGED_IN': for conn in session.get('connections'): ips.add(conn.get('address')) result['ip_address'] = list(ips) break return result
def load_config(self): """ Grab the target, tpg and portal objects from LIO and store in this Gateway object """ try: self.target = Target(ISCSIFabricModule(), self.iqn, "lookup") # clear list so we can rebuild with the current values below if self.tpg_list: del self.tpg_list[:] # there could/should be multiple tpg's for the target for tpg in self.target.tpgs: self.tpg_list.append(tpg) # self.portal = self.tpg.network_portals.next() except RTSLibError as err: self.error_msg = err self.error = True self.logger.info("(Gateway.load_config) successfully loaded existing " "target definition")
def create_target(self): """ Add an iSCSI target to LIO with this objects iqn name, and bind to the IP that aligns with the given iscsi_network """ try: iscsi_fabric = ISCSIFabricModule() self.target = Target(iscsi_fabric, wwn=self.iqn) logger.debug( "(Gateway.create_target) Added iscsi target - {}".format( self.iqn)) self.tpg = TPG(self.target) logger.debug("(Gateway.create_target) Added tpg") self.tpg.enable = True self.portal = NetworkPortal(self.tpg, self.ip_address) logger.debug( "(Gateway.create_target) Added portal IP '{}' to tpg".format( self.ip_address)) except RTSLibError as err: self.error_msg = err self.error = True self.delete() self.changes_made = True logger.info( "(Gateway.create_target) created an iscsi target with iqn of '{}'". format(self.iqn))
def set_discovery_auth_lio(username, password, password_encryption_enabled, mutual_username, mutual_password, mutual_password_encryption_enabled): iscsi_fabric = ISCSIFabricModule() if username == '': iscsi_fabric.clear_discovery_auth_settings() else: chap = CHAP(username, password, password_encryption_enabled) chap_mutual = CHAP(mutual_username, mutual_password, mutual_password_encryption_enabled) iscsi_fabric.discovery_userid = chap.user iscsi_fabric.discovery_password = chap.password iscsi_fabric.discovery_mutual_userid = chap_mutual.user iscsi_fabric.discovery_mutual_password = chap_mutual.password iscsi_fabric.discovery_enable_auth = True
def get_tpgs(self, target_iqn): """ determine the number of tpgs in the current target :return: count of the defined tpgs """ try: target = Target(ISCSIFabricModule(), target_iqn, "lookup") return len([tpg.tag for tpg in target.tpgs]) except RTSLibError: return 0
def define_client(self): """ Establish the links for this object to the corresponding ACL and TPG objects from LIO :return: """ iscsi_fabric = ISCSIFabricModule() target = Target(iscsi_fabric, self.target_iqn, 'lookup') # NB. this will check all tpg's for a matching iqn for tpg in target.tpgs: if tpg.enable: for client in tpg.node_acls: if client.node_wwn == self.iqn: self.acl = client self.tpg = client.parent_tpg try: self.update_acl_controls() except RTSLibError as err: self.logger.error( "(Client.define_client) FAILED to update " "{}".format(self.iqn)) self.error = True self.error_msg = err self.logger.debug( "(Client.define_client) - {} already " "defined".format(self.iqn)) return # at this point the client does not exist, so create it # The configuration only has one active tpg, so pick that one for any # acl definitions for tpg in target.tpgs: if tpg.enable: self.tpg = tpg try: self.acl = NodeACL(self.tpg, self.iqn) self.update_acl_controls() except RTSLibError as err: self.logger.error("(Client.define_client) FAILED to define " "{}".format(self.iqn)) self.logger.debug("(Client.define_client) failure msg " "{}".format(err)) self.error = True self.error_msg = err else: self.logger.info("(Client.define_client) {} added " "successfully".format(self.iqn)) self.change_count += 1
def create_target(self): """ Add an iSCSI target to LIO with this objects iqn name, and bind to the IP that aligns with the given iscsi_network """ try: iscsi_fabric = ISCSIFabricModule() self.target = Target(iscsi_fabric, wwn=self.iqn) self.logger.debug("(Gateway.create_target) Added iscsi target - " "{}".format(self.iqn)) # tpg's are defined in the sequence provide by the gateway_ip_list, # so across multiple gateways the same tpg number will be # associated with the same IP - however, only the tpg with an IP on # the host will be in an enabled state. The other tpgs are # necessary for systems like ESX who issue a rtpg scsi inquiry # only to one of the gateways - so that gateway must provide # details for the whole configuration self.logger.debug("Creating tpgs") for ip in self.gateway_ip_list: self.create_tpg(ip) if self.error: self.logger.critical("Unable to create the TPG for {} " "- {}".format(ip, self.error_msg)) self.update_tpg_controls() except RTSLibError as err: self.error_msg = err self.logger.critical("Unable to create the Target definition " "- {}".format(self.error_msg)) self.error = True if self.error: if self.target: self.target.delete() else: self.changes_made = True self.logger.info("(Gateway.create_target) created an iscsi target " "with iqn of '{}'".format(self.iqn))
def load_config(self): """ Grab the target, tpg and portal objects from LIO and store in this Gateway object """ try: self.target = Target(ISCSIFabricModule(), self.iqn, "lookup") # clear list so we can rebuild with the current values below if self.tpg_list: del self.tpg_list[:] if self.tpg_tag_by_gateway_name: self.tpg_tag_by_gateway_name = {} # there could/should be multiple tpg's for the target for tpg in self.target.tpgs: self.tpg_list.append(tpg) network_portals = list(tpg.network_portals) if network_portals: ip_address = network_portals[0].ip_address gateway_name = self._get_gateway_name(ip_address) if gateway_name: self.tpg_tag_by_gateway_name[gateway_name] = tpg.tag else: self.logger.info("No available network portal for target " "with iqn of '{}'".format(self.iqn)) # self.portal = self.tpg.network_portals.next() except RTSLibError as err: self.error_msg = err self.error = True self.logger.info("(Gateway.load_config) successfully loaded existing " "target definition")