Commit 3ad6d364 by tarokkk

vmdriver basic functions

parent fba0d6f5
#!/usr/bin/env python
import libvirt
import vm
import logging
class VMDriver:
'''Circle Virtal Machin driver main class
'''
connection = None
def req_connection(original_function):
'''Connection checking decorator for libvirt.
'''
def new_function(*args, **kwargs):
if args[0].connection is None:
logging.error("No connection to libvirt daemon.")
else:
return original_function(*args, **kwargs)
return new_function
def connect(self, connection_string='qemu:///system'):
if self.connection is None:
self.connection = libvirt.open(connection_string)
else:
logging.error("There is already an active connection to libvirt.")
@req_connection
def disconnect(self, connection_string='qemu:///system'):
self.connection.close()
self.connection = None
@req_connection
def vm_define(self, vm):
self.connection.defineXML(vm.dump_xml())
logging.info("Virtual machine %s is defined from xml", vm.name)
def vm_create(self, vm):
self.connection.createXML(vm.dump_xml())
logging.info("Virtual machine %s is created from xml", vm.name)
@req_connection
def list_domains(self):
return self.connection.listDefinedDomains()
#Create VM
a = vm.VMNetwork(name="vm-88", mac="02:00:00:00:00:00")
b = vm.VMDisk(name="asd", source='/asdasd/adasds/asd')
testvm = vm.VMInstance(name="Thisthename", vcpu="1",
memory_max="2048",
disk_list=[a],
network_list=[b])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment