diff --git a/pkgs/clan-cli/clan_cli/webui/routers/vms.py b/pkgs/clan-cli/clan_cli/webui/routers/vms.py index 18576f3fe..179b9e116 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/vms.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/vms.py @@ -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 diff --git a/pkgs/clan-cli/clan_cli/webui/task_manager.py b/pkgs/clan-cli/clan_cli/webui/task_manager.py index dd53a70fe..21ea7ae23 100644 --- a/pkgs/clan-cli/clan_cli/webui/task_manager.py +++ b/pkgs/clan-cli/clan_cli/webui/task_manager.py @@ -82,13 +82,9 @@ class TaskPool: self.lock: threading.RLock = threading.RLock() self.pool: dict[UUID, BaseTask] = {} - def __getitem__(self, uuid: str | UUID) -> BaseTask: + def __getitem__(self, uuid: UUID) -> BaseTask: with self.lock: - if type(uuid) is UUID: - return self.pool[uuid] - else: - uuid = UUID(uuid) - return self.pool[uuid] + return self.pool[uuid] def __setitem__(self, uuid: UUID, task: BaseTask) -> None: with self.lock: