Started working on vm_create

This commit is contained in:
Luis Hebendanz 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):
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 = {
logging.DEBUG: format_str(blue),
@ -36,7 +36,7 @@ class CustomFormatter(logging.Formatter):
def register(level):
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setLevel(level)
ch.setFormatter(CustomFormatter())
logging.basicConfig(level=level, handlers=[ch])

View File

@ -11,6 +11,8 @@ from .routers import flake, health, machines, root, vms
origins = [
"http://localhost:3000",
]
# Logging setup
log = logging.getLogger(__name__)
def setup_app() -> FastAPI:
@ -37,6 +39,8 @@ def setup_app() -> FastAPI:
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()
log.warn("log warn")
log.debug("log debug")

View File

@ -2,7 +2,7 @@ import asyncio
import json
import shlex
from typing import Annotated, AsyncIterator
import logging
from fastapi import APIRouter, Body, HTTPException, Request, status, logger
from fastapi.encoders import jsonable_encoder
@ -11,6 +11,8 @@ from fastapi.responses import JSONResponse, StreamingResponse
from ...nix import nix_build, nix_eval
from ..schemas import VmConfig, VmInspectResponse
# Logging setup
log = logging.getLogger(__name__)
router = APIRouter()
@ -94,6 +96,7 @@ command output:
async def vm_build(vm: VmConfig) -> AsyncIterator[str]:
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(
cmd[0],
*cmd[1:],

View File

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