def add_directlun(prefix): # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh( ['cat', '/root/multipath.txt']) nt.assert_equals(ret.code, 0) all_guids = ret.out.splitlines() lun_guid = all_guids[ SD_ISCSI_NR_LUNS] #Take the first unused LUN. 0-(SD_ISCSI_NR_LUNS) are used by iSCSI SD dlun_params = params.Disk( name=DLUN_DISK_NAME, interface='virtio_scsi', format='raw', lun_storage=params.Storage( type_='iscsi', logical_unit=[ params.LogicalUnit( id=lun_guid, address=prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ip(), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='******', password='******', ) ]), sgio='unfiltered', ) api = prefix.virt_env.engine_vm().get_api() api.vms.get(VM0_NAME).disks.add(dlun_params) nt.assert_not_equal( api.vms.get(VM0_NAME).disks.get(DLUN_DISK_NAME), None, 'Direct LUN disk not attached')
def create_lun(api, vm_name, disk_alias, lun_id): """ Create a new direct attach disk from lun_id then attach to vm_name """ try: lu = params.LogicalUnit() lu.set_id(lun_id) lus = list() lus.append(lu) storage_params = params.Storage() storage_params.set_id(lun_id) storage_params.set_logical_unit(lus) storage_params.set_type('fcp') disk_params = params.Disk() disk_params.set_format('raw') disk_params.set_interface('virtio') disk_params.set_alias(disk_alias) disk_params.set_active(True) disk_params.set_lun_storage(storage_params) if vm_name: if not MODULE_CHECK_MODE: vm = api.vms.get(name=vm_name) disk = vm.disks.add(disk_params) else: if not MODULE_CHECK_MODE: disk = api.disks.add(disk_params) return 1 except Exception as e: raise Exception("Error while adding new lun: " + str(e))
def add_iscsi_storage_domain_3(prefix, lun_guids): api = prefix.virt_env.engine_vm().get_api() ips = _get_host_all_ips(prefix, SD_ISCSI_HOST_NAME) luns = [] for lun_id in lun_guids: for ip in ips: lun = params.LogicalUnit( id=lun_id, address=ip, port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='******', password='******', ) luns.append(lun) p = params.StorageDomain( name=SD_ISCSI_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format=SD_FORMAT, host=_random_host_from_dc(api, DC_NAME), storage=params.Storage( type_='iscsi', volume_group=params.VolumeGroup(logical_unit=luns), ), ) _add_storage_domain_3(api, p)
def add_iscsi_storage_domain(prefix): api = prefix.virt_env.engine_vm().get_api() # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh( ['multipath', '-ll', '-v1', '|sort']) nt.assert_equals(ret.code, 0) lun_guids = ret.out.splitlines()[:SD_ISCSI_NR_LUNS] p = params.StorageDomain( name=SD_ISCSI_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format='v3', host=params.Host(name=api.hosts.list().pop().name, ), storage=params.Storage( type_='iscsi', volume_group=params.VolumeGroup(logical_unit=[ params.LogicalUnit( id=lun_id, address=_get_host_ip( prefix, SD_ISCSI_HOST_NAME, ), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, ) for lun_id in lun_guids ]), ), ) _add_storage_domain(api, p)
def add_iscsi_storage_domain(prefix): api = prefix.virt_env.engine_vm().get_api() # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh( ['cat', '/root/multipath.txt']) nt.assert_equals(ret.code, 0) lun_guids = ret.out.splitlines()[:SD_ISCSI_NR_LUNS] p = params.StorageDomain( name=SD_ISCSI_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format=SD_FORMAT, host=_random_host_from_dc(api, DC_NAME), storage=params.Storage( type_='iscsi', volume_group=params.VolumeGroup(logical_unit=[ params.LogicalUnit( id=lun_id, address=_get_host_ip( prefix, SD_ISCSI_HOST_NAME, ), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='******', password='******', ) for lun_id in lun_guids ]), ), ) _add_storage_domain(api, p)
def add_iscsi_storage_domain(prefix): api = prefix.virt_env.engine_vm().get_api() # Find LUN GUIDs ret = prefix.virt_env.get_vm('storage-iscsi').ssh(['multipath', '-ll'], ) nt.assert_equals(ret.code, 0) lun_guids = [ line.split()[0] for line in ret.out.split('\n') if line.find('LIO-ORG') != -1 ] lun_guids = lun_guids[:SD_ISCSI_NR_LUNS] p = params.StorageDomain( name=SD_ISCSI_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format='v3', host=params.Host(name=api.hosts.list().pop().name, ), storage=params.Storage( type_='iscsi', volume_group=params.VolumeGroup(logical_unit=[ params.LogicalUnit( id=lun_id, address=SD_ISCSI_ADDRESS, port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, ) for lun_id in lun_guids ]), ), ) _add_storage_domain(api, p)
def connect_direct_lun_to_appliance(self, vm_name, disconnect): """Connects or disconnects the direct lun disk to an appliance. Args: vm_name: Name of the VM with the appliance. disconnect: If False, it will connect, otherwise it will disconnect """ if "provider_key" in self.kwargs: provider_name = self.kwargs["provider_key"] else: raise TypeError("provider_key not supplied to the provider.") # check that the vm exists on the rhev provider, get the ip address if so try: vm = self.api.vms.get(vm_name) ip_addr = self.get_ip_address(vm_name) except: raise NameError("{} not found on {}".format( vm_name, provider_name)) # check for direct lun definition on provider's cfme_data.yaml if 'direct_lun' not in self.kwargs: raise ValueError( "direct_lun key not in cfme_data.yaml under provider {}, exiting..." .format(provider_name)) # does the direct lun exist prov_data = self.kwargs dlun_name = prov_data['direct_lun']['name'] dlun = self.api.disks.get(dlun_name) if dlun is None: # Create the iSCSI storage connection: sc = params.StorageConnection() sc.set_address(prov_data['direct_lun']['ip_address']) sc.set_type("iscsi") sc.set_port(int(prov_data['direct_lun']['port'])) sc.set_target(prov_data['direct_lun']['iscsi_target']) # Add the direct LUN disk: lu = params.LogicalUnit() lu.set_id(prov_data['direct_lun']['iscsi_target']) lu.set_address(sc.get_address()) lu.set_port(sc.get_port()) lu.set_target(sc.get_target()) storage = params.Storage() storage.set_type("iscsi") storage.set_logical_unit([lu]) disk = params.Disk() disk.set_name(dlun_name) disk.set_interface("virtio") disk.set_type("iscsi") disk.set_format("raw") disk.set_lun_storage(storage) disk.set_shareable(True) disk = self.api.disks.add(disk) dlun = self.api.disks.get(dlun_name) # add it if not disconnect: retries = 0 while retries < 3: retries += 1 direct_lun = params.Disk(id=dlun.id) try: # is the disk present and active? vm_disk_list = vm.get_disks().list() for vm_disk in vm_disk_list: if vm_disk.name == dlun_name: if vm_disk.active: return else: vm_disk.activate() return # if not present, add it and activate direct_lun = params.Disk(id=dlun.id) added_lun = vm.disks.add(direct_lun) added_lun.activate() except Exception as e: logger.error("Exception caught: %s", str(e)) if retries == 3: logger.error("exhausted retries and giving up") raise else: logger.info( "sleeping for 30s and retrying to connect direct lun" ) time.sleep(30) # Init SSH client, run pvscan on the appliance ssh_kwargs = { 'username': conf.credentials['ssh']['username'], 'password': conf.credentials['ssh']['password'], 'hostname': ip_addr } with SSHClient(**ssh_kwargs) as ssh_client: status, out = ssh_client.run_command('pvscan', timeout=5 * 60) # remove it else: vm_dlun = vm.disks.get(name=dlun_name) if vm_dlun is None: return else: detach = params.Action(detach=True) vm_dlun.delete(action=detach)