feat: improve drive reattachment logic to safely remove unused entry after attaching volume

This commit is contained in:
2025-12-05 04:55:21 -05:00
parent 9f8c4eef04
commit 352b98e0c7

View File

@@ -1023,7 +1023,7 @@ class Storage extends Component
$diskConfig = implode(',', $configParts);
// First, set the disk on the new bus
// First, set the disk on the new bus (this attaches the volume)
$proxmox->request(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config',
'put',
@@ -1032,14 +1032,19 @@ class Storage extends Component
]
);
// Then clear the unused slot (set to empty/none to remove the reference without deleting volume)
$proxmox->request(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config',
'put',
[
$this->reattachingDriveKey => '',
]
);
// Then remove the unused entry using delete parameter
// This is safe because the volume is now attached to the new bus
try {
$proxmox->request(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config',
'put',
[
'delete' => $this->reattachingDriveKey,
]
);
} catch (\Exception $e) {
// Unused entry might already be cleaned up automatically, ignore this error
}
$this->notify("Drive reattached as {$targetKey} successfully.", 'success');
$this->closeReattachModal();