def delete_target(self, target_iqn): target = GWTarget(self.logger, target_iqn, {}) if target.error: raise CephiSCSIError("Could not initialize target: {}". format(target.error_msg)) target.load_config() if target.error: self.logger.debug("Could not find target {}: {}". format(target_iqn, target.error_msg)) # Target might not be setup on this node. Ignore. return try: target.delete(self.config) except RTSLibError as err: err_msg = "Could not remove target {}: {}".format(target_iqn, err) raise CephiSCSIError(err_msg)
def define_target(self, target_iqn, gw_ip_list, target_only=False): """ define the iSCSI target and tpgs :param target_iqn: (str) target iqn :param gw_ip_list: (list) gateway ip list :param target_only: (bool) if True only setup target :return: (object) GWTarget object """ # GWTarget Definition : Handle the creation of the Target/TPG(s) and # Portals. Although we create the tpgs, we flick the enable_portal flag # off so the enabled tpg will not have an outside IP address. This # prevents clients from logging in too early, failing and giving up # because the nodeACL hasn't been defined yet (yes Windows I'm looking # at you!) # first check if there are tpgs already in LIO (True) - this would # indicate a restart or reload call has been made. If the tpg count is # 0, this is a boot time request self.logger.info("Setting up {}".format(target_iqn)) target = GWTarget(self.logger, target_iqn, gw_ip_list, enable_portal=self.portals_active(target_iqn)) if target.error: raise CephiSCSIError("Error initializing iSCSI target: " "{}".format(target.error_msg)) target.manage('target') if target.error: raise CephiSCSIError("Error creating the iSCSI target (target, " "TPGs, Portals): {}".format(target.error_msg)) if not target_only: self.logger.info("Processing LUN configuration") try: LUN.define_luns(self.logger, self.config, target) except CephiSCSIError as err: self.logger.error("{} - Could not define LUNs: " "{}".format(target.iqn, err)) raise self.logger.info("{} - Processing client configuration". format(target.iqn)) try: GWClient.define_clients(self.logger, self.config, target.iqn) except CephiSCSIError as err: self.logger.error("Could not define clients: {}".format(err)) raise if not target.enable_portal: # The tpgs, luns and clients are all defined, but the active tpg # doesn't have an IP bound to it yet (due to the # enable_portals=False setting above) self.logger.info("{} - Adding the IP to the enabled tpg, " "allowing iSCSI logins".format(target.iqn)) target.enable_active_tpg(self.config) if target.error: raise CephiSCSIError("{} - Error enabling the IP with the " "active TPG: {}".format(target.iqn, target.error_msg)) return target
def activate(self): disk = self.config.config['disks'].get(self.config_key, None) if not disk: raise CephiSCSIError("Image {} not found.".format(self.image)) wwn = disk.get('wwn', None) if not wwn: raise CephiSCSIError("LUN {} missing wwn".format(self.image)) # re-add backend storage object so = self.lio_stg_object() if not so: so = self.add_dev_to_lio(wwn) if self.error: raise CephiSCSIError("LUN activate failure - {}".format( self.error_msg)) # re-add LUN to target local_gw = this_host() targets_items = [ item for item in self.config.config['targets'].items() if self.config_key in item[1]['disks'] and local_gw in item[1]['portals'] ] for target_iqn, target in targets_items: ip_list = target['ip_list'] # Add the mapping for the lun to ensure the block device is # present on all TPG's gateway = GWTarget(self.logger, target_iqn, ip_list) gateway.map_lun(self.config, so) if gateway.error: raise CephiSCSIError("LUN mapping failed - {}".format( gateway.error_msg)) # re-map LUN to hosts client_err = '' for client_iqn in target['clients']: client_metadata = target['clients'][client_iqn] if client_metadata.get('group_name', ''): continue image_list = list(client_metadata['luns'].keys()) if self.config_key not in image_list: continue client_auth_config = client_metadata['auth'] client_chap = CHAP( client_auth_config['username'], client_auth_config['password'], client_auth_config['password_encryption_enabled']) if client_chap.error: raise CephiSCSIError("Password decode issue : " "{}".format(client_chap.error_msg)) client_chap_mutual = CHAP( client_auth_config['mutual_username'], client_auth_config['mutual_password'], client_auth_config['mutual_password_encryption_enabled']) if client_chap_mutual.error: raise CephiSCSIError("Password decode issue : " "{}".format( client_chap_mutual.error_msg)) client = GWClient(self.logger, client_iqn, image_list, client_chap.user, client_chap.password, client_chap_mutual.user, client_chap_mutual.password, target_iqn) client.manage('present') if client.error: client_err = "LUN mapping failed {} - {}".format( client_iqn, client.error_msg) # re-map LUN to host groups for group_name in target['groups']: host_group = target['groups'][group_name] members = host_group.get('members') disks = host_group.get('disks').keys() if self.config_key not in disks: continue group = Group(self.logger, target_iqn, group_name, members, disks) group.apply() if group.error: client_err = "LUN mapping failed {} - {}".format( group_name, group.error_msg) if client_err: raise CephiSCSIError(client_err)