diff --git a/backend/app/proxmox_templates.py b/backend/app/proxmox_templates.py index 8d02b7e..74af850 100644 --- a/backend/app/proxmox_templates.py +++ b/backend/app/proxmox_templates.py @@ -1,39 +1,29 @@ -from .proxmox_client import _client from .config import settings +from .proxmox_client import _client def list_templates() -> dict[str, list[dict]]: - """Возвращает VM-шаблоны и CT-шаблоны с настроенной ноды.""" - client = _client() - node = settings.pve_node - vm_templates: 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)), - } - ) + 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"}) - 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), - } - ) + 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}