From 7c818dd9267e6d50e92eab6a88ee21c5b4132b7a Mon Sep 17 00:00:00 2001 From: pyarya Date: Sat, 17 Aug 2024 15:17:14 -0600 Subject: [PATCH 1/7] started some stuff --- build.py | 1 - 1 file changed, 1 deletion(-) diff --git a/build.py b/build.py index 387d8e9..962641b 100644 --- a/build.py +++ b/build.py @@ -1,3 +1,2 @@ from subprocess import Popen, PIPE -print("meow") -- 2.43.4 From c0f174f55166a75d844cbf0a428b4aa114e19362 Mon Sep 17 00:00:00 2001 From: pyarya Date: Sat, 17 Aug 2024 17:07:48 -0600 Subject: [PATCH 2/7] basic working build script --- build.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build.py b/build.py index 962641b..a2c8458 100644 --- a/build.py +++ b/build.py @@ -1,2 +1,21 @@ from subprocess import Popen, PIPE +import os + +user = os.getlogin() +image = f"/home/{user}/safe/debian.qcow2" + + +initialize = [ + "qemu-system-x86_64", + "-enable-kvm", + "-m", "2G", + "-nic", "user,hostfwd=tcp::5555-:22", + "-drive", "file=%s,media=disk,if=virtio" % image, +# "-display", "sdl", +] + +Popen(["cp", "/home/chopper/safe/debian.qcow2", f"/home/{user}/nnnnndebian.qcow2"]) #copy the base image to a directory with everyones virtual machines. +Popen(initialize) + + -- 2.43.4 From 5e94d00a5c9f3ee4588a643a73dfa2ae9c2db9fb Mon Sep 17 00:00:00 2001 From: pyarya Date: Sat, 17 Aug 2024 17:22:29 -0600 Subject: [PATCH 3/7] build script update --- build.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build.py b/build.py index a2c8458..c559fd4 100644 --- a/build.py +++ b/build.py @@ -8,14 +8,17 @@ image = f"/home/{user}/safe/debian.qcow2" initialize = [ "qemu-system-x86_64", "-enable-kvm", - "-m", "2G", - "-nic", "user,hostfwd=tcp::5555-:22", + "-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, -# "-display", "sdl", + +# "-nographic", +# "-serial", "mon:stdio", + + "-vga", "virtio", # i think this fixes resolution but idk yet + "-display", "sdl", ] -Popen(["cp", "/home/chopper/safe/debian.qcow2", f"/home/{user}/nnnnndebian.qcow2"]) #copy the base image to a directory with everyones virtual machines. +#Popen(["cp", "/home/chopper/safe/debian.qcow2", f"/home/{user}/nnnnndebian.qcow2"]) #copy the base image to a directory with everyones virtual machines. Popen(initialize) - - -- 2.43.4 From 4b2ab6794c0192a4b93cb2389e39671e1b2077f0 Mon Sep 17 00:00:00 2001 From: pyarya Date: Wed, 21 Aug 2024 19:35:32 -0600 Subject: [PATCH 4/7] made function and added nographic flag --- build.py | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/build.py b/build.py index c559fd4..626c73f 100644 --- a/build.py +++ b/build.py @@ -1,24 +1,45 @@ from subprocess import Popen, PIPE import os +from pathlib import Path +import argparse -user = os.getlogin() -image = f"/home/{user}/safe/debian.qcow2" +def vm_start(nographic=False): + home = Path.home() + user = os.getlogin() + image_src = "var/lib/debian.qcow2" + vm_storage_location = f"/home/arvp/virtual_machines/{user}.qcow2" + image_dest = f"{home}/debian.qcow2" + 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, -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, + # "-nographic", + # "-serial", "mon:stdio", -# "-nographic", -# "-serial", "mon:stdio", + "-vga", "virtio", # i think this fixes resolution but idk yet + "-display", "sdl", + ] - "-vga", "virtio", # i think this fixes resolution but idk yet - "-display", "sdl", -] + if nographic==True: + initialize.append("-nographic") + initialize.append("-serial") + initialize.append("mon:stdio") -#Popen(["cp", "/home/chopper/safe/debian.qcow2", f"/home/{user}/nnnnndebian.qcow2"]) #copy the base image to a directory with everyones virtual machines. -Popen(initialize) + #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) +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) -- 2.43.4 From 2cb1587b23988375e1960328903b40e4f5c2bfe7 Mon Sep 17 00:00:00 2001 From: pyarya Date: Wed, 4 Sep 2024 12:27:56 -0600 Subject: [PATCH 5/7] clean up` --- build.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/build.py b/build.py index 626c73f..6c15778 100644 --- a/build.py +++ b/build.py @@ -5,7 +5,7 @@ import argparse def vm_start(nographic=False): home = Path.home() - user = os.getlogin() + user = os.getuser() image_src = "var/lib/debian.qcow2" vm_storage_location = f"/home/arvp/virtual_machines/{user}.qcow2" image_dest = f"{home}/debian.qcow2" @@ -16,19 +16,17 @@ def vm_start(nographic=False): "-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, - - # "-nographic", - # "-serial", "mon:stdio", - - "-vga", "virtio", # i think this fixes resolution but idk yet - "-display", "sdl", ] - if nographic==True: + if nographic: initialize.append("-nographic") initialize.append("-serial") initialize.append("mon:stdio") - + else: + initialize.append("-vga") + initialize.append("virtio") + initialize.append("-display") + initialize.append("sdl") #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) -- 2.43.4 From 89c67eaf6237fff83ece48cd22adf3ef8f6e426c Mon Sep 17 00:00:00 2001 From: pyarya Date: Wed, 4 Sep 2024 12:31:01 -0600 Subject: [PATCH 6/7] update os to getpass --- build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 6c15778..fbb2fc0 100644 --- a/build.py +++ b/build.py @@ -1,11 +1,11 @@ from subprocess import Popen, PIPE -import os +import getpass from pathlib import Path import argparse def vm_start(nographic=False): home = Path.home() - user = os.getuser() + user = getpass.getuser() image_src = "var/lib/debian.qcow2" vm_storage_location = f"/home/arvp/virtual_machines/{user}.qcow2" image_dest = f"{home}/debian.qcow2" -- 2.43.4 From e8c064ae9acc92ba5592dbbcdb5343bedad9c68d Mon Sep 17 00:00:00 2001 From: pyarya Date: Wed, 4 Sep 2024 12:46:31 -0600 Subject: [PATCH 7/7] add argparse flags for ram and port specification --- build.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index fbb2fc0..ccf3d29 100644 --- a/build.py +++ b/build.py @@ -13,8 +13,8 @@ def vm_start(nographic=False): 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 + "-m", RAM, # ram allocation + "-nic", f'user,hostfwd=tcp::{PORT}-:22', #forward port 5555 in host to port 22 in vm "-drive", "file=%s,media=disk,if=virtio" % image_dest, ] @@ -35,9 +35,10 @@ 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", + "-nographic", action="store_true", help="Run QEMU in nographic mode (runs the VM embedded in your terminal instead of opening a new window)",) - + parser.add_argument("-port", help="Port to forward to the VM for ssh", default=5555) + parser.add_argument("-ram", help="Amount of RAM to allocate to the VM", default="4G") args = parser.parse_args() vm_start(nographic=args.nographic) -- 2.43.4