feat: improve slot availability check for drive assignment in Proxmox configuration

This commit is contained in:
2025-12-05 06:03:05 -05:00
parent 63129a61ae
commit d467368ed8

View File

@@ -837,22 +837,34 @@ class Storage extends Component
return;
}
// Get next available index on target bus
$targetIndex = $this->getNextAvailableIndex($targetBus);
try {
$proxmox = new Proxmox;
// Get current config to check actual slot availability
$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;
}
try {
$proxmox = new Proxmox;
$targetKey = $targetBus . $targetIndex;
// 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])) {