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 yaml
|
||||
import os
|
||||
import stat
|
||||
import psutil
|
||||
from string import Template
|
||||
|
||||
@ -71,9 +72,9 @@ class MachineData():
|
||||
|
||||
def generate_runner_script(self, file_path: str):
|
||||
substitution_mapper = {
|
||||
"CPU_CORES_COUNT": (self.cpu_count/2),
|
||||
"MEMORY_ALLOCATION_SIZE": f"{(self.ram_size/2)}M",
|
||||
"IMAGE_PATH": "image.qcow2"
|
||||
"CPU_CORES_COUNT": int(self.cpu_count/2),
|
||||
"MEMORY_ALLOCATION_SIZE": f"{int(self.ram_size/2)}M",
|
||||
"IMAGE_PATH": f"{os.getcwd()}/{file_path}/image.qcow2"
|
||||
}
|
||||
try:
|
||||
with open("vm_run_script.template", "r") as file:
|
||||
@ -84,5 +85,9 @@ class MachineData():
|
||||
result_file.write(result)
|
||||
result_file.flush()
|
||||
result_file.close()
|
||||
|
||||
st = os.stat(file_path)
|
||||
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
|
||||
|
||||
except Exception as ex:
|
||||
print(str(ex))
|
||||
|
@ -6,6 +6,7 @@ from picotui.menu import *
|
||||
from picotui.context import Context
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
machine_data = MachineData()
|
||||
|
||||
@ -33,6 +34,7 @@ def synchronize():
|
||||
machine_data.generate_runner_script(run_script_path)
|
||||
|
||||
def runner():
|
||||
while (True):
|
||||
d = None
|
||||
image_choice_vm_id = None
|
||||
vm_data = {}
|
||||
@ -77,6 +79,8 @@ def runner():
|
||||
m.focus = True
|
||||
m.redraw()
|
||||
continue
|
||||
if key == KEY_ESC:
|
||||
exit(0)
|
||||
# Otherwise, dialog gets input
|
||||
res = d.handle_input(key)
|
||||
if res is not None and res is not True:
|
||||
@ -121,10 +125,11 @@ def runner():
|
||||
|
||||
res = main_loop()
|
||||
image_choice_vm_id = int(str(vm_names_table[int(w_listbox.choice)]).split(":")[0])
|
||||
|
||||
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']}")
|
||||
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")
|
||||
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))
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
## QEMU (VM) command
|
||||
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 \
|
||||
-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 \
|
||||
-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