Перед удалением автоматически останавливается VM или LXC

This commit is contained in:
2026-08-09 16:22:25 +03:00
parent 9425e29e89
commit fb4c485118
+11 -9
View File
@@ -11,28 +11,30 @@ def _is_not_found(error: Exception) -> bool:
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
endpoint = client.nodes(node).qemu(vmid) if guest_type == "vm" else client.nodes(node).lxc(vmid) endpoint = client.nodes(node).qemu(vmid) if guest_type == "vm" else client.nodes(node).lxc(vmid)
try: try:
endpoint.status.current.get() current = endpoint.status.current.get()
except Exception as error: except Exception as error:
if _is_not_found(error): if _is_not_found(error):
return return
raise 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: try:
upid = endpoint.delete() delete_upid = endpoint.delete()
except Exception as error: except Exception as error:
if _is_not_found(error): if _is_not_found(error):
return return
raise raise
if upid: if delete_upid:
_wait_task(client, node, upid) _wait_task(client, node, delete_upid)