From 3395badb82eb4516294287df6508e5a9c0969c69 Mon Sep 17 00:00:00 2001 From: host Date: Sun, 9 Aug 2026 15:16:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D0=B1=D0=BD=D0=B0=D1=80=D1=83=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20Proxmox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/proxmox_templates.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/app/proxmox_templates.py diff --git a/backend/app/proxmox_templates.py b/backend/app/proxmox_templates.py new file mode 100644 index 0000000..8d02b7e --- /dev/null +++ b/backend/app/proxmox_templates.py @@ -0,0 +1,39 @@ +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}