WIP:aryan/build #2
51
build.py
51
build.py
|
@ -1,24 +1,45 @@
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import argparse
|
||||||
|
|
||||||
user = os.getlogin()
|
def vm_start(nographic=False):
|
||||||
image = f"/home/{user}/safe/debian.qcow2"
|
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
|
||||||
akemi
commented
Isn't this far too low? It should also be adjustable via argparse Isn't this far too low? It should also be adjustable via argparse
|
|||||||
|
"-nic", "user,hostfwd=tcp::5555-:22", #forward port 5555 in host to port 22 in vm
|
||||||
akemi
commented
This port should be configurable, otherwise we can't run several vms at the same time. Best put it in argparse This port should be configurable, otherwise we can't run several vms at the same time. Best put it in argparse
|
|||||||
|
"-drive", "file=%s,media=disk,if=virtio" % image_dest,
|
||||||
|
|
||||||
initialize = [
|
# "-nographic",
|
||||||
"qemu-system-x86_64",
|
# "-serial", "mon:stdio",
|
||||||
akemi
commented
What are these doing here? What are these doing here?
|
|||||||
"-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",
|
"-vga", "virtio", # i think this fixes resolution but idk yet
|
||||||
# "-serial", "mon:stdio",
|
"-display", "sdl",
|
||||||
akemi
commented
Say I enable Say I enable `nographic`. It seems like this display arg will conflict. Instead, it'd be better for these to be the else branch on the conditional below
|
|||||||
|
]
|
||||||
|
|
||||||
"-vga", "virtio", # i think this fixes resolution but idk yet
|
if nographic==True:
|
||||||
akemi
commented
`==True` O.O
`if nographic:`
|
|||||||
"-display", "sdl",
|
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.
|
#copy the base image to a directory with everyones virtual machines. -n should not overwrite any existing vms.
|
||||||
Popen(initialize)
|
#subprocess.run(["cp", "-n", image_src, vm_storage_location])
|
||||||
|
Popen(initialize)
|
||||||
akemi
commented
You'll want some sort of error handling here. What if the vm fails to start? Check the returncode and such on a You'll want some sort of error handling here. What if the vm fails to start? Check the returncode and such on a `.communicate()`
|
|||||||
|
|
||||||
|
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)",)
|
||||||
akemi
commented
Did you use Did you use `black` to format this? Looks a bit odd
|
|||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
vm_start(nographic=args.nographic)
|
||||||
|
|
Loading…
Reference in a new issue
Documentation suggests using getuser