Started working on vm_create

This commit is contained in:
Qubasa
2023-09-22 19:58:45 +02:00
committed by Mic92
parent b86e02e183
commit 7479fca82b
4 changed files with 13 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ class CustomFormatter(logging.Formatter):
def format_str(color): def format_str(color):
reset = "\x1b[0m" reset = "\x1b[0m"
return f"%(asctime)s - %(name)s - {color} %(levelname)s {reset} - %(message)s (%(filename)s:%(lineno)d)" return f"{color}%(levelname)s{reset}:(%(filename)s:%(lineno)d): %(message)s"
FORMATS = { FORMATS = {
logging.DEBUG: format_str(blue), logging.DEBUG: format_str(blue),
@@ -36,7 +36,7 @@ class CustomFormatter(logging.Formatter):
def register(level): def register(level):
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) ch.setLevel(level)
ch.setFormatter(CustomFormatter()) ch.setFormatter(CustomFormatter())
logging.basicConfig(level=level, handlers=[ch]) logging.basicConfig(level=level, handlers=[ch])

View File

@@ -11,6 +11,8 @@ from .routers import flake, health, machines, root, vms
origins = [ origins = [
"http://localhost:3000", "http://localhost:3000",
] ]
# Logging setup
log = logging.getLogger(__name__)
def setup_app() -> FastAPI: def setup_app() -> FastAPI:
@@ -37,6 +39,8 @@ def setup_app() -> FastAPI:
return app return app
custom_logger.register(logging.getLogger('uvicorn').level) #TODO: How do I get the log level from the command line in here?
custom_logger.register(logging.DEBUG)
app = setup_app() app = setup_app()
log.warn("log warn")
log.debug("log debug")

View File

@@ -2,7 +2,7 @@ import asyncio
import json import json
import shlex import shlex
from typing import Annotated, AsyncIterator from typing import Annotated, AsyncIterator
import logging
from fastapi import APIRouter, Body, HTTPException, Request, status, logger from fastapi import APIRouter, Body, HTTPException, Request, status, logger
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
@@ -11,6 +11,8 @@ from fastapi.responses import JSONResponse, StreamingResponse
from ...nix import nix_build, nix_eval from ...nix import nix_build, nix_eval
from ..schemas import VmConfig, VmInspectResponse from ..schemas import VmConfig, VmInspectResponse
# Logging setup
log = logging.getLogger(__name__)
router = APIRouter() router = APIRouter()
@@ -94,6 +96,7 @@ command output:
async def vm_build(vm: VmConfig) -> AsyncIterator[str]: async def vm_build(vm: VmConfig) -> AsyncIterator[str]:
cmd = nix_build_vm(vm.flake_attr, flake_url=vm.flake_url) cmd = nix_build_vm(vm.flake_attr, flake_url=vm.flake_url)
log.debug(f"Running command: {shlex.join(cmd)}")
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
cmd[0], cmd[0],
*cmd[1:], *cmd[1:],

View File

@@ -20,6 +20,7 @@ def test_inspect(api: TestClient, test_flake_with_core: Path) -> None:
@pytest.mark.impure @pytest.mark.impure
def test_create(api: TestClient, test_flake_with_core: Path) -> None: def test_create(api: TestClient, test_flake_with_core: Path) -> None:
print(f"flake_url: {test_flake_with_core} ")
response = api.post( response = api.post(
"/api/vms/create", "/api/vms/create",
json=dict( json=dict(