CLI: Restructured TaskManager and log collection

This commit is contained in:
Qubasa
2023-10-02 18:36:50 +02:00
parent 6640c78089
commit 814d81c1d2
3 changed files with 136 additions and 97 deletions

View File

@@ -1,10 +1,24 @@
import argparse
import asyncio
from uuid import UUID
import threading
import queue
from ..dirs import get_clan_flake_toplevel
from ..webui.routers import vms
from ..webui.schemas import VmConfig
from typing import Any, Iterator
from fastapi.responses import StreamingResponse
import pdb
def read_stream_response(stream: StreamingResponse) -> Iterator[Any]:
iterator = stream.body_iterator
while True:
try:
tem = asyncio.run(iterator.__anext__())
except StopAsyncIteration:
break
yield tem
def create(args: argparse.Namespace) -> None:
clan_dir = get_clan_flake_toplevel().as_posix()
@@ -18,6 +32,13 @@ def create(args: argparse.Namespace) -> None:
res = asyncio.run(vms.create_vm(vm))
print(res.json())
uuid = UUID(res.uuid)
res = asyncio.run(vms.get_vm_logs(uuid))
for line in read_stream_response(res):
print(line)
def register_create_parser(parser: argparse.ArgumentParser) -> None: