From 9425e29e89f194fdd73c076ad5ed63238de430e5 Mon Sep 17 00:00:00 2001 From: host Date: Sun, 9 Aug 2026 16:18:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D1=83?= =?UTF-8?q?=D1=8E=D1=89=D0=B8=D1=85=20=D0=B3=D0=BE=D1=81=D1=82=D0=B5=D0=B2?= =?UTF-8?q?=D1=8B=D1=85=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/proxmox_actions.py | 36 ++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/backend/app/proxmox_actions.py b/backend/app/proxmox_actions.py index 04ed96b..62ce267 100644 --- a/backend/app/proxmox_actions.py +++ b/backend/app/proxmox_actions.py @@ -1,14 +1,38 @@ -from .proxmox_client import _client, _wait_task 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: - """Удаляет VM или LXC и ожидает завершения задачи Proxmox.""" + """Удаляет VM или LXC и ожидает завершения задачи Proxmox. + + Если объект уже отсутствует в Proxmox, операция считается успешной: + это позволяет очищать осиротевшие записи панели после неудачного создания. + """ client = _client() node = settings.pve_node - if guest_type == "vm": - upid = client.nodes(node).qemu(vmid).delete() - else: - upid = client.nodes(node).lxc(vmid).delete() + endpoint = client.nodes(node).qemu(vmid) if guest_type == "vm" else client.nodes(node).lxc(vmid) + + try: + 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: _wait_task(client, node, upid)