WIP
This commit is contained in:
parent
e0f1eac159
commit
2263749d86
@ -2,6 +2,7 @@ from getmac import get_mac_address as gma
|
|||||||
import socket
|
import socket
|
||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
|
import stat
|
||||||
import psutil
|
import psutil
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
@ -71,9 +72,9 @@ class MachineData():
|
|||||||
|
|
||||||
def generate_runner_script(self, file_path: str):
|
def generate_runner_script(self, file_path: str):
|
||||||
substitution_mapper = {
|
substitution_mapper = {
|
||||||
"CPU_CORES_COUNT": (self.cpu_count/2),
|
"CPU_CORES_COUNT": int(self.cpu_count/2),
|
||||||
"MEMORY_ALLOCATION_SIZE": f"{(self.ram_size/2)}M",
|
"MEMORY_ALLOCATION_SIZE": f"{int(self.ram_size/2)}M",
|
||||||
"IMAGE_PATH": "image.qcow2"
|
"IMAGE_PATH": f"{os.getcwd()}/{file_path}/image.qcow2"
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
with open("vm_run_script.template", "r") as file:
|
with open("vm_run_script.template", "r") as file:
|
||||||
@ -84,5 +85,9 @@ class MachineData():
|
|||||||
result_file.write(result)
|
result_file.write(result)
|
||||||
result_file.flush()
|
result_file.flush()
|
||||||
result_file.close()
|
result_file.close()
|
||||||
|
|
||||||
|
st = os.stat(file_path)
|
||||||
|
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(str(ex))
|
print(str(ex))
|
||||||
|
163
valhalla-client
163
valhalla-client
@ -6,6 +6,7 @@ from picotui.menu import *
|
|||||||
from picotui.context import Context
|
from picotui.context import Context
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
machine_data = MachineData()
|
machine_data = MachineData()
|
||||||
|
|
||||||
@ -33,100 +34,104 @@ def synchronize():
|
|||||||
machine_data.generate_runner_script(run_script_path)
|
machine_data.generate_runner_script(run_script_path)
|
||||||
|
|
||||||
def runner():
|
def runner():
|
||||||
d = None
|
while (True):
|
||||||
image_choice_vm_id = None
|
d = None
|
||||||
vm_data = {}
|
image_choice_vm_id = None
|
||||||
with open("vms_data.json", "r") as vm_data_file:
|
vm_data = {}
|
||||||
try:
|
|
||||||
vm_data = json.loads(vm_data_file.read())
|
|
||||||
except Exception as ex:
|
|
||||||
print(f"ERROR: {str(ex)}")
|
|
||||||
# This routine is called to redraw screen "in menu's background"
|
|
||||||
def screen_redraw(s, allow_cursor=False):
|
|
||||||
with open("vms_data.json", "r") as vm_data_file:
|
with open("vms_data.json", "r") as vm_data_file:
|
||||||
try:
|
try:
|
||||||
vm_data = json.loads(vm_data_file.read())
|
vm_data = json.loads(vm_data_file.read())
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"ERROR: {str(ex)}")
|
print(f"ERROR: {str(ex)}")
|
||||||
s.attr_color(C_WHITE, C_BLUE)
|
# This routine is called to redraw screen "in menu's background"
|
||||||
s.cls()
|
def screen_redraw(s, allow_cursor=False):
|
||||||
s.attr_reset()
|
with open("vms_data.json", "r") as vm_data_file:
|
||||||
d.redraw()
|
try:
|
||||||
def main_loop():
|
vm_data = json.loads(vm_data_file.read())
|
||||||
while 1:
|
except Exception as ex:
|
||||||
key = m.get_input()
|
print(f"ERROR: {str(ex)}")
|
||||||
|
s.attr_color(C_WHITE, C_BLUE)
|
||||||
|
s.cls()
|
||||||
|
s.attr_reset()
|
||||||
|
d.redraw()
|
||||||
|
def main_loop():
|
||||||
|
while 1:
|
||||||
|
key = m.get_input()
|
||||||
|
|
||||||
if isinstance(key, list):
|
if isinstance(key, list):
|
||||||
# Mouse click
|
# Mouse click
|
||||||
x, y = key
|
x, y = key
|
||||||
if m.inside(x, y):
|
if m.inside(x, y):
|
||||||
m.focus = True
|
m.focus = True
|
||||||
|
|
||||||
if m.focus:
|
if m.focus:
|
||||||
# If menu is focused, it gets events. If menu is cancelled,
|
# If menu is focused, it gets events. If menu is cancelled,
|
||||||
# it loses focus. Otherwise, if menu selection is made, we
|
# it loses focus. Otherwise, if menu selection is made, we
|
||||||
# quit with with menu result.
|
# quit with with menu result.
|
||||||
res = m.handle_input(key)
|
res = m.handle_input(key)
|
||||||
if res == ACTION_CANCEL:
|
if res == ACTION_CANCEL:
|
||||||
m.focus = False
|
m.focus = False
|
||||||
elif res is not None and res is not True:
|
elif res is not None and res is not True:
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
# If menu isn't focused, it can be focused by pressing F9.
|
# If menu isn't focused, it can be focused by pressing F9.
|
||||||
if key == KEY_F9:
|
if key == KEY_F9:
|
||||||
m.focus = True
|
m.focus = True
|
||||||
m.redraw()
|
m.redraw()
|
||||||
continue
|
continue
|
||||||
# Otherwise, dialog gets input
|
if key == KEY_ESC:
|
||||||
res = d.handle_input(key)
|
exit(0)
|
||||||
if res is not None and res is not True:
|
# Otherwise, dialog gets input
|
||||||
return res
|
res = d.handle_input(key)
|
||||||
with Context():
|
if res is not None and res is not True:
|
||||||
|
return res
|
||||||
|
with Context():
|
||||||
|
|
||||||
d = Dialog(10, 5, 80, 24)
|
d = Dialog(10, 5, 80, 24)
|
||||||
d.add(12, 1, WLabel("Virtual Machine selection screen"))
|
d.add(12, 1, WLabel("Virtual Machine selection screen"))
|
||||||
d.add(1, 2, WLabel("VMs:"))
|
d.add(1, 2, WLabel("VMs:"))
|
||||||
vm_names_table = []
|
vm_names_table = []
|
||||||
for vm_id in vm_data:
|
for vm_id in vm_data:
|
||||||
vm_names_table.append(f"{vm_id}: {vm_data[vm_id]['image_name']} - ver. {vm_data[vm_id]['image_version']}")
|
vm_names_table.append(f"{vm_id}: {vm_data[vm_id]['image_name']} - ver. {vm_data[vm_id]['image_version']}")
|
||||||
w_listbox = WListBox(64, 4, vm_names_table)
|
w_listbox = WListBox(64, 4, vm_names_table)
|
||||||
d.add(1,3, w_listbox)
|
d.add(1,3, w_listbox)
|
||||||
|
|
||||||
d.add(1, 6, "Selected listbox value:")
|
d.add(1, 6, "Selected listbox value:")
|
||||||
w_listbox_val = WLabel("", w=64)
|
w_listbox_val = WLabel("", w=64)
|
||||||
d.add(1, 7, w_listbox_val)
|
d.add(1, 7, w_listbox_val)
|
||||||
|
|
||||||
def listbox_changed(w):
|
def listbox_changed(w):
|
||||||
val = w.items[w.choice]
|
val = w.items[w.choice]
|
||||||
w_listbox_val.t = val
|
w_listbox_val.t = val
|
||||||
w_listbox_val.redraw()
|
w_listbox_val.redraw()
|
||||||
|
|
||||||
w_listbox.on("changed", listbox_changed)
|
|
||||||
|
|
||||||
b = WButton(8, "OK")
|
w_listbox.on("changed", listbox_changed)
|
||||||
d.add(10, 11, b)
|
|
||||||
b.finish_dialog = ACTION_OK
|
|
||||||
|
|
||||||
b = WButton(8, "Cancel")
|
b = WButton(8, "OK")
|
||||||
d.add(23, 11, b)
|
d.add(10, 11, b)
|
||||||
b.finish_dialog = ACTION_CANCEL
|
b.finish_dialog = ACTION_OK
|
||||||
|
|
||||||
screen_redraw(Screen)
|
b = WButton(8, "Cancel")
|
||||||
Screen.set_screen_redraw(screen_redraw)
|
d.add(23, 11, b)
|
||||||
|
b.finish_dialog = ACTION_CANCEL
|
||||||
|
|
||||||
menu_file = WMenuBox([("Exit", "ex")])
|
screen_redraw(Screen)
|
||||||
m = WMenuBar([("File", menu_file), ("About", "About")])
|
Screen.set_screen_redraw(screen_redraw)
|
||||||
m.permanent = True
|
|
||||||
m.redraw()
|
|
||||||
|
|
||||||
res = main_loop()
|
menu_file = WMenuBox([("Exit", "ex")])
|
||||||
image_choice_vm_id = int(str(vm_names_table[int(w_listbox.choice)]).split(":")[0])
|
m = WMenuBar([("File", menu_file), ("About", "About")])
|
||||||
print(image_choice_vm_id)
|
m.permanent = True
|
||||||
try:
|
m.redraw()
|
||||||
print(f"Running VM: {vm_data[f'{image_choice_vm_id}']['image_name']}:{vm_data[f'{image_choice_vm_id}']['image_version']}")
|
|
||||||
os.execvp(f"images/valhalla/{vm_data[f'{image_choice_vm_id}']['image_name']}/{vm_data[f'{image_choice_vm_id}']['image_version']}/run.sh")
|
res = main_loop()
|
||||||
except Exception as ex:
|
image_choice_vm_id = int(str(vm_names_table[int(w_listbox.choice)]).split(":")[0])
|
||||||
print(str(ex))
|
|
||||||
|
print(image_choice_vm_id)
|
||||||
|
try:
|
||||||
|
print(f"Running VM: {vm_data[f'{image_choice_vm_id}']['image_name']}:{vm_data[f'{image_choice_vm_id}']['image_version']}")
|
||||||
|
run_res = subprocess.check_call([f"images/valhalla/{vm_data[f'{image_choice_vm_id}']['image_name']}/{vm_data[f'{image_choice_vm_id}']['image_version']}/run.sh"])
|
||||||
|
except Exception as ex:
|
||||||
|
print(str(ex))
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="valhalla-client",
|
prog="valhalla-client",
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
## QEMU (VM) command
|
## QEMU (VM) command
|
||||||
qemu-system-x86_64 -enable-kvm -m $MEMORY_ALLOCATION_SIZE \
|
qemu-system-x86_64 -enable-kvm -m $MEMORY_ALLOCATION_SIZE \
|
||||||
-cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
|
-cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
|
||||||
-rtc clock=host,base=localtime -smp 4,sockets=1,cores=$CPU_CORES_COUNT,threads=2 \
|
-rtc clock=host,base=localtime -smp $CPU_CORES_COUNT,sockets=1,cores=$CPU_CORES_COUNT,threads=1 \
|
||||||
-device virtio-net-pci,netdev=n1 -netdev user,id=n1 \
|
-device virtio-net-pci,netdev=n1 -netdev user,id=n1 \
|
||||||
-hda $IMAGE_PATH &
|
-hda $IMAGE_PATH &
|
@ -1 +1 @@
|
|||||||
{"4": {"image_file": "temp_file.qcow2", "image_hash": "d41d8cd98f00b204e9800998ecf8427e", "image_id": "4", "image_name": "cool-image-name", "image_name_version_combo": "cool-image-name@v0.0.2alpha", "image_version": "v0.0.2alpha"}, "3": {"image_file": "temp_file.qcow2", "image_hash": "d41d8cd98f00b204e9800998ecf8427e", "image_id": "3", "image_name": "cool-image-name", "image_name_version_combo": "cool-image-name@v0.0.1alpha", "image_version": "v0.0.1alpha"}}
|
{"4": {"image_file": "temp_file.qcow2", "image_hash": "d41d8cd98f00b204e9800998ecf8427e", "image_id": "4", "image_name": "cool-image-name", "image_name_version_combo": "cool-image-name@v0.0.2alpha", "image_version": "v0.0.2alpha"}, "3": {"image_file": "temp_file.qcow2", "image_hash": "d41d8cd98f00b204e9800998ecf8427e", "image_id": "3", "image_name": "cool-image-name", "image_name_version_combo": "cool-image-name@v0.0.1alpha", "image_version": "v0.0.1alpha"}, "5": {"image_file": "/home/nixen/Projects/College/engineering-degree/images/ubuntu_base/image.qcow2", "image_hash": "f734423d6aaccd7e97c9561f127dd72d", "image_id": "5", "image_name": "xubuntu-22.04", "image_name_version_combo": "xubuntu-22.04@v0.0.1", "image_version": "v0.0.1"}}
|
Loading…
Reference in New Issue
Block a user