From 904301c20e26dbf12340a5bad4a624b9229f9b6c Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 22 Sep 2023 15:37:30 +0200 Subject: [PATCH] api/vm/create: start vm --- pkgs/clan-cli/clan_cli/webui/routers/vms.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/vms.py b/pkgs/clan-cli/clan_cli/webui/routers/vms.py index 18c8c74bd..99b124c93 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/vms.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/vms.py @@ -52,6 +52,16 @@ def nix_build_vm(machine: str, flake_url: str) -> list[str]: ) +async def start_vm(vm_path: str) -> None: + proc = await asyncio.create_subprocess_exec( + vm_path, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + ) + + await proc.wait() + + @router.post("/api/vms/inspect") async def inspect_vm( flake_url: Annotated[str, Body()], flake_attr: Annotated[str, Body()] @@ -90,11 +100,15 @@ async def vm_build(vm: VmConfig) -> AsyncIterator[str]: stderr=asyncio.subprocess.PIPE, ) assert proc.stdout is not None and proc.stderr is not None + vm_path = "" async for line in proc.stdout: - yield line.decode("utf-8", "ignore") + vm_path = f'{line.decode("utf-8", "ignore").strip()}/bin/run-nixos-vm' + + await start_vm(vm_path) stderr = "" async for line in proc.stderr: stderr += line.decode("utf-8", "ignore") + yield line.decode("utf-8", "ignore") res = await proc.wait() if res != 0: raise NixBuildException(