Backend: - gpu_service: detect NVIDIA (nvidia-smi) + AMD/Intel (/dev/dri, sysfs); inject helpers (nvidia deploy.reservations, /dev/dri + groups + LIBVA) - volume_service: list/orphaned/prune volumes; NFS/SMB/named/bind/tmpfs YAML generation (generate-yaml) - device_service: USB/TTY/DRI detection + sandboxed host path browser - compose_edit_service: server-side merge of volume/gpu/device fragments - routers: volumes (+host paths), editor (services/add-volume/set-gpu/ add-device/remove-device/set-privileged), system gpus+devices - compose: bind-mount /dev:ro for detection Frontend: - split-pane StackEditor with helper panel (service picker + tabs) - VolumeWizard (bind/named/nfs/smb/tmpfs) + HostPathBrowser - GPUSelector, DevicePanel; api clients for volumes/editor/system Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
"""Editor helper endpoints — merge wizard fragments into compose YAML."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from auth import get_current_user
|
|
from models.user import User
|
|
from services import compose_edit_service as edit
|
|
|
|
router = APIRouter(prefix="/api/editor", tags=["editor"])
|
|
|
|
|
|
class AddVolumeBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
spec: dict
|
|
|
|
|
|
class SetGpuBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
config: dict
|
|
|
|
|
|
class DeviceBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
host_path: str
|
|
target: str | None = None
|
|
|
|
|
|
class PrivilegedBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
value: bool
|
|
|
|
|
|
def _run(fn, *args) -> dict:
|
|
try:
|
|
return {"yaml": fn(*args)}
|
|
except edit.EditError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post("/services")
|
|
def services(body: dict, _user: User = Depends(get_current_user)) -> dict:
|
|
try:
|
|
return {"services": edit.list_services(body.get("yaml", ""))}
|
|
except edit.EditError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post("/add-volume")
|
|
def add_volume(body: AddVolumeBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.add_volume, body.yaml, body.service, body.spec)
|
|
|
|
|
|
@router.post("/set-gpu")
|
|
def set_gpu(body: SetGpuBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.set_gpu, body.yaml, body.service, body.config)
|
|
|
|
|
|
@router.post("/add-device")
|
|
def add_device(body: DeviceBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.add_device, body.yaml, body.service, body.host_path, body.target)
|
|
|
|
|
|
@router.post("/remove-device")
|
|
def remove_device(body: DeviceBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.remove_device, body.yaml, body.service, body.host_path)
|
|
|
|
|
|
@router.post("/set-privileged")
|
|
def set_privileged(body: PrivilegedBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.set_privileged, body.yaml, body.service, body.value)
|