-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibvirt_loop.py
95 lines (78 loc) · 2.74 KB
/
libvirt_loop.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import sys
import libvirt
import xml_parsing_main as xml
import time
import os
import getpass
import threading
import libvirt_console as console_vm
import genvt_ssh as guest_ssh
from yml_parser import YAMLParser
import netifaces as ni
#opening connection from hypervisor
try:
conn = libvirt.open('qemu:///system')
f = open("guest.yml", mode = 'w', encoding = 'utf-8')
os.system("clear")
except libvirt.libvirtError as e:
print(repr(e),file=sys.stderr)
exit(1)
#geting user name of host machine
username = getpass.getuser()
print("\r\nusername of Host machine:{}".format(username))
#geting ip address of host machine
ni.ifaddresses('virbr0')
ip = ni.ifaddresses('virbr0')[ni.AF_INET][0]['addr']
print("\r\nIP Address of Host machine:{}".format(ip))
# Check arguments
if len(sys.argv) != 2:
sys.exit("Usage: ./wlc_bench.py <config.yaml>")
# no longer need to specify breakpoint_serial, only takes 1 arg - yml file
yml_file = sys.argv[1]
# default mode, none other currently defined
wlc_bench_mode = "breakpoint_serial"
# parse YML file
parser = YAMLParser(yml_file)
parsed_file = parser.parse()
#picking values from YAML
mode = parser.get(wlc_bench_mode, parsed_file)
vm = parser.get("vm_0", mode)
os_image = parser.get("os_image",vm)
vm_name = parser.get("vm_name",vm)
os_name = parser.get("os_name",vm)
wl_info = parser.get("proxy_wl",vm)
workload_name = wl_info[0]['wl']
init_cmd = wl_info[0]['init_cmd']
#reading xml configuration for domain creation
try:
for vm_count in range(0,1):
xml.vm_xml_create(vm_count,vm_name,os_image)
f_xml = open(f'vm_{vm_count}.xml','r')
dom = conn.createXML(f_xml.read(),0) #2 conncetion closed means, vm should be closed. 0 means no such dependency
# dom = conn.defineXMLFlags(f_xml.read(),0)
# if dom.create() < 0:
# print("Can Not boot guest domain {file=sys.stderr}")
except Exception:
print("Can Not boot guest domain {file=sys.stderr}")
uuid = dom.UUIDString()
print(f"\r\nsystem : {dom.name()} booted, file=sys.stderr")
vm_0 = {'vm_name':vm_name,'vm_uuid':uuid,'host_ip':ip}
# Aregument file creation for guest
for x,y in vm_0.items():
f.write(f"{x} : {y}\n")
f.close()
print(f"\r\nSleep for 20 second")
time.sleep(20)
#console call for created VM
console = console_vm.Console('qemu:///system',dom.name(),wl_info)
console.stdin_watch = libvirt.virEventAddHandle(0, libvirt.VIR_EVENT_HANDLE_READABLE, console_vm.stdin_callback, console)
while console_vm.check_console(console):
libvirt.virEventRunDefaultImpl()
#dom.destroy()
x = threading.Thread(target=guest_ssh.ssh_guest, args=('cd ${HOME}/GenVT_Env/synbench/ && ./Gen_VT.sh',))
x.start()
x.join()
#guest_ssh.ssh_guest('cd ${HOME}/GenVT_Env/synbench/ && ./Gen_VT.sh')
#time.sleep(30)
conn.close()
exit(0)