def destroy_VM(self, vmid): virtualization_platform = VIRT_ENV virtualization_platorm_URI = virtualization_platform+":///session" conn = virt.virConnectOpen(virtualization_platorm_URI) dom = virt.virDomainLookupByName(conn,self.name) ret_val = '{\n"status":0\n}\n' if dom: ret_val = '{\n"status":1\n}\n' HYPERVISORS_LIST.pop(str(vmid['vmid'][0])) virt.virDomainDestroy(dom) return ret_val
def start_VM(self, xml_def,vmid): global VIRT_ENV #establish a connection to qemu/Kvm/Xen ret_val = "0" virtualization_platform = VIRT_ENV virtualization_platorm_URI = virtualization_platform+":///session" conn = virt.virConnectOpen(virtualization_platorm_URI) dom = virt.virDomainCreateXML(conn,xml_def,0) self.doms[vmid] = dom if dom: ret_val="1" return ret_val
def get_XML_def(self, parameters): """ This function will return the Hypervisor XML to be used in domain creation based on the parameters that it recieves""" global QEMU_PATH,VIRT_ENV all_types_of_vm = self.get_all_vm_types() new_vm_type = parameters['vm_type'][0] new_vm_name = parameters['name'][0] new_vm_vmid = parameters['vmid'][0] self.name = new_vm_name self.type = new_vm_type self.vmid = new_vm_vmid vm_types = json.loads(all_types_of_vm)[u'types'] for vm_type in vm_types: print vm_type if vm_type[u'tid'] == int(new_vm_type): new_vm_ram = str(int(vm_type[u'ram'])*1000) new_vm_disk = vm_type[u'disk'] new_vm_cpu = vm_type[u'cpu'] print "ram", self.ram_left self.ram_left -= int(new_vm_ram) print "ram", new_vm_ram print "ram", self.ram_left self.ram_usage = int(new_vm_ram) self.hd_usage = int(new_vm_disk) new_vm_image_path = IMAGE_DIR+parameters['image_name'][0] virtualization_platform = VIRT_ENV virtualization_platorm_URI = "qemu:///session" conn = virt.virConnectOpen(virtualization_platorm_URI) xml_def = virt.virConnectGetCapabilities(conn) environment = re.findall("<domain type='(.*)'",xml_def)[0] os_type = re.findall("<os_type>(.*)</os_type>",xml_def)[0] emulator = re.findall("<emulator>(.*)</emulator>",xml_def)[0] VIRT_ENV = environment QEMU_PATH = emulator ######UPDATE HD HERE############## xml_def = """ <domain type='%s'><name>%s</name><memory>%s</memory><vcpu>%s</vcpu><os><type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/></os><features> <acpi/><apic/><pae/></features><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>restart</on_crash><devices><emulator>%s</emulator><disk type='file' device='disk'><driver name='%s' type='raw'/><source file='%s'/><target dev='hda' bus='ide'/><address type='drive' controller='0' bus='0' unit='0'/></disk></devices></domain> """%(environment,str(new_vm_name),str(new_vm_ram), str(new_vm_cpu),emulator,environment,str(new_vm_image_path)) return xml_def