Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'''
All KVM technology specefic functions are implemented inside this module
Two entites belong to this module: a Kvm hypervisor or a Kvm virtual machine
'''
from libvirtwrapper import *
from exceptions import *
class KvmHypervisor(LibvirtHypervisor):
'''
Base class of a Kvm Hypervisor
This class have a attribute hv_type for tagging purposes
'''
_instance = None
def __init__(self):
super(KvmHypervisor, self).__init__('kvm')
self.hv_type = 'KVM/QEMU'
def __new__(cls, *args, **kwargs):
'''
.. note::
We use singleton design pattern to force only a single instance
of ourlibvirt hypervisor handle, it's essential since we connect
with libvirt only on localhost so we must assure one single
connection to the hypervisor
'''
if cls._instance is None:
cls._instance = super(KvmHypervisor, cls).__new__(cls, *args,
**kwargs)
return cls._instance
def start_vm(self, name, start_options=DEFAULT_VM_START):
'''
Starts the vm identified by name
:param name: The name of the virtual machine
:type nane: :class:`str`
:param start_options: Options flags while starting vm
:type start_options: TODO reference to constants
'''
for vm in self._vm_list:
if vm.get_name() == name:
vm.start()
return
raise VMError('Virtual Machine %s not found: '% name)
def stop_vm(self, name, stop_mode=SOFT_VM_POWEROFF):
'''
Poweroff the specifed vm with the specified options
:param name: the name of the vm:
:type name: :class:`str`
'''
for vm in self._vm_list:
if vm.get_name() == name:
vm.shutdown() if stop_mode else vm.force_poweroff()
return
raise VMError('Virtual Machine %s not found: '% name)
def get_network_conf(self):
raise NotImplementedError
def get_storage_conf(self):
raise NotImplementedError
def get_storage_stats(self):
raise NotImplementedError