feat(instances): ISO eject/mount with boot-order switch and hybrid reboot
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled
Backend Tests / pytest (Python 3.12) (push) Has been cancelled

- Images: show real ISO files already on the node storage (incl. those
  present before the node joined the panel) via existing node/isos endpoint
- ISO dialog: rename "detach" to "Eject", show current image inside the
  select (drop overflowing side text), add "boot from disk" checkbox
- Backend: on eject, put disk first in boot order; on mount, optional
  "boot from this ISO" puts CD-ROM first
- Reboot to apply the new boot order via hybrid restart: graceful ACPI
  shutdown with forceStop fallback, then start (fixes guest-ping timeout
  on freshly installed OS without QEMU Guest Agent)
- Update iso_next_steps hint to reflect the automated flow
This commit is contained in:
markmorado
2026-07-24 23:00:32 +05:00
parent aa100b49c1
commit b7c3a6ed35
8 changed files with 311 additions and 37 deletions

View File

@@ -3649,10 +3649,18 @@ class NotesRequest(BaseModel):
class IsoAttachRequest(BaseModel):
volid: str
device: str = "ide2"
# Поставить этот ISO первым в порядке загрузки (грузиться с образа: live-CD и т.п.).
boot_from_iso: bool = False
# Перезапустить ВМ, чтобы новый порядок загрузки вступил в силу (только если запущена).
reboot_after: bool = True
class IsoDetachRequest(BaseModel):
device: str = "ide2"
# После извлечения ISO — поставить диск первым в порядке загрузки (грузиться с ОС).
boot_from_disk: bool = True
# Перезапустить ВМ, чтобы новый порядок загрузки вступил в силу (только если запущена).
reboot_after: bool = True
class ExecuteCommandRequest(BaseModel):
@@ -3750,16 +3758,29 @@ def attach_iso_endpoint(
require_vm_access(db, current_user, server_id, vmid)
server = _resolve_server(db, server_id)
client = _get_client_or_503(server)
ok = client.attach_iso(node, vmid, body.volid, body.device or 'ide2')
device = body.device or 'ide2'
ok = client.attach_iso(node, vmid, body.volid, device)
if not ok:
raise HTTPException(status_code=500, detail="Failed to attach ISO")
boot_iso_set = False
rebooted = False
if body.boot_from_iso:
boot_iso_set = client.set_boot_iso_first(node, vmid, device)
# Новый порядок загрузки применяется только при power-cycle QEMU.
# Перезапускаем лишь запущенную ВМ.
if boot_iso_set and body.reboot_after:
status = client.get_vm_status(node, vmid) or {}
if status.get('status') == 'running':
rebooted = client.hybrid_restart_vm(node, vmid)
LoggingService.log_proxmox_action(
db=db, action='attach-iso', resource_type='vm', resource_id=vmid,
username=current_user.username, server_id=server_id,
server_name=server.name, node_name=node,
details={'volid': body.volid, 'device': body.device}, success=True,
details={'volid': body.volid, 'device': device,
'boot_from_iso': boot_iso_set, 'rebooted': rebooted},
success=True,
)
return {"status": "success"}
return {"status": "success", "boot_from_iso": boot_iso_set, "rebooted": rebooted}
@router.post("/api/{server_id}/vm/{vmid}/iso/detach")
@@ -3775,10 +3796,28 @@ def detach_iso_endpoint(
require_vm_access(db, current_user, server_id, vmid)
server = _resolve_server(db, server_id)
client = _get_client_or_503(server)
ok = client.detach_iso(node, vmid, body.device or 'ide2')
device = body.device or 'ide2'
ok = client.detach_iso(node, vmid, device)
if not ok:
raise HTTPException(status_code=500, detail="Failed to detach ISO")
return {"status": "success"}
boot_disk_set = False
rebooted = False
if body.boot_from_disk:
boot_disk_set = client.set_boot_disk_first(node, vmid, exclude_device=device)
# Новый порядок загрузки применяется только при power-cycle QEMU (гостевой
# reboot конфиг не перечитывает). Перезапускаем лишь запущенную ВМ.
if boot_disk_set and body.reboot_after:
status = client.get_vm_status(node, vmid) or {}
if status.get('status') == 'running':
rebooted = client.hybrid_restart_vm(node, vmid)
LoggingService.log_proxmox_action(
db=db, action='detach-iso', resource_type='vm', resource_id=vmid,
username=current_user.username, server_id=server_id,
server_name=server.name, node_name=node,
details={'device': device, 'boot_from_disk': boot_disk_set, 'rebooted': rebooted},
success=True,
)
return {"status": "success", "boot_from_disk": boot_disk_set, "rebooted": rebooted}
# ══════════════════════════════════════════════════════════════════════════