From 6099f7600ef49b6b2b180039c1fb2e0e79345b94 Mon Sep 17 00:00:00 2001 From: host Date: Sun, 9 Aug 2026 15:17:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=D0=B7=20Proxmox=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/templates.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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,