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: 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.manage('map') 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_chap = CHAP(client_metadata['auth']['chap']) chap_str = client_chap.chap_str if client_chap.error: raise CephiSCSIError("Password decode issue : " "{}".format(client_chap.error_msg)) client_chap_mutual = CHAP( client_metadata['auth']['chap_mutual']) chap_mutual_str = client_chap_mutual.chap_str if client_chap_mutual.error: raise CephiSCSIError("Password decode issue : " "{}".format( client_chap_mutual.error_msg)) client = GWClient(self.logger, client_iqn, image_list, chap_str, chap_mutual_str, 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)
import ceph_iscsi_config.settings as settings settings.init() # Pre-reqs # 1. You need a working ceph iscsi environment # 2. disks and clients need to pre-exist log = logging.getLogger() log.setLevel(logging.DEBUG) ch = logging.StreamHandler(sys.stdout) log.addHandler(ch) # 1. Create a new group definition new_group = Group( log, "mygroup", ['iqn.1994-05.com.redhat:my-esx-1', 'iqn.1994-05.com.redhat:my-esx-2'], ['rbd.disk_2', 'rbd.disk_1']) new_group.apply() assert not new_group.error, "Error caught when creating the group" assert "mygroup" in new_group.config.config["groups"], \ "Group did not create/commit correctly to the configuration" update_group = Group(log, "mygroup", [ 'iqn.1994-05.com.redhat:my-esx-1', 'iqn.1994-05.com.redhat:my-esx-2', 'iqn.1994-05.com.redhat:my-esx-3' ], ['rbd.disk_2', 'rbd.disk_1', 'rbd.disk_3']) update_group.apply() assert len(update_group.config.config['groups']['mygroup']['members']) == 3, \