Archived
Добавлено обнаружение шаблонов Proxmox
This commit is contained in:
@@ -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}
|
||||||
Reference in New Issue
Block a user