This repository has been archived on 2026-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Proxmox-VPS-Panel-secure/backend/app/proxmox_templates.py
T

40 lines
1.5 KiB
Python

from .proxmox_client import _client
from .config import settings
def list_templates() -> dict[str, list[dict]]:
"""Возвращает VM-шаблоны и CT-шаблоны с настроенной ноды."""
client = _client()
node = settings.pve_node
vm_templates: list[dict] = []
for vm in client.nodes(node).qemu.get():
if vm.get("template") != 1:
continue
config = client.nodes(node).qemu(vm["vmid"]).config.get()
vm_templates.append(
{
"vmid": int(vm["vmid"]),
"name": vm.get("name", ""),
"cores": int(config.get("cores", 1)),
"memory_mb": int(config.get("memory", 1024)),
}
)
lxc_templates: list[dict] = []
for storage in client.nodes(node).storage.get():
if "vztmpl" not in storage.get("content", ""):
continue
storage_name = storage["storage"]
for item in client.nodes(node).storage(storage_name).content.get():
if item.get("content") != "vztmpl":
continue
lxc_templates.append(
{
"volid": item["volid"],
"name": item["volid"].rsplit("/", 1)[-1],
"storage": storage_name,
"size_mb": round(item.get("size", 0) / (1024 * 1024), 1),
}
)
return {"vm_templates": vm_templates, "lxc_templates": lxc_templates}