2024-08-17 12:18:59 -06:00
|
|
|
from subprocess import Popen, PIPE
|
2024-08-17 17:07:48 -06:00
|
|
|
import os
|
2024-08-21 19:35:32 -06:00
|
|
|
from pathlib import Path
|
|
|
|
import argparse
|
2024-08-17 17:07:48 -06:00
|
|
|
|
2024-08-21 19:35:32 -06:00
|
|
|
def vm_start(nographic=False):
|
|
|
|
home = Path.home()
|
2024-09-04 12:27:56 -06:00
|
|
|
user = os.getuser()
|
2024-08-21 19:35:32 -06:00
|
|
|
image_src = "var/lib/debian.qcow2"
|
|
|
|
vm_storage_location = f"/home/arvp/virtual_machines/{user}.qcow2"
|
|
|
|
image_dest = f"{home}/debian.qcow2"
|
2024-08-17 17:07:48 -06:00
|
|
|
|
2024-08-21 19:35:32 -06:00
|
|
|
initialize = [
|
|
|
|
"qemu-system-x86_64",
|
|
|
|
"-enable-kvm",
|
|
|
|
"-m", "2G", # ram allocation
|
|
|
|
"-nic", "user,hostfwd=tcp::5555-:22", #forward port 5555 in host to port 22 in vm
|
|
|
|
"-drive", "file=%s,media=disk,if=virtio" % image_dest,
|
|
|
|
]
|
2024-08-17 17:07:48 -06:00
|
|
|
|
2024-09-04 12:27:56 -06:00
|
|
|
if nographic:
|
2024-08-21 19:35:32 -06:00
|
|
|
initialize.append("-nographic")
|
|
|
|
initialize.append("-serial")
|
|
|
|
initialize.append("mon:stdio")
|
2024-09-04 12:27:56 -06:00
|
|
|
else:
|
|
|
|
initialize.append("-vga")
|
|
|
|
initialize.append("virtio")
|
|
|
|
initialize.append("-display")
|
|
|
|
initialize.append("sdl")
|
2024-08-21 19:35:32 -06:00
|
|
|
#copy the base image to a directory with everyones virtual machines. -n should not overwrite any existing vms.
|
|
|
|
#subprocess.run(["cp", "-n", image_src, vm_storage_location])
|
|
|
|
Popen(initialize)
|
2024-08-17 12:18:59 -06:00
|
|
|
|
2024-08-21 19:35:32 -06:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="ARVP Onboarding Virtual Machine Launcher! Don't use --nographic if you are in a tmux session. it might explode :3")
|
|
|
|
parser.add_argument(
|
|
|
|
"--nographic",
|
|
|
|
action="store_true",
|
|
|
|
help="Run QEMU in nographic mode (runs the VM embedded in your terminal instead of opening a new window)",)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
vm_start(nographic=args.nographic)
|