feat: enhance slot availability check for reattaching drives in Proxmox configuration

This commit is contained in:
2025-12-05 06:05:38 -05:00
parent d467368ed8
commit b0388874d5

View File

@@ -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');