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 = 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 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 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_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 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 create(self, name, clu, numcpu, numinterfaces, netinterface, diskthin1, disksize1, diskinterface, memory, storagedomain, guestid, net1, net2=None, net3=None, net4=None, mac1=None, mac2=None, launched=True, iso=None, diskthin2=None, disksize2=None, vnc=False): boot1, boot2 = 'hd', 'network' if iso in ["", "xx", "yy"]: iso = None if iso: boot2 = 'cdrom' api = self.api memory = memory * MB disksize1 = disksize1 * GB if disksize2: disksize2 = disksize2 * GB #VM CREATION IN OVIRT #TODO check that clu and storagedomain exist and that there is space there diskformat1, diskformat2 = 'raw', 'raw' sparse1, sparse2 = False, False if diskthin1: diskformat1 = 'cow' sparse1 = True if disksize2 and diskthin2: diskformat2 = 'cow' sparse2 = True vm = api.vms.get(name=name) if vm: return "VM %s allready existing.Leaving...\n" % name clu = api.clusters.get(name=clu) storagedomain = api.storagedomains.get(name=storagedomain) try: disk1 = params.Disk(storage_domains=params.StorageDomains( storage_domain=[storagedomain]), name="%s_Disk1" % (name), size=disksize1, type_='system', status=None, interface=diskinterface, format=diskformat1, sparse=sparse1, bootable=True) disk1 = api.disks.add(disk1) disk1id = disk1.get_id() except: return "Insufficient space in storage domain for disk1.Leaving...\n" if disksize2: try: disk2 = params.Disk(storage_domains=params.StorageDomains( storage_domain=[storagedomain]), name="%s_Disk2" % (name), size=disksize2, type_='system', status=None, interface=diskinterface, format=diskformat2, sparse=sparse2, bootable=False) disk2 = api.disks.add(disk2) disk2id = disk2.get_id() except: return "Insufficient space in storage domain for disk2.Leaving...\n" #boot order boot = [params.Boot(dev=boot1), params.Boot(dev=boot2)] #vm creation kernel, initrd, cmdline = None, None, None if vnc: display = params.Display(type_='vnc') else: display = params.Display(type_='spice') api.vms.add( params.VM( name=name, memory=memory, cluster=clu, display=display, template=api.templates.get('Blank'), os=params.OperatingSystem(type_=guestid, boot=boot, kernel=kernel, initrd=initrd, cmdline=cmdline), cpu=params.CPU(topology=params.CpuTopology(cores=numcpu)), type_="server")) #add nics api.vms.get(name).nics.add( params.NIC(name='eth0', network=params.Network(name=net1), interface=netinterface)) if numinterfaces >= 2: api.vms.get(name).nics.add( params.NIC(name='eth1', network=params.Network(name=net2), interface=netinterface)) #compare eth0 and eth1 to get sure eth0 has a lower mac eth0ok = True maceth0 = api.vms.get(name).nics.get(name="eth0").mac.address maceth1 = api.vms.get(name).nics.get(name="eth1").mac.address eth0 = maceth0.split(":") eth1 = maceth1.split(":") for i in range(len(eth0)): el0 = int(eth0[i], 16) el1 = int(eth1[i], 16) if el0 == el1: pass elif el0 > el1: eth0ok = False if not eth0ok: tempnic = "00:11:11:11:11:11" nic = api.vms.get(name).nics.get(name="eth0") nic.mac.address = tempnic nic.update() nic = api.vms.get(name).nics.get(name="eth1") nic.mac.address = maceth0 nic.update() nic = api.vms.get(name).nics.get(name="eth0") nic.mac.address = maceth1 nic.update() if mac1: nic = api.vms.get(name).nics.get(name="eth0") if not ":" in mac1: mac1 = "%s%s" % (nic.mac.address[:-2], mac1) nic.mac.address = mac1 nic.update() if mac2: nic = api.vms.get(name).nics.get(name="eth1") if not ":" in mac2: mac2 = "%s%s" % (nic.mac.address[:-2], mac2) nic.mac.address = mac2 nic.update() if numinterfaces >= 3: api.vms.get(name).nics.add( params.NIC(name='eth2', network=params.Network(name=net3), interface=netinterface)) if numinterfaces >= 4: api.vms.get(name).nics.add( params.NIC(name='eth3', network=params.Network(name=net4), interface=netinterface)) api.vms.get(name).update() if iso: iso = checkiso(api, iso) cdrom = params.CdRom(file=iso) api.vms.get(name).cdroms.add(cdrom) while api.disks.get(id=disk1id).get_status().get_state() != "ok": time.sleep(5) api.vms.get(name).disks.add(disk1) while not api.vms.get(name).disks.get(id=disk1id): time.sleep(2) api.vms.get(name).disks.get(id=disk1id).activate() if disksize2: while api.disks.get(id=disk2id).get_status().get_state() != "ok": time.sleep(5) api.vms.get(name).disks.add(disk2) while not api.vms.get(name).disks.get(id=disk2id): time.sleep(2) api.vms.get(name).disks.get(id=disk2id).activate() #retrieve MACS for cobbler vm = api.vms.get(name=name) for nic in vm.nics.list(): self.macaddr.append(nic.mac.address)
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') # Create disks description to be created in specified storage domain, one for each disk sd = params.StorageDomains( storage_domain=[params.StorageDomain(id=storageId)]) dsks = [] for dsk in vm.disks.list(): dsks.append(params.Disk(id=dsk.get_id(), storage_domains=sd)) disks = params.Disks(disk=dsks) # Create display description display = params.Display(type_=displayType) template = params.Template( name=name, vm=params.VM(id=vm.get_id(), disks=disks), cluster=params.Cluster(id=cluster.get_id()), description=comments) # display=display) return api.templates.add(template).get_id() # return api.templates.get(name=name).get_id() finally: lock.release()