-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibvirt_important_code.py
55 lines (50 loc) · 1.69 KB
/
libvirt_important_code.py
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
'''def get_yml_values(mode, parsed_file, parser):
"""
Extract all values from parsed YML object
:param mode: WLC mode, ex: breakpoint_serial
:param parsed_file: parsed object from parse() API
:param parser: YML parser object handle
:return: tuple of values
"""
mode = parser.get(mode, parsed_file)
# get os image name
os_image = parser.get("os_image", mode)
# get no. of vm_instance
vm_name = parser.get("vm_name", mode)
return os_image,vm_name
'''
'''
#checking state for VM
state, reason = dom.state()
if state == libvirt.VIR_DOMAIN_NOSTATE:
print('The state is VIR_DOMAIN_NOSTATE')
elif state == libvirt.VIR_DOMAIN_RUNNING:
print('The state is VIR_DOMAIN_RUNNING')
elif state == libvirt.VIR_DOMAIN_BLOCKED:
print('The state is VIR_DOMAIN_BLOCKED')
elif state == libvirt.VIR_DOMAIN_PAUSED:
print('The state is VIR_DOMAIN_PAUSED')
elif state == libvirt.VIR_DOMAIN_SHUTDOWN:
print('The state is VIR_DOMAIN_SHUTDOWN')
elif state == libvirt.VIR_DOMAIN_SHUTOFF:
print('The state is VIR_DOMAIN_SHUTOFF')
elif state == libvirt.VIR_DOMAIN_CRASHED:
print('The state is VIR_DOMAIN_CRASHED')
elif state == libvirt.VIR_DOMAIN_PMSUSPENDED:
print('The state is VIR_DOMAIN_PMSUSPENDED')
else:
print(' The state is unknown.')
print('The reason code is ' + str(reason))
'''
'''
conn = None
try:
conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
print(repr(e), file=sys.stderr)
exit(1)
temp = []
dom = conn.lookupByName(vm_name)
if dom == None:
print('Failed to get the domain object', file=sys.stderr)
'''