From fb4c485118dfe6badd4838825fdc63390f642f0f Mon Sep 17 00:00:00 2001 From: host Date: Sun, 9 Aug 2026 16:22:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=BD=D0=B0=D0=B2=D0=BB=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20VM=20=D0=B8=D0=BB=D0=B8=20LXC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/proxmox_actions.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/app/proxmox_actions.py b/backend/app/proxmox_actions.py index 62ce267..682a514 100644 --- a/backend/app/proxmox_actions.py +++ b/backend/app/proxmox_actions.py @@ -11,28 +11,30 @@ def _is_not_found(error: Exception) -> bool: def delete_guest(guest_type: str, vmid: int) -> None: - """Удаляет VM или LXC и ожидает завершения задачи Proxmox. - - Если объект уже отсутствует в Proxmox, операция считается успешной: - это позволяет очищать осиротевшие записи панели после неудачного создания. - """ + """Останавливает и удаляет VM/LXC, ожидая завершения задач Proxmox.""" client = _client() node = settings.pve_node endpoint = client.nodes(node).qemu(vmid) if guest_type == "vm" else client.nodes(node).lxc(vmid) try: - endpoint.status.current.get() + current = endpoint.status.current.get() except Exception as error: if _is_not_found(error): return raise + # Proxmox не удаляет запущенную VM/LXC, поэтому сначала останавливаем её. + if current.get("status") == "running": + stop_upid = endpoint.status.stop.post() + if stop_upid: + _wait_task(client, node, stop_upid) + try: - upid = endpoint.delete() + delete_upid = endpoint.delete() except Exception as error: if _is_not_found(error): return raise - if upid: - _wait_task(client, node, upid) + if delete_upid: + _wait_task(client, node, delete_upid)