Обработано удаление отсутствующих гостевых систем

This commit is contained in:
2026-08-09 16:18:59 +03:00
parent 9b57b9dc8b
commit 9425e29e89
+30 -6
View File
@@ -1,14 +1,38 @@
from .proxmox_client import _client, _wait_task
from .config import settings from .config import settings
from .proxmox_client import _client, _wait_task
def _is_not_found(error: Exception) -> bool:
"""Определяет ответ Proxmox об отсутствующем госте."""
if getattr(error, "status_code", None) == 404:
return True
response = getattr(error, "response", None)
return getattr(response, "status_code", None) == 404
def delete_guest(guest_type: str, vmid: int) -> None: def delete_guest(guest_type: str, vmid: int) -> None:
"""Удаляет VM или LXC и ожидает завершения задачи Proxmox.""" """Удаляет VM или LXC и ожидает завершения задачи Proxmox.
Если объект уже отсутствует в Proxmox, операция считается успешной:
это позволяет очищать осиротевшие записи панели после неудачного создания.
"""
client = _client() client = _client()
node = settings.pve_node node = settings.pve_node
if guest_type == "vm": endpoint = client.nodes(node).qemu(vmid) if guest_type == "vm" else client.nodes(node).lxc(vmid)
upid = client.nodes(node).qemu(vmid).delete()
else: try:
upid = client.nodes(node).lxc(vmid).delete() endpoint.status.current.get()
except Exception as error:
if _is_not_found(error):
return
raise
try:
upid = endpoint.delete()
except Exception as error:
if _is_not_found(error):
return
raise
if upid: if upid:
_wait_task(client, node, upid) _wait_task(client, node, upid)