diff --git a/backend/app/routers/templates.py b/backend/app/routers/templates.py index adca069..a7f4904 100644 --- a/backend/app/routers/templates.py +++ b/backend/app/routers/templates.py @@ -1,3 +1,5 @@ +import logging + from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy import select from sqlalchemy.exc import IntegrityError @@ -6,7 +8,9 @@ from sqlalchemy.orm import Session from .. import models, schemas from ..database import get_db from ..deps import get_current_user, require_admin +from ..proxmox_templates import list_templates as discover_templates +logger = logging.getLogger(__name__) router = APIRouter(prefix="/templates", tags=["templates"]) @@ -15,7 +19,7 @@ def list_templates( db: Session = Depends(get_db), _: models.User = Depends(get_current_user), ): - """Возвращает только активные шаблоны.""" + """Возвращает только активные шаблоны панели.""" return list( db.scalars( select(models.Template) @@ -25,6 +29,16 @@ def list_templates( ) +@router.get("/from-proxmox") +def list_proxmox_templates(_: models.User = Depends(require_admin)): + """Находит VM templates и CT templates на настроенной ноде Proxmox.""" + try: + return discover_templates() + except Exception: + logger.exception("Не удалось получить список шаблонов Proxmox") + raise HTTPException(status_code=502, detail="Proxmox временно недоступен") + + @router.post("", response_model=schemas.TemplateOut, status_code=status.HTTP_201_CREATED) def create_template( payload: schemas.TemplateCreate,