Archived
Добавлено получение шаблонов из Proxmox API
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
@@ -6,7 +8,9 @@ from sqlalchemy.orm import Session
|
|||||||
from .. import models, schemas
|
from .. import models, schemas
|
||||||
from ..database import get_db
|
from ..database import get_db
|
||||||
from ..deps import get_current_user, require_admin
|
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"])
|
router = APIRouter(prefix="/templates", tags=["templates"])
|
||||||
|
|
||||||
|
|
||||||
@@ -15,7 +19,7 @@ def list_templates(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
_: models.User = Depends(get_current_user),
|
_: models.User = Depends(get_current_user),
|
||||||
):
|
):
|
||||||
"""Возвращает только активные шаблоны."""
|
"""Возвращает только активные шаблоны панели."""
|
||||||
return list(
|
return list(
|
||||||
db.scalars(
|
db.scalars(
|
||||||
select(models.Template)
|
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)
|
@router.post("", response_model=schemas.TemplateOut, status_code=status.HTTP_201_CREATED)
|
||||||
def create_template(
|
def create_template(
|
||||||
payload: schemas.TemplateCreate,
|
payload: schemas.TemplateCreate,
|
||||||
|
|||||||
Reference in New Issue
Block a user