api/vm/create: start vm
This commit is contained in:
@@ -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")
|
@router.post("/api/vms/inspect")
|
||||||
async def inspect_vm(
|
async def inspect_vm(
|
||||||
flake_url: Annotated[str, Body()], flake_attr: Annotated[str, Body()]
|
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,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
)
|
)
|
||||||
assert proc.stdout is not None and proc.stderr is not None
|
assert proc.stdout is not None and proc.stderr is not None
|
||||||
|
vm_path = ""
|
||||||
async for line in proc.stdout:
|
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 = ""
|
stderr = ""
|
||||||
async for line in proc.stderr:
|
async for line in proc.stderr:
|
||||||
stderr += line.decode("utf-8", "ignore")
|
stderr += line.decode("utf-8", "ignore")
|
||||||
|
yield line.decode("utf-8", "ignore")
|
||||||
res = await proc.wait()
|
res = await proc.wait()
|
||||||
if res != 0:
|
if res != 0:
|
||||||
raise NixBuildException(
|
raise NixBuildException(
|
||||||
|
|||||||
Reference in New Issue
Block a user