Archived
30 lines
1.6 KiB
Python
30 lines
1.6 KiB
Python
from .config import settings
|
|
from .proxmox_client import _client
|
|
|
|
|
|
def list_templates() -> dict[str, list[dict]]:
|
|
"""Возвращает VM-шаблоны, LXC-шаблоны по CTID и архивные CT-шаблоны."""
|
|
client = _client(); node = settings.pve_node
|
|
vm_templates = []
|
|
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 = []
|
|
for ct in client.nodes(node).lxc.get():
|
|
if ct.get("template") != 1:
|
|
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"})
|
|
|
|
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":
|
|
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"})
|
|
return {"vm_templates": vm_templates, "lxc_templates": lxc_templates}
|