nix fmt
This commit is contained in:
@@ -40,6 +40,7 @@ def create(args: argparse.Namespace) -> None:
|
|||||||
print(line, end="")
|
print(line, end="")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument("machine", type=str)
|
parser.add_argument("machine", type=str)
|
||||||
parser.set_defaults(func=create)
|
parser.set_defaults(func=create)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
|
||||||
from .assets import asset_path
|
from .assets import asset_path
|
||||||
from .routers import flake, health, machines, root, utils, vms
|
from .routers import flake, health, machines, root, utils, vms
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import functools
|
import functools
|
||||||
from pathlib import Path
|
|
||||||
import logging
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_hash(string: str) -> str:
|
def get_hash(string: str) -> str:
|
||||||
"""
|
"""
|
||||||
This function takes a string like '/nix/store/kkvk20b8zh8aafdnfjp6dnf062x19732-source'
|
This function takes a string like '/nix/store/kkvk20b8zh8aafdnfjp6dnf062x19732-source'
|
||||||
and returns the hash part 'kkvk20b8zh8aafdnfjp6dnf062x19732' after '/nix/store/' and before '-source'.
|
and returns the hash part 'kkvk20b8zh8aafdnfjp6dnf062x19732' after '/nix/store/' and before '-source'.
|
||||||
"""
|
"""
|
||||||
# Split the string by '/' and get the last element
|
# Split the string by '/' and get the last element
|
||||||
last_element = string.split('/')[-1]
|
last_element = string.split("/")[-1]
|
||||||
# Split the last element by '-' and get the first element
|
# Split the last element by '-' and get the first element
|
||||||
hash_part = last_element.split('-')[0]
|
hash_part = last_element.split("-")[0]
|
||||||
# Return the hash part
|
# Return the hash part
|
||||||
return hash_part
|
return hash_part
|
||||||
|
|
||||||
@@ -30,10 +31,9 @@ def check_divergence(path: Path) -> None:
|
|||||||
log.debug(f"Serving webui asset with hash {gh}")
|
log.debug(f"Serving webui asset with hash {gh}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@functools.cache
|
@functools.cache
|
||||||
def asset_path() -> Path:
|
def asset_path() -> Path:
|
||||||
path = Path(__file__).parent / "assets"
|
path = Path(__file__).parent / "assets"
|
||||||
log.debug("Serving assets from: %s", path)
|
log.debug("Serving assets from: %s", path)
|
||||||
check_divergence(path)
|
check_divergence(path)
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
|
||||||
from fastapi import APIRouter, Response
|
from fastapi import APIRouter, Response
|
||||||
|
|
||||||
from ..assets import asset_path
|
from ..assets import asset_path
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ from pathlib import Path
|
|||||||
from typing import Annotated, Iterator
|
from typing import Annotated, Iterator
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from fastapi import APIRouter, Body
|
from fastapi import APIRouter, Body, status
|
||||||
from fastapi import APIRouter, BackgroundTasks, Body, status
|
|
||||||
from fastapi.exceptions import HTTPException
|
from fastapi.exceptions import HTTPException
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
||||||
from ...nix import nix_build, nix_eval, nix_shell
|
|
||||||
from clan_cli.webui.routers.flake import get_attrs
|
from clan_cli.webui.routers.flake import get_attrs
|
||||||
|
|
||||||
from ...nix import nix_build, nix_eval
|
from ...nix import nix_build, nix_eval, nix_shell
|
||||||
from ..schemas import VmConfig, VmCreateResponse, VmInspectResponse, VmStatusResponse
|
from ..schemas import VmConfig, VmCreateResponse, VmInspectResponse, VmStatusResponse
|
||||||
from ..task_manager import BaseTask, CmdState, get_task, register_task
|
from ..task_manager import BaseTask, CmdState, get_task, register_task
|
||||||
from .utils import run_cmd
|
from .utils import run_cmd
|
||||||
@@ -163,9 +161,7 @@ async def get_vm_logs(uuid: UUID) -> StreamingResponse:
|
|||||||
|
|
||||||
|
|
||||||
@router.post("/api/vms/create")
|
@router.post("/api/vms/create")
|
||||||
async def create_vm(
|
async def create_vm(vm: Annotated[VmConfig, Body()]) -> VmCreateResponse:
|
||||||
vm: Annotated[VmConfig, Body()]
|
|
||||||
) -> VmCreateResponse:
|
|
||||||
flake_attrs = await get_attrs(vm.flake_url)
|
flake_attrs = await get_attrs(vm.flake_url)
|
||||||
if vm.flake_attr not in flake_attrs:
|
if vm.flake_attr not in flake_attrs:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class CmdState:
|
|||||||
line = line.strip("\n")
|
line = line.strip("\n")
|
||||||
self.stderr.append(line)
|
self.stderr.append(line)
|
||||||
self.log.debug("stderr: %s", line)
|
self.log.debug("stderr: %s", line)
|
||||||
self._output.put(line + '\n')
|
self._output.put(line + "\n")
|
||||||
|
|
||||||
if self.p.stdout in rlist:
|
if self.p.stdout in rlist:
|
||||||
assert self.p.stdout is not None
|
assert self.p.stdout is not None
|
||||||
@@ -63,7 +63,7 @@ class CmdState:
|
|||||||
line = line.strip("\n")
|
line = line.strip("\n")
|
||||||
self.stdout.append(line)
|
self.stdout.append(line)
|
||||||
self.log.debug("stdout: %s", line)
|
self.log.debug("stdout: %s", line)
|
||||||
self._output.put(line + '\n')
|
self._output.put(line + "\n")
|
||||||
|
|
||||||
if self.p.returncode != 0:
|
if self.p.returncode != 0:
|
||||||
raise RuntimeError(f"Failed to run command: {shlex.join(cmd)}")
|
raise RuntimeError(f"Failed to run command: {shlex.join(cmd)}")
|
||||||
@@ -109,9 +109,9 @@ class BaseTask(threading.Thread):
|
|||||||
break
|
break
|
||||||
if proc.done:
|
if proc.done:
|
||||||
for line in proc.stderr:
|
for line in proc.stderr:
|
||||||
yield line + '\n'
|
yield line + "\n"
|
||||||
for line in proc.stdout:
|
for line in proc.stdout:
|
||||||
yield line + '\n'
|
yield line + "\n"
|
||||||
continue
|
continue
|
||||||
while True:
|
while True:
|
||||||
out = proc._output
|
out = proc._output
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
|
||||||
import json
|
|
||||||
import pytest
|
import pytest
|
||||||
from api import TestClient
|
from api import TestClient
|
||||||
|
|
||||||
@@ -31,7 +31,6 @@ def test_inspect_err(api: TestClient) -> None:
|
|||||||
assert data.get("detail")
|
assert data.get("detail")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.impure
|
@pytest.mark.impure
|
||||||
def test_inspect_flake(api: TestClient, test_flake_with_core: Path) -> None:
|
def test_inspect_flake(api: TestClient, test_flake_with_core: Path) -> None:
|
||||||
params = {"url": str(test_flake_with_core)}
|
params = {"url": str(test_flake_with_core)}
|
||||||
@@ -49,4 +48,4 @@ def test_inspect_flake(api: TestClient, test_flake_with_core: Path) -> None:
|
|||||||
assert actions[0].get("id") == "vms/inspect"
|
assert actions[0].get("id") == "vms/inspect"
|
||||||
assert actions[0].get("uri") == "api/vms/inspect"
|
assert actions[0].get("uri") == "api/vms/inspect"
|
||||||
assert actions[1].get("id") == "vms/create"
|
assert actions[1].get("id") == "vms/create"
|
||||||
assert actions[1].get("uri") == "api/vms/create"
|
assert actions[1].get("uri") == "api/vms/create"
|
||||||
|
|||||||
Reference in New Issue
Block a user