From d01289cd0062f432b1d669f1d4768f500f9bc428 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Sat, 6 Dec 2025 12:35:56 -0500 Subject: [PATCH] Fetch VM configuration to calculate accurate total storage and update display in service view --- app/Livewire/Services/Show.php | 82 +++++++++++++++++++ themes/lucentui/views/services/show.blade.php | 9 +- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Services/Show.php b/app/Livewire/Services/Show.php index 0ac1be0cb..b2439ab0c 100644 --- a/app/Livewire/Services/Show.php +++ b/app/Livewire/Services/Show.php @@ -115,11 +115,93 @@ class Show extends Component )->json()['data'] ?? null; $this->vmStatus = $data; + + // Also fetch VM config to calculate accurate total storage + // The status endpoint's maxdisk is often unreliable + if ($this->vmStatus) { + $config = $proxmox->request( + '/nodes/' . $this->proxmoxServer->node->name . '/qemu/' . $this->proxmoxServer->vm_id . '/config' + )->json()['data'] ?? null; + + if ($config) { + $totalDiskGB = $this->calculateTotalStorage($config); + if ($totalDiskGB > 0) { + // Store as bytes for consistency with other values + $this->vmStatus['total_disk_bytes'] = $totalDiskGB * 1024 * 1024 * 1024; + } + } + } } catch (\Throwable $e) { $this->vmStatus = null; } } + /** + * Calculate total storage from VM config (excluding cloud-init, EFI, TPM). + * Returns size in GB. + */ + protected function calculateTotalStorage(array $config): float + { + $totalSize = 0; + + foreach ($config as $key => $value) { + // Check for attached drives (ide, sata, scsi, virtio) + if (preg_match('/^(ide|sata|scsi|virtio)(\d+)$/', $key)) { + // Skip excluded disks (cloud-init, EFI, TPM) + if ($this->isExcludedDisk($value)) { + continue; + } + // Skip CD-ROM drives + if (str_contains($value, 'media=cdrom')) { + continue; + } + $totalSize += $this->extractDiskSize($value); + } + } + + return $totalSize; + } + + /** + * Check if a disk should be excluded (cloud-init, EFI, TPM). + */ + protected function isExcludedDisk(string $value): bool + { + $excludePatterns = ['cloudinit', 'vm-\d+-cloudinit', 'efidisk', 'tpmstate']; + foreach ($excludePatterns as $pattern) { + if (preg_match('/' . $pattern . '/i', $value)) { + return true; + } + } + return false; + } + + /** + * Extract disk size in GB from a disk configuration string. + */ + protected function extractDiskSize(string $value): float + { + // Example: cephpool:vm-100-disk-0,size=32G,cache=none,ssd=1 + $parts = explode(',', $value); + + foreach ($parts as $part) { + if (preg_match('/^size=(\d+)([KMGT]?)$/i', $part, $sizeMatch)) { + $size = (float) $sizeMatch[1]; + $unit = strtoupper($sizeMatch[2] ?? 'G'); + + switch ($unit) { + case 'K': return $size / (1024 * 1024); + case 'M': return $size / 1024; + case 'G': + case '': return $size; + case 'T': return $size * 1024; + } + } + } + + return 0; + } + public function render() { $view = null; diff --git a/themes/lucentui/views/services/show.blade.php b/themes/lucentui/views/services/show.blade.php index ce7afb638..67863e156 100644 --- a/themes/lucentui/views/services/show.blade.php +++ b/themes/lucentui/views/services/show.blade.php @@ -151,7 +151,14 @@ @endif - @if(isset($vmStatus['maxdisk'])) + @if(isset($vmStatus['total_disk_bytes'])) +
+ + Storage + + {{ Illuminate\Support\Number::fileSize(bytes: $vmStatus['total_disk_bytes']) }} +
+ @elseif(isset($vmStatus['maxdisk']))
Storage