Шаблоны LXC по CTID добавлены в обнаружение

This commit is contained in:
2026-08-09 16:43:55 +03:00
parent 593350c3a7
commit e907cf7ef5
+14 -24
View File
@@ -1,39 +1,29 @@
from .proxmox_client import _client
from .config import settings from .config import settings
from .proxmox_client import _client
def list_templates() -> dict[str, list[dict]]: def list_templates() -> dict[str, list[dict]]:
"""Возвращает VM-шаблоны и CT-шаблоны с настроенной ноды.""" """Возвращает VM-шаблоны, LXC-шаблоны по CTID и архивные CT-шаблоны."""
client = _client() client = _client(); node = settings.pve_node
node = settings.pve_node vm_templates = []
vm_templates: list[dict] = []
for vm in client.nodes(node).qemu.get(): for vm in client.nodes(node).qemu.get():
if vm.get("template") != 1: if vm.get("template") != 1:
continue continue
config = client.nodes(node).qemu(vm["vmid"]).config.get() config = client.nodes(node).qemu(vm["vmid"]).config.get()
vm_templates.append( vm_templates.append({"vmid": int(vm["vmid"]), "name": vm.get("name", ""), "cores": int(config.get("cores", 1)), "memory_mb": int(config.get("memory", 1024))})
{
"vmid": int(vm["vmid"]), lxc_templates = []
"name": vm.get("name", ""), for ct in client.nodes(node).lxc.get():
"cores": int(config.get("cores", 1)), if ct.get("template") != 1:
"memory_mb": int(config.get("memory", 1024)), continue
} config = client.nodes(node).lxc(ct["vmid"]).config.get()
) lxc_templates.append({"vmid": int(ct["vmid"]), "name": ct.get("name", config.get("hostname", "")), "cores": int(config.get("cores", 1)), "memory_mb": int(config.get("memory", 1024)), "disk_gb": 10, "source_kind": "vmid"})
lxc_templates: list[dict] = []
for storage in client.nodes(node).storage.get(): for storage in client.nodes(node).storage.get():
if "vztmpl" not in storage.get("content", ""): if "vztmpl" not in storage.get("content", ""):
continue continue
storage_name = storage["storage"] storage_name = storage["storage"]
for item in client.nodes(node).storage(storage_name).content.get(): for item in client.nodes(node).storage(storage_name).content.get():
if item.get("content") != "vztmpl": 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), "source_kind": "archive"})
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} return {"vm_templates": vm_templates, "lxc_templates": lxc_templates}