cli/vms: serialize uuid already in the api

This commit is contained in:
Jörg Thalheim
2023-09-27 11:11:30 +02:00
committed by Mic92
parent 1a63bf265a
commit 852166104a
2 changed files with 6 additions and 16 deletions

View File

@@ -5,14 +5,7 @@ import shlex
from typing import Annotated
from uuid import UUID
from fastapi import (
APIRouter,
BackgroundTasks,
Body,
HTTPException,
Request,
status,
)
from fastapi import APIRouter, BackgroundTasks, Body, HTTPException, Request, status
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse, StreamingResponse
@@ -126,13 +119,13 @@ command output:
@router.get("/api/vms/{uuid}/status")
async def get_status(uuid: str) -> VmStatusResponse:
async def get_status(uuid: UUID) -> VmStatusResponse:
task = get_task(uuid)
return VmStatusResponse(running=not task.finished, status=0)
@router.get("/api/vms/{uuid}/logs")
async def get_logs(uuid: str) -> StreamingResponse:
async def get_logs(uuid: UUID) -> StreamingResponse:
# Generator function that yields log lines as they are available
def stream_logs():
task = get_task(uuid)
@@ -158,6 +151,7 @@ async def get_logs(uuid: str) -> StreamingResponse:
media_type="text/plain",
)
@router.post("/api/vms/create")
async def create_vm(
vm: Annotated[VmConfig, Body()], background_tasks: BackgroundTasks