Archived
Перед удалением автоматически останавливается VM или LXC
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user