Add --state-dir option to the Python VM launchers
Let each run-*.py launcher take the VM directory (disk, seed ISO, UEFI variables, PID file, console log) from the command line, taking precedence over the *_STATE_DIR environment variable. Paths derived from the state directory are now computed after argument parsing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1dybYsc36kf3gUPB7NuNB
This commit is contained in:
1 parent
a03fb23977
commit
8a7f974c11
5 files changed
+84
-37
No files matched your search
+20
-10
@@ -52,8 +52,6 @@ else:
|
||||
uses_shared_base_image = True
|
||||
|
||||
state_dir = Path(env("VM_STATE_DIR") or script_dir / ".vm" / "debian13")
|
||||
disk_image = Path(env("VM_DISK_IMAGE") or state_dir / "disk.qcow2")
|
||||
seed_image = Path(env("VM_SEED_IMAGE") or disk_image.parent / "seed.iso")
|
||||
disk_size = env("VM_DISK_SIZE") or "20G"
|
||||
memory = env("VM_MEMORY") or "8G"
|
||||
cpus = env("VM_CPUS") or "8"
|
||||
@@ -117,23 +115,23 @@ else:
|
||||
"/opt/homebrew/share/qemu/edk2-i386-vars.fd",
|
||||
"/usr/local/share/qemu/edk2-i386-vars.fd",
|
||||
)
|
||||
uefi_vars = state_dir / "OVMF_VARS_4M.fd"
|
||||
pid_file = state_dir / "qemu.pid"
|
||||
log_file = state_dir / "console.log"
|
||||
daemonize = False
|
||||
extra_args = []
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
stream.write(f"""\
|
||||
Usage: {Path(sys.argv[0]).name} [--daemon] [-- QEMU_ARGUMENT ...]
|
||||
Usage: {Path(sys.argv[0]).name} [--daemon] [--state-dir DIR] [-- QEMU_ARGUMENT ...]
|
||||
|
||||
Start the Debian 13 virtual machine. A writable overlay is created under
|
||||
.vm/debian13/, so the downloaded base image is never modified.
|
||||
Start the Debian 13 virtual machine. A writable overlay is created in the state
|
||||
directory (default: .vm/debian13/), so the downloaded base image is never
|
||||
modified.
|
||||
|
||||
Options:
|
||||
--daemon Run in the background while keeping the graphical window
|
||||
-h, --help Show this help
|
||||
--daemon Run in the background while keeping the graphical window
|
||||
--state-dir DIR Directory for the VM disk, seed ISO and runtime files
|
||||
(default: .vm/debian13; overrides VM_STATE_DIR)
|
||||
-h, --help Show this help
|
||||
|
||||
Environment variables:
|
||||
VM_MEMORY Guest memory (default: 8G)
|
||||
@@ -156,6 +154,12 @@ while args:
|
||||
arg = args.pop(0)
|
||||
if arg == "--daemon":
|
||||
daemonize = True
|
||||
elif arg == "--state-dir":
|
||||
if not args:
|
||||
die(f"{arg} requires a directory argument.", 2)
|
||||
state_dir = Path(args.pop(0))
|
||||
elif arg.startswith("--state-dir="):
|
||||
state_dir = Path(arg.split("=", 1)[1])
|
||||
elif arg in ("-h", "--help"):
|
||||
usage()
|
||||
sys.exit(0)
|
||||
@@ -167,6 +171,12 @@ while args:
|
||||
usage(sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
disk_image = Path(env("VM_DISK_IMAGE") or state_dir / "disk.qcow2")
|
||||
seed_image = Path(env("VM_SEED_IMAGE") or disk_image.parent / "seed.iso")
|
||||
uefi_vars = state_dir / "OVMF_VARS_4M.fd"
|
||||
pid_file = state_dir / "qemu.pid"
|
||||
log_file = state_dir / "console.log"
|
||||
|
||||
for command_name in (qemu_binary, "qemu-img"):
|
||||
if shutil.which(command_name) is None:
|
||||
die(f"{command_name} is not installed.")
|
||||
|
||||
Reference in new issue
Block a user