vms/run: make portmap a dict to fix serializer

This commit is contained in:
Jörg Thalheim
2024-10-08 19:24:33 +02:00
committed by Mic92
parent 9e5de5c8f0
commit 09d1ccd0fd
2 changed files with 7 additions and 7 deletions

View File

@@ -92,11 +92,11 @@ def qemu_command(
virtiofsd_socket: Path, virtiofsd_socket: Path,
qmp_socket_file: Path, qmp_socket_file: Path,
qga_socket_file: Path, qga_socket_file: Path,
portmap: list[tuple[int, int]] | None = None, portmap: dict[int, int] | None = None,
interactive: bool = False, interactive: bool = False,
) -> QemuCommand: ) -> QemuCommand:
if portmap is None: if portmap is None:
portmap = [] portmap = {}
kernel_cmdline = [ kernel_cmdline = [
(Path(nixos_config["toplevel"]) / "kernel-params").read_text(), (Path(nixos_config["toplevel"]) / "kernel-params").read_text(),
f'init={nixos_config["toplevel"]}/init', f'init={nixos_config["toplevel"]}/init',
@@ -105,7 +105,7 @@ def qemu_command(
] ]
if not vm.waypipe: if not vm.waypipe:
kernel_cmdline.append("console=tty0") kernel_cmdline.append("console=tty0")
hostfwd = ",".join(f"hostfwd=tcp::{h}-:{g}" for h, g in portmap) hostfwd = ",".join(f"hostfwd=tcp::{h}-:{g}" for h, g in portmap.items())
# fmt: off # fmt: off
command = [ command = [
"qemu-kvm", "qemu-kvm",

View File

@@ -203,13 +203,13 @@ def spawn_vm(
cachedir: Path | None = None, cachedir: Path | None = None,
socketdir: Path | None = None, socketdir: Path | None = None,
nix_options: list[str] | None = None, nix_options: list[str] | None = None,
portmap: list[tuple[int, int]] | None = None, portmap: dict[int, int] | None = None,
stdout: int | None = None, stdout: int | None = None,
stderr: int | None = None, stderr: int | None = None,
stdin: int | None = None, stdin: int | None = None,
) -> Iterator[QemuVm]: ) -> Iterator[QemuVm]:
if portmap is None: if portmap is None:
portmap = [] portmap = {}
if nix_options is None: if nix_options is None:
nix_options = [] nix_options = []
with ExitStack() as stack: with ExitStack() as stack:
@@ -314,7 +314,7 @@ class RuntimeConfig:
cachedir: Path | None = None cachedir: Path | None = None
socketdir: Path | None = None socketdir: Path | None = None
nix_options: list[str] | None = None nix_options: list[str] | None = None
portmap: list[tuple[int, int]] | None = None portmap: dict[int, int] | None = None
command: list[str] | None = None command: list[str] | None = None
no_block: bool = False no_block: bool = False
@@ -373,7 +373,7 @@ def run_command(
vm: VmConfig = inspect_vm(machine=machine_obj) vm: VmConfig = inspect_vm(machine=machine_obj)
portmap = [p.split(":") for p in args.publish] portmap = dict(p.split(":") for p in args.publish)
runtime_config = RuntimeConfig( runtime_config = RuntimeConfig(
nix_options=args.option, nix_options=args.option,