diff --git a/app/Livewire/Services/Show.php b/app/Livewire/Services/Show.php index 6d295fb92..0ac1be0cb 100644 --- a/app/Livewire/Services/Show.php +++ b/app/Livewire/Services/Show.php @@ -6,6 +6,7 @@ use App\Helpers\ExtensionHelper; use App\Livewire\Component; use App\Models\Service; use Paymenter\Extensions\Servers\Proxmox\Models\Server as ProxmoxServer; +use Paymenter\Extensions\Servers\Proxmox\Proxmox; use Livewire\Attributes\Locked; use Livewire\Attributes\Url; @@ -15,6 +16,11 @@ class Show extends Component public ?ProxmoxServer $proxmoxServer = null; + /** + * Actual VM status from Proxmox API (includes maxmem, maxdisk, cpus, etc.) + */ + public ?array $vmStatus = null; + #[Locked] public $buttons = []; @@ -30,7 +36,12 @@ class Show extends Component public function mount() { // Attach Proxmox server (if any) so we can show hostname on the service page - $this->proxmoxServer = ProxmoxServer::with('os')->where('service_id', $this->service->id)->first(); + $this->proxmoxServer = ProxmoxServer::with(['os', 'node'])->where('service_id', $this->service->id)->first(); + + // Fetch actual VM status from Proxmox API if server exists + if ($this->proxmoxServer) { + $this->loadVmStatus(); + } // Only fetch the actions if the service is active if ($this->service->status == Service::STATUS_ACTIVE) { @@ -88,6 +99,27 @@ class Show extends Component $this->redirect($result); } + /** + * Load the actual VM status from Proxmox API. + */ + protected function loadVmStatus(): void + { + try { + if (!$this->proxmoxServer || !$this->proxmoxServer->node) { + return; + } + + $proxmox = new Proxmox(); + $data = $proxmox->request( + '/nodes/' . $this->proxmoxServer->node->name . '/qemu/' . $this->proxmoxServer->vm_id . '/status/current' + )->json()['data'] ?? null; + + $this->vmStatus = $data; + } catch (\Throwable $e) { + $this->vmStatus = null; + } + } + public function render() { $view = null; diff --git a/themes/lucentui/views/services/show.blade.php b/themes/lucentui/views/services/show.blade.php index 59b42bf6e..ce7afb638 100644 --- a/themes/lucentui/views/services/show.blade.php +++ b/themes/lucentui/views/services/show.blade.php @@ -126,49 +126,42 @@ - @if($proxmoxServer) - @php - $cores = $service->product->settings()->where('key', 'cores')->first()?->value; - $memory = $service->product->settings()->where('key', 'memory')->first()?->value; - $disk = $service->product->settings()->where('key', 'disk')->first()?->value; - $bandwidth = $service->product->settings()->where('key', 'bandwidth')->first()?->value; - @endphp + @if($proxmoxServer && $vmStatus)