feat: add tool catalog and installation endpoints with models for tool management
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from contextlib import asynccontextmanager
|
||||
from ipaddress import ip_address
|
||||
from pathlib import Path
|
||||
import ssl
|
||||
@@ -32,6 +33,7 @@ def create_api(application: Application | None = None, *, host: str | None = Non
|
||||
try:
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
except ModuleNotFoundError as error:
|
||||
raise UvmError(
|
||||
"FastAPI server support is not installed. Install this project with its dependencies."
|
||||
@@ -42,11 +44,24 @@ def create_api(application: Application | None = None, *, host: str | None = Non
|
||||
from .routers.installation import router as installation_router
|
||||
from .routers.vms import router as vms_router
|
||||
from .routers.diagnostics import router as diagnostics_router
|
||||
from .routers.tools import router as tools_router
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_api):
|
||||
tools = getattr(resolved_application, "tools", None)
|
||||
if tools is not None:
|
||||
await run_in_threadpool(tools.start)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if tools is not None:
|
||||
await run_in_threadpool(tools.shutdown)
|
||||
|
||||
api = FastAPI(
|
||||
title="uvm",
|
||||
version="0.1.0",
|
||||
description="Local Firecracker microVM management API.",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
api.state.uvm_application = resolved_application
|
||||
|
||||
@@ -65,6 +80,7 @@ def create_api(application: Application | None = None, *, host: str | None = Non
|
||||
api.include_router(installation_router)
|
||||
api.include_router(vms_router)
|
||||
api.include_router(diagnostics_router)
|
||||
api.include_router(tools_router)
|
||||
|
||||
return api
|
||||
|
||||
|
||||
Reference in New Issue
Block a user