fix: add multiqueue support for network interfaces and update original state handling

This commit is contained in:
2025-12-04 21:49:55 -05:00
parent 6d00d76c5b
commit e5460fcb7a

View File

@@ -47,6 +47,9 @@ class Network extends Component
$this->interfaceSelections = collect($this->interfaces)
->map(fn ($meta) => $meta['model'] ?? 'virtio')
->toArray();
$this->interfaceMultiqueues = collect($this->interfaces)
->map(fn ($meta) => $meta['queues'] ?? 1)
->toArray();
$this->selectedInterface = array_key_first($this->interfaces) ?? 'net0';
$this->interfaceType = $this->interfaceSelections[$this->selectedInterface] ?? 'virtio';
$this->canRemoveInterfaces = count($this->interfaces) > 1;
@@ -55,6 +58,7 @@ class Network extends Component
if (empty($this->original)) {
$this->original = [
'interfaceSelections' => json_decode(json_encode($this->interfaceSelections), true),
'interfaceMultiqueues' => json_decode(json_encode($this->interfaceMultiqueues), true),
];
}
}
@@ -380,6 +384,25 @@ class Network extends Component
}
}
// Also check interfaceMultiqueues
$originalInterfaceMultiqueues = isset($this->original['interfaceMultiqueues']) && is_array($this->original['interfaceMultiqueues'])
? $this->original['interfaceMultiqueues']
: [];
$currentInterfaceMultiqueues = is_array($this->interfaceMultiqueues) ? $this->interfaceMultiqueues : [];
ksort($originalInterfaceMultiqueues);
ksort($currentInterfaceMultiqueues);
if (count($originalInterfaceMultiqueues) !== count($currentInterfaceMultiqueues)) {
return false;
}
foreach ($originalInterfaceMultiqueues as $key => $value) {
if (!isset($currentInterfaceMultiqueues[$key]) || $currentInterfaceMultiqueues[$key] !== $value) {
return false;
}
}
return true;
}
@@ -477,6 +500,7 @@ class Network extends Component
// Update original values after successful save
$this->original = [
'interfaceSelections' => json_decode(json_encode($this->interfaceSelections), true),
'interfaceMultiqueues' => json_decode(json_encode($this->interfaceMultiqueues), true),
];
$this->notify(strtoupper($this->selectedInterface) . ' updated to ' . strtoupper($targetType) . '.', 'success');
@@ -538,6 +562,7 @@ class Network extends Component
// Update original values after refresh
$this->original = [
'interfaceSelections' => json_decode(json_encode($this->interfaceSelections), true),
'interfaceMultiqueues' => json_decode(json_encode($this->interfaceMultiqueues), true),
];
$this->notify('Network interfaces refreshed.', 'success');
@@ -607,6 +632,12 @@ class Network extends Component
);
$this->interfaces[$name]['queues'] = $queues;
// Update original state to reflect the saved change
if (isset($this->original['interfaceMultiqueues'])) {
$this->original['interfaceMultiqueues'][$name] = $queues;
}
$this->notify('Multiqueue updated for ' . strtoupper($name) . ' to ' . $queues . ' queues.', 'success');
} catch (\Exception $e) {
$this->notify('Failed to update multiqueue: ' . $e->getMessage(), 'error');