def add_vm_blank(api): vm_memory = 256 * MB vm_params = params.VM( memory=vm_memory, os=params.OperatingSystem(type_='other_linux', ), type_='server', high_availability=params.HighAvailability(enabled=False, ), cluster=params.Cluster(name=TEST_CLUSTER, ), template=params.Template(name=TEMPLATE_BLANK, ), display=params.Display( smartcard_enabled=True, keyboard_layout='en-us', file_transfer_enabled=True, copy_paste_enabled=True, ), memory_policy=params.MemoryPolicy(guaranteed=vm_memory / 2, ), name=VM0_NAME) api.vms.add(vm_params) testlib.assert_true_within_short( lambda: api.vms.get(VM0_NAME).status.state == 'down', ) vm_params.name = VM2_NAME vm_params.high_availability.enabled = True api.vms.add(vm_params) testlib.assert_true_within_short( lambda: api.vms.get(VM2_NAME).status.state == 'down', )
def generic_import_from_glance(api, image_name=CIRROS_IMAGE_NAME, as_template=False, image_ext='_glance_disk', template_ext='_glance_template', dest_storage_domain=MASTER_SD_TYPE, dest_cluster=CLUSTER_NAME): glance_provider = api.storagedomains.get(SD_GLANCE_NAME) target_image = glance_provider.images.get(name=image_name) disk_name = image_name.replace(" ", "_") + image_ext template_name = image_name.replace(" ", "_") + template_ext import_action = params.Action( storage_domain=params.StorageDomain( name=dest_storage_domain, ), cluster=params.Cluster( name=dest_cluster, ), import_as_template=as_template, disk=params.Disk( name=disk_name, ), template=params.Template( name=template_name, ), ) nt.assert_true( target_image.import_image(import_action) ) testlib.assert_true_within_long( lambda: api.disks.get(disk_name).status.state == 'ok', )
def add_vm_template(api): #TODO: Fix the exported domain generation raise SkipTest('Exported domain generation not supported yet') vm_params = params.VM( name=VM1_NAME, memory=512 * MB, cluster=params.Cluster( name=TEST_CLUSTER, ), template=params.Template( name=TEMPLATE_CENTOS7, ), display=params.Display( type_='spice', ), ) api.vms.add(vm_params) testlib.assert_true_within_long( lambda: api.vms.get(VM1_NAME).status.state == 'down', ) disk_name = api.vms.get(VM1_NAME).disks.list()[0].name testlib.assert_true_within_long( lambda: api.vms.get(VM1_NAME).disks.get(disk_name).status.state == 'ok' )
def add_vm_blank(api): vm_memory = 512 * MB vm_params = params.VM( name=VM0_NAME, memory=vm_memory, cluster=params.Cluster( name=TEST_CLUSTER, ), template=params.Template( name=TEMPLATE_BLANK, ), display=params.Display( smartcard_enabled=True, keyboard_layout='en-us', file_transfer_enabled=True, copy_paste_enabled=True, ), memory_policy=params.MemoryPolicy( guaranteed=vm_memory / 2, ), ) api.vms.add(vm_params) testlib.assert_true_within_short( lambda: api.vms.get(VM0_NAME).status.state == 'down', )
def add_blank_vms(api): vm_memory = 256 * MB vm_params = params.VM( memory=vm_memory, os=params.OperatingSystem(type_='other_linux', ), type_='server', high_availability=params.HighAvailability(enabled=False, ), cluster=params.Cluster(name=TEST_CLUSTER, ), template=params.Template(name=TEMPLATE_BLANK, ), display=params.Display( smartcard_enabled=True, keyboard_layout='en-us', file_transfer_enabled=True, copy_paste_enabled=True, ), memory_policy=params.MemoryPolicy(guaranteed=vm_memory / 2, ), name=VM0_NAME) for vm in [VM0_NAME, VM2_NAME, BACKUP_VM_NAME]: vm_params.name = vm if vm == VM2_NAME: vm_params.high_availability.enabled = True vm_params.custom_emulated_machine = 'pc-i440fx-rhel7.4.0' api.vms.add(vm_params) testlib.assert_true_within_short( lambda: api.vms.get(vm).status.state == 'down', )
def import_template_from_glance(api, sdomain, cluster, temp_template_name, glance_server, provider, template_name): try: if api.templates.get(temp_template_name) is not None: logger.info( "RHEVM:%r Warning: found another template with this name.", provider) logger.info( "RHEVM:%r Skipping this step, attempting to continue...", provider) return # Find the storage domain: sd = api.storagedomains.get(name=glance_server) # Find the image: image = sd.images.get(name=template_name) # Import the image: image.import_image( params.Action(async=True, import_as_template=True, template=params.Template(name=temp_template_name), cluster=params.Cluster(name=cluster), storage_domain=params.StorageDomain(name=sdomain)))
def _add_host(vm): p = params.Host( name=vm.name(), address=vm.ip(), cluster=params.Cluster(name='Default', ), root_password=vm.root_password(), override_iptables=True, ) return api.hosts.add(p)
def move_vm_to_cluster(vm, cluster): logging.info("Moving the VM to cluster: %s", cluster) vm.cluster = params.Cluster(name=cluster) try: vm.update() except Exception as e: # getting exception that VM cannot be updated if some of the specified # custom properties are not configured by the system. Ignoring this exception. logging.exception(e)
def add_event(api): event_params = params.Event( description='ovirt-system-tests description', custom_id=int('01234567890'), severity='NORMAL', origin='ovirt-system-tests', cluster=params.Cluster(name=TEST_CLUSTER, ), ) nt.assert_true(api.events.add(event_params))
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 import_templates(api): templates = api.storagedomains.get('templates', ).templates.list( unregistered=True, ) for template in templates: template.register(action=params.Action(cluster=params.Cluster( name=CLUSTER_NAME, ), ), ) for template in api.templates.list(): testlib.assert_true_within_short( lambda: api.templates.get(template.name).status.state == 'ok', )
def add_vm_blank(api): vm_params = params.VM( name=VM0_NAME, memory=1 * GB, cluster=params.Cluster(name=TEST_CLUSTER, ), template=params.Template(name=TEMPLATE_BLANK, ), display=params.Display(type_='spice', ), ) api.vms.add(vm_params) testlib.assert_true_within_short( lambda: api.vms.get(VM0_NAME).status.state == 'down', )
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 import_templates(api): #TODO: Fix the exported domain generation raise SkipTest('Exported domain generation not supported yet') templates = api.storagedomains.get(SD_TEMPLATES_NAME, ).templates.list( unregistered=True, ) for template in templates: template.register(action=params.Action(cluster=params.Cluster( name=CLUSTER_NAME, ), ), ) for template in api.templates.list(): testlib.assert_true_within_short( lambda: api.templates.get(template.name).status.state == 'ok', )
def deployFromTemplate(self, name, comments, templateId, clusterId, displayType, usbType, memoryMB, guaranteedMB): ''' Deploys a virtual machine on selected cluster from selected template Args: name: Name (sanitized) of the machine comments: Comments for machine templateId: Id of the template to deploy from clusterId: Id of the cluster to deploy to displayType: 'vnc' or 'spice'. Display to use ad oVirt admin interface memoryMB: Memory requested for machine, in MB guaranteedMB: Minimum memory guaranteed for this machine Returns: Id of the machine being created form template ''' logger.debug( 'Deploying machine with name "{0}" from template {1} at cluster {2} with display {3} and usb {4}, memory {5} and guaranteed {6}' .format(name, templateId, clusterId, displayType, usbType, memoryMB, guaranteedMB)) try: lock.acquire(True) api = self.__getApi() logger.debug('Deploying machine {0}'.format(name)) cluster = params.Cluster(id=clusterId) template = params.Template(id=templateId) display = params.Display(type_=displayType) if usbType in ('native', 'legacy'): usb = params.Usb(enabled=True, type_=usbType) else: usb = params.Usb(enabled=False) memoryPolicy = params.MemoryPolicy(guaranteed=guaranteedMB * 1024 * 1024) par = params.VM(name=name, cluster=cluster, template=template, description=comments, type_='desktop', memory=memoryMB * 1024 * 1024, memory_policy=memoryPolicy, usb=usb) # display=display, return api.vms.add(par).get_id() finally: lock.release()
def add_vm_template(api): #TODO: Fix the exported domain generation. #For the time being, add VM from Glance imported template. if api.templates.get(name=TEMPLATE_CIRROS) is None: raise SkipTest('%s: template %s not available.' % (add_vm_template.__name__, TEMPLATE_CIRROS)) vm_memory = 512 * MB vm_params = params.VM( name=VM1_NAME, description='CirrOS imported from Glance as Template', memory=vm_memory, cluster=params.Cluster( name=TEST_CLUSTER, ), template=params.Template( name=TEMPLATE_CIRROS, ), display=params.Display( type_='vnc', ), memory_policy=params.MemoryPolicy( guaranteed=vm_memory / 2, ballooning=False, ), os=params.OperatingSystem( type_='other_linux', ), timezone='Etc/GMT', type_='server', serial_number=params.SerialNumber( policy='custom', value='12345678', ), cpu=params.CPU( architecture='X86_64', topology=params.CpuTopology( cores=1, threads=2, sockets=1, ), ), ) api.vms.add(vm_params) testlib.assert_true_within_long( lambda: api.vms.get(VM1_NAME).status.state == 'down', ) disk_name = api.vms.get(VM1_NAME).disks.list()[0].name testlib.assert_true_within_long( lambda: api.vms.get(VM1_NAME).disks.get(disk_name).status.state == 'ok' )
def add_vm_template(api): vm_params = params.VM( name=VM1_NAME, memory=4 * GB, cluster=params.Cluster(name=TEST_CLUSTER, ), template=params.Template(name=TEMPLATE_CENTOS7, ), display=params.Display(type_='spice', ), ) api.vms.add(vm_params) testlib.assert_true_within_long( lambda: api.vms.get(VM1_NAME).status.state == 'down', ) disk_name = api.vms.get(VM1_NAME).disks.list()[0].name testlib.assert_true_within_long(lambda: api.vms.get(VM1_NAME).disks.get( disk_name).status.state == 'ok')
def createCluster(): global controller logging.debug("Creating the local cluster") CPU_TYPE = controller.CONF['VDSM_CPU_FAMILY'] try: controller.CONF["API_OBJECT"].clusters.add( params.Cluster( name=LOCAL_CLUSTER, cpu=params.CPU(id=CPU_TYPE), data_center=controller.CONF["API_OBJECT"].datacenters.get( LOCAL_DATA_CENTER), version=params.Version(major=MAJOR, minor=MINOR))) except: logging.error(traceback.format_exc()) raise Exception(ERROR_CREATE_LOCAL_CLUSTER)
def add(self, dc_name, cpu_type='Intel Nehalem Family'): """ Add a new cluster into data center. """ if not self.name: self.name = "my_cluster" dc = self.api.datacenters.get(dc_name) try: logging.info('Creating a cluster %s in datacenter %s' % (self.name, dc_name)) if self.api.clusters.add(param.Cluster(name=self.name, cpu=param.CPU(id=cpu_type), data_center=dc, version=self.version)): logging.info('Cluster was created successfully') except Exception, e: logging.error('Failed to create cluster:\n%s' % str(e))
def generic_import_from_glance(glance_provider, image_name=CIRROS_IMAGE_NAME, as_template=False, image_ext='_glance_disk', template_ext='_glance_template', dest_storage_domain=MASTER_SD_TYPE, dest_cluster=CLUSTER_NAME): target_image = glance_provider.images.get(name=image_name) disk_name = image_name.replace(" ", "_") + image_ext template_name = image_name.replace(" ", "_") + template_ext import_action = params.Action( storage_domain=params.StorageDomain(name=dest_storage_domain, ), cluster=params.Cluster(name=dest_cluster, ), import_as_template=as_template, disk=params.Disk(name=disk_name, ), template=params.Template(name=template_name, ), ) nt.assert_true(target_image.import_image(import_action))
def create_cluster(self, name="mycluster", cpu=None, datacenter=None, datacenter_broker=None, version=None, virt_service=False, gluster_service=True): version = version or self.create_version() cpu = cpu or self.create_cpu() if (datacenter): datacenter_param = datacenter elif (datacenter_broker): datacenter_param = self.create_datacenter_from(datacenter_broker) else: datacenter_param = None return params.Cluster(name="mycluster", cpu=cpu, data_center=datacenter_param, version=version, virt_service=virt_service, gluster_service=gluster_service)
# 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) # Install vdsm, since it will be failed if we put it to livecd try: pass #cmd = "tar xf /etc/vdsm-setup/vdsm.tar.gz -C /tmp/vdsm-setup/; mv /etc/yum.repos.d/* /tmp/vdsm-setup/; yum localinstall -y /tmp/vdsm-setup/vdsm/*;rm -fr /tmp/vdsm-setup/vdsm/; mv /tmp/vdsm-setup/*.repo /etc/yum.repos.d/" #cmd_out = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.read() except Exception as e: print 'Failed to install rpm:\n%s' % str(e) exit(1) # Add host
def makeTemplate(self, name, comments, machineId, clusterId, storageId, displayType): ''' Publish the machine (makes a template from it so we can create COWs) and returns the template id of the creating machine Args: name: Name of the machine (care, only ascii characters and no spaces!!!) machineId: id of the machine to be published clusterId: id of the cluster that will hold the machine storageId: id of the storage tuat will contain the publication AND linked clones displayType: type of display (for oVirt admin interface only) Returns Raises an exception if operation could not be acomplished, or returns the id of the template being created. ''' logger.debug( "n: {0}, c: {1}, vm: {2}, cl: {3}, st: {4}, dt: {5}".format( name, comments, machineId, clusterId, storageId, displayType)) try: lock.acquire(True) api = self.__getApi() cluster = api.clusters.get(id=clusterId) vm = api.vms.get(id=machineId) if vm is None: raise Exception('Machine not found') if cluster is None: raise Exception('Cluster not found') if vm.get_status().get_state() != 'down': raise Exception('Machine must be in down state to publish it') print(vm.disks.list()) # Create disks description to be created in specified storage domain, one for each disk sd = params.StorageDomains( storage_domain=[params.StorageDomain(id=storageId)]) fix = not self._isFullyFunctionalVersion(api)[ 0] # If we need a fix for "publish" dsks = [] for dsk in vm.disks.list(): dsks.append( params.Disk(id=dsk.get_id(), storage_domains=sd, alias=dsk.get_alias())) # dsks.append(dsk) disks = params.Disks(disk=dsks) # Create display description # display = params.Display(type_=displayType) # TODO: Restore proper template creation mechanism if fix is True: vm = params.VM(id=vm.get_id()) else: vm = params.VM(id=vm.get_id(), disks=disks) template = params.Template( name=name, vm=vm, cluster=params.Cluster(id=cluster.get_id()), description=comments) # display=display) return api.templates.add(template).get_id() finally: lock.release()