feat: update drive detachment logic to preserve volume data by moving to unused slot
This commit is contained in:
@@ -760,6 +760,7 @@ class Storage extends Component
|
||||
}
|
||||
|
||||
$driveKey = $this->detachingDriveKey;
|
||||
$drive = $this->drives[$driveKey];
|
||||
|
||||
// Check VM status - must be stopped to detach
|
||||
if ($this->status && $this->status->status !== 'stopped') {
|
||||
@@ -770,11 +771,24 @@ class Storage extends Component
|
||||
try {
|
||||
$proxmox = new Proxmox;
|
||||
|
||||
// Use the delete parameter to remove the disk from the config (keeps the volume as unused)
|
||||
// Get current config to find next unused slot
|
||||
$config = $proxmox->request(
|
||||
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config'
|
||||
);
|
||||
|
||||
// Find the next available unused slot
|
||||
$unusedIndex = 0;
|
||||
while (isset($config['data']['unused' . $unusedIndex])) {
|
||||
$unusedIndex++;
|
||||
}
|
||||
|
||||
// Move the disk to an unused slot instead of deleting it
|
||||
// This preserves the volume data
|
||||
$proxmox->request(
|
||||
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config',
|
||||
'put',
|
||||
[
|
||||
'unused' . $unusedIndex => $drive['volume'],
|
||||
'delete' => $driveKey,
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user