Оставлены только архивные LXC-шаблоны
This commit is contained in:
@@ -32,30 +32,12 @@ def create_template(
|
|||||||
return tpl
|
return tpl
|
||||||
|
|
||||||
|
|
||||||
def _list_lxc_container_templates(node: str = None) -> list:
|
|
||||||
"""Возвращает LXC-контейнеры, отмеченные в Proxmox как template=1."""
|
|
||||||
node = node or pve.settings.pve_node
|
|
||||||
px = pve._client()
|
|
||||||
result = []
|
|
||||||
for container in px.nodes(node).lxc.get():
|
|
||||||
if container.get("template") != 1:
|
|
||||||
continue
|
|
||||||
vmid = int(container["vmid"])
|
|
||||||
config = px.nodes(node).lxc(vmid).config.get()
|
|
||||||
result.append({
|
|
||||||
"vmid": vmid,
|
|
||||||
"name": container.get("hostname") or config.get("hostname") or f"lxc-{vmid}",
|
|
||||||
"cores": int(config.get("cores", 1)),
|
|
||||||
"memory_mb": int(config.get("memory", 1024)),
|
|
||||||
"disk_gb": 8,
|
|
||||||
"source_kind": "vmid",
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/from-proxmox")
|
@router.get("/from-proxmox")
|
||||||
def list_proxmox_templates(_=Depends(require_admin)):
|
def list_proxmox_templates(_=Depends(require_admin)):
|
||||||
"""Ищет VM, LXC-контейнеры и архивы LXC на Proxmox-ноде."""
|
"""Возвращает VM-шаблоны и архивные LXC-шаблоны с Proxmox.
|
||||||
|
|
||||||
|
Готовые LXC-контейнеры по VMID намеренно не показываются.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
vm_templates = pve.list_vm_templates()
|
vm_templates = pve.list_vm_templates()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@@ -63,23 +45,17 @@ def list_proxmox_templates(_=Depends(require_admin)):
|
|||||||
vm_templates = []
|
vm_templates = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lxc_templates = _list_lxc_container_templates()
|
lxc_templates = pve.list_lxc_templates()
|
||||||
except Exception as exc:
|
|
||||||
logger.warning("Ошибка получения LXC-шаблонов-контейнеров из Proxmox: %s", exc)
|
|
||||||
lxc_templates = []
|
|
||||||
|
|
||||||
try:
|
|
||||||
archive_templates = pve.list_lxc_templates()
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("Ошибка получения архивов LXC-шаблонов из Proxmox: %s", exc)
|
logger.warning("Ошибка получения архивов LXC-шаблонов из Proxmox: %s", exc)
|
||||||
archive_templates = []
|
lxc_templates = []
|
||||||
|
|
||||||
for template in archive_templates:
|
for template in lxc_templates:
|
||||||
template["source_kind"] = "archive"
|
template["source_kind"] = "archive"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"vm_templates": vm_templates,
|
"vm_templates": vm_templates,
|
||||||
"lxc_templates": lxc_templates + archive_templates,
|
"lxc_templates": lxc_templates,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user