API: Improved vm_status and added some tests. Skip vm tests in VM

This commit is contained in:
Qubasa
2023-09-30 11:08:42 +02:00
parent 46d108e473
commit d805c4b069
4 changed files with 59 additions and 16 deletions

View File

@@ -115,13 +115,15 @@ command output:
@router.get("/api/vms/{uuid}/status")
async def get_status(uuid: UUID) -> VmStatusResponse:
async def vm_status(uuid: UUID) -> VmStatusResponse:
task = get_task(uuid)
return VmStatusResponse(running=not task.finished, status=0)
status: list[int | None] = list(map(lambda x: x.returncode, task.procs))
log.debug(msg=f"returncodes: {status}. task.finished: {task.finished}")
return VmStatusResponse(running=not task.finished, returncode=status)
@router.get("/api/vms/{uuid}/logs")
async def get_logs(uuid: UUID) -> StreamingResponse:
async def get_vm_logs(uuid: UUID) -> StreamingResponse:
# Generator function that yields log lines as they are available
def stream_logs() -> Iterator[str]:
task = get_task(uuid)

View File

@@ -45,7 +45,7 @@ class VmConfig(BaseModel):
class VmStatusResponse(BaseModel):
status: int
returncode: list[int | None]
running: bool