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:
GuofangandClaude Opus 5.5 committed 2026-09-29 13:35:32 +08:00
1 parent a03fb23977
commit 8a7f974c11
5 files changed
+84 -37

No files matched your search

+18 -9
View File
@@ -52,8 +52,6 @@ else:
uses_shared_base_image = True
state_dir = Path(env("ALMA_VM_STATE_DIR") or script_dir / ".vm" / "almalinux10")
disk_image = Path(env("ALMA_VM_DISK_IMAGE") or state_dir / "disk.qcow2")
seed_image = Path(env("ALMA_VM_SEED_IMAGE") or disk_image.parent / "seed.iso")
disk_size = env("ALMA_VM_DISK_SIZE") or "20G"
memory = env("ALMA_VM_MEMORY") or "8G"
cpus = env("ALMA_VM_CPUS") or "8"
@@ -117,24 +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 an AlmaLinux 10 Generic Cloud virtual machine. The launcher obtains a
missing base image through ../vm-images/download-images.sh and creates a
writable overlay under .vm/almalinux10/, leaving the base image unchanged.
writable overlay in the state directory, leaving the base image unchanged.
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/almalinux10; overrides ALMA_VM_STATE_DIR)
-h, --help Show this help
Environment variables:
ALMA_VM_MEMORY Guest memory (default: 8G)
@@ -157,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)
@@ -168,6 +171,12 @@ while args:
usage(sys.stderr)
sys.exit(2)
disk_image = Path(env("ALMA_VM_DISK_IMAGE") or state_dir / "disk.qcow2")
seed_image = Path(env("ALMA_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.")