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 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(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_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 create_network_params(network_name, dc_name, **net_params): return params.Network( name=network_name, data_center=params.DataCenter( name=dc_name, ), **net_params )
def add_dc_3(api): p = params.DataCenter( name=DC_NAME, local=False, version=params.Version( major=DC_VER_MAJ, minor=DC_VER_MIN, ), ) nt.assert_true(api.datacenters.add(p))
def create_datacenter(self, name="mydatacenter", description="hi", storage_type="posixfs", version=None): version = version or self.create_version() return params.DataCenter(name=name, description=description, storage_type=storage_type, version=version)
def add_vm_network(api): VLAN100 = params.Network( name=VLAN100_NET, data_center=params.DataCenter(name=DC_NAME, ), description='VM Network on VLAN 100', vlan=params.VLAN(id='100', ), ) nt.assert_true(api.networks.add(VLAN100)) nt.assert_true(api.clusters.get(CLUSTER_NAME).networks.add(VLAN100))
def add_cluster(api): p = params.Cluster( name=CLUSTER_NAME, cpu=params.CPU(id=CLUSTER_CPU_FAMILY, ), version=params.Version( major=DC_VER_MAJ, minor=DC_VER_MIN, ), data_center=params.DataCenter(name=DC_NAME, ), ) nt.assert_true(api.clusters.add(p))
def add_non_vm_network(api): VLAN200 = params.Network( name=VLAN200_NET, data_center=params.DataCenter(name=DC_NAME, ), description='Non VM Network on VLAN 200, MTU 9000', vlan=params.VLAN(id='200', ), usages=params.Usages(), mtu=9000, ) nt.assert_true(api.networks.add(VLAN200)) nt.assert_true(api.clusters.get(CLUSTER_NAME).networks.add(VLAN200))
def createDC(): global controller logging.debug("Creating the local datacenter") try: controller.CONF["API_OBJECT"].datacenters.add( params.DataCenter(name=LOCAL_DATA_CENTER, storage_type='localfs', version=params.Version(major=MAJOR, minor=MINOR))) except: logging.error(traceback.format_exc()) raise Exception(ERROR_CREATE_LOCAL_DATACENTER)
def add_cluster_3(prefix): api = prefix.virt_env.engine_vm().get_api() p = params.Cluster( name=CLUSTER_NAME, version=params.Version( major=DC_VER_MAJ, minor=DC_VER_MIN, ), data_center=params.DataCenter(name=DC_NAME, ), ballooning_enabled=True, ) nt.assert_true(api.clusters.add(p))
def add_cluster(api): p = params.Cluster( name=CLUSTER_NAME, cpu=params.CPU(id=CLUSTER_CPU_FAMILY, ), version=params.Version( major=DC_VER_MAJ, minor=DC_VER_MIN, ), data_center=params.DataCenter(name=DC_NAME, ), memory_policy=params.MemoryPolicy(overcommit=params.MemoryOverCommit( percent=100)), ) nt.assert_true(api.clusters.add(p))
def add(self, storage_type): """ Add a new data center. """ if not self.name: self.name = "my_datacenter" try: logging.info('Creating a %s type datacenter %s' % (storage_type, self.name)) if self.api.datacenters.add(param.DataCenter(name=self.name, storage_type=storage_type, version=self.version)): logging.info('Data center was created successfully') except Exception, e: logging.error('Failed to create data center:\n%s' % str(e))
def add_iso_storage_domain(api): p = params.StorageDomain( name=SD_ISO_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='iso', host=params.Host(name=api.hosts.list().pop().name, ), storage=params.Storage( type_='nfs', address=SD_ISO_ADDRESS, path=SD_ISO_PATH, ), ) _add_storage_domain(api, p)
def add_iso_storage_domain(prefix): api = prefix.virt_env.engine_vm().get_api() p = params.StorageDomain( name=SD_ISO_NAME, data_center=params.DataCenter(name=DC_NAME, ), type_='iso', host=params.Host(name=api.hosts.list().pop().name, ), storage=params.Storage( type_='nfs', address=_get_host_ip(prefix, SD_ISO_HOST_NAME), path=SD_ISO_PATH, ), ) _add_storage_domain(api, p)
def add_templates_storage_domain(api): p = params.StorageDomain( name=SD_TEMPLATES_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_='nfs', address=SD_TEMPLATES_ADDRESS, path=SD_TEMPLATES_PATH, ), ) _add_storage_domain(api, p)
def add_generic_nfs_storage_domain_3(prefix, sd_nfs_name, nfs_host_name, mount_path, sd_format=SD_FORMAT, sd_type='data', nfs_version='v4_1'): api = prefix.virt_env.engine_vm().get_api() p = params.StorageDomain( name=sd_nfs_name, data_center=params.DataCenter( name=DC_NAME, ), type_=sd_type, storage_format=sd_format, host=_random_host_from_dc(api, DC_NAME), storage=params.Storage( type_='nfs', address=_get_host_ip(prefix, nfs_host_name), path=mount_path, nfs_version=nfs_version, ), ) _add_storage_domain_3(api, p)
def add_generic_nfs_storage_domain(prefix, sd_nfs_name, nfs_host_name, mount_path, sd_format='v3', sd_type='data'): api = prefix.virt_env.engine_vm().get_api() p = params.StorageDomain( name=sd_nfs_name, data_center=params.DataCenter( name=DC_NAME, ), type_=sd_type, storage_format=sd_format, host=params.Host( name=api.hosts.list().pop().name, ), storage=params.Storage( type_='nfs', address=_get_host_ip(prefix, nfs_host_name), path=mount_path, ), ) _add_storage_domain(api, p)
def add_glusterfs_storage_domain(prefix, sdname, volname): api = prefix.virt_env.engine_vm().get_api() hosts = sorted([vm.name() for vm in prefix.virt_env.host_vms()]) mount_path = "{0}://{1}".format(hosts[0], volname) mount_options = "backup-volfile-servers={0}".format(':'.join(hosts[1:])) p = params.StorageDomain( name=sdname, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format='v3', host=_random_host_from_dc(api, DC_NAME), storage=params.Storage( type_='glusterfs', path=mount_path, vfs_type='glusterfs', mount_options=mount_options, ), ) _add_storage_domain(api, p)
def add_labeled_network(api): """ Creates a labeled network """ # create network labeled_net = params.Network( name=LABELED_NET_NAME, data_center=params.DataCenter(name=DC_NAME, ), description='Labeled network on VLAN {}'.format(LABELED_NET_VLAN_ID), usages=params.Usages(), # because only one non-VLAN network, here 'ovirtmgmt', can be assigned to each nic, # this additional network has to be a VLAN network vlan=params.VLAN(id=LABELED_NET_VLAN_ID, ), ) net = api.networks.add(labeled_net) nt.assert_true(net) # assign label to the network nt.assert_true(net.labels.add(params.Label(id=NETWORK_LABEL))) nt.assert_equal(len(net.labels.list(id=NETWORK_LABEL)), 1)
def add_glusterfs_storage_domain(prefix, sdname, volname): api = prefix.virt_env.engine_vm().get_api() mount_path = "{0}://{1}".format(_get_host_ip(prefix, GLUSTER_HOST0), volname) mount_options = "backup-volfile-servers={0}:{1}".format( _get_host_ip(prefix, GLUSTER_HOST1), _get_host_ip(prefix, GLUSTER_HOST2)) p = params.StorageDomain( name=sdname, data_center=params.DataCenter(name=DC_NAME, ), type_='data', storage_format='v3', host=_random_host_from_dc(api, DC_NAME), storage=params.Storage( type_='glusterfs', path=mount_path, vfs_type='glusterfs', mount_options=mount_options, ), ) _add_storage_domain(api, p)
def nullifyNic(hostNIC): ''' resets nic configuration to enable its reuse ''' hostNIC.network = params.Network() hostNIC.boot_protocol = 'none' hostNIC.ip = params.IP(address='', netmask='', gateway='') return hostNIC # Create DC try: if api.datacenters.add( params.DataCenter(name=DC_NAME, storage_type='localfs', version=VERSION)): print 'Local Data Center was created successfully' except Exception as e: print 'Failed to create Local Data Center:\n%s' % str(e) # Create Cluster try: if api.clusters.add( params.Cluster(name=CLUSTER_NAME, cpu=params.CPU(id=CPU_TYPE), data_center=api.datacenters.get(DC_NAME), version=VERSION)): print 'Cluster was created successfully' except Exception as e: print 'Failed to create Cluster:\n%s' % str(e)
def create_datacenter_from(self, datacenter_broker): return params.DataCenter(id=datacenter_broker.id)