From b0388874d5a2a791daf9ecd3cfe1ee5927191771 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Fri, 5 Dec 2025 06:05:38 -0500 Subject: [PATCH] feat: enhance slot availability check for reattaching drives in Proxmox configuration --- .../Servers/Proxmox/Livewire/Storage.php | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Storage.php b/extensions/Servers/Proxmox/Livewire/Storage.php index 9f99d33e1..3e5bf6957 100644 --- a/extensions/Servers/Proxmox/Livewire/Storage.php +++ b/extensions/Servers/Proxmox/Livewire/Storage.php @@ -1070,23 +1070,34 @@ class Storage extends Component $unusedDrive = $this->unusedDrives[$this->reattachingDriveKey]; $targetBus = $this->reattachTargetBus; - // Get next available index on target bus - $targetIndex = $this->getNextAvailableIndex($targetBus); - if ($targetIndex === null) { - $this->notify("No available slots for {$this->busTypes[$targetBus]['label']} drives.", 'error'); - return; - } - - $targetKey = $targetBus . $targetIndex; - try { $proxmox = new Proxmox; - // First, get the current config to retrieve the exact unused disk value + // First, get the current config to check actual slot availability and retrieve the exact unused disk value $config = $proxmox->request( '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config' ); + // Find the next available slot on the target bus by checking actual Proxmox config + $maxIndex = $this->busTypes[$targetBus]['max'] ?? 4; + $targetIndex = null; + + for ($i = 0; $i < $maxIndex; $i++) { + $slotKey = $targetBus . $i; + // Check if this slot is occupied in the actual config + if (!isset($config['data'][$slotKey])) { + $targetIndex = $i; + break; + } + } + + if ($targetIndex === null) { + $this->notify("No available slots for {$this->busTypes[$targetBus]['label']} drives.", 'error'); + return; + } + + $targetKey = $targetBus . $targetIndex; + $unusedValue = $config['data'][$this->reattachingDriveKey] ?? null; if (!$unusedValue) { $this->notify('Unused drive no longer exists. Please refresh the page.', 'error');