Fetch and display actual VM status from Proxmox API in service view
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -126,49 +126,42 @@
|
||||
</div>
|
||||
|
||||
<!-- Server Specifications Card (Proxmox) -->
|
||||
@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)
|
||||
<div class="bg-gradient-to-br from-background/50 to-background/20 border border-neutral/20 rounded-2xl p-6 backdrop-blur-sm hover:shadow-lg transition-all duration-300">
|
||||
<div class="flex items-center gap-3 mb-6">
|
||||
<x-ri-cpu-line class="size-6 text-primary" />
|
||||
<h3 class="uppercase font-black text-color-base text-sm tracking-wider">Server Specifications</h3>
|
||||
</div>
|
||||
<div class="space-y-4">
|
||||
@if($cores)
|
||||
@if(isset($vmStatus['cpus']))
|
||||
<div class="flex items-center justify-between py-3 px-4 bg-background/50 rounded-xl">
|
||||
<span class="text-color-muted text-sm font-medium flex items-center gap-2">
|
||||
<x-ri-cpu-line class="size-4" /> CPU Cores
|
||||
</span>
|
||||
<span class="font-bold text-color-base">{{ $cores }} {{ $cores == 1 ? 'Core' : 'Cores' }}</span>
|
||||
<span class="font-bold text-color-base">{{ $vmStatus['cpus'] }} {{ $vmStatus['cpus'] == 1 ? 'Core' : 'Cores' }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if($memory)
|
||||
@if(isset($vmStatus['maxmem']))
|
||||
<div class="flex items-center justify-between py-3 px-4 bg-background/50 rounded-xl">
|
||||
<span class="text-color-muted text-sm font-medium flex items-center gap-2">
|
||||
<x-ri-ram-2-line class="size-4" /> Memory
|
||||
</span>
|
||||
<span class="font-bold text-color-base">
|
||||
@if($memory >= 1024)
|
||||
{{ round($memory / 1024, 1) }} GB
|
||||
@else
|
||||
{{ $memory }} MB
|
||||
@endif
|
||||
{{ round($vmStatus['maxmem'] / (1024 * 1024 * 1024), 2) }} GB
|
||||
</span>
|
||||
</div>
|
||||
@endif
|
||||
@if($disk)
|
||||
@if(isset($vmStatus['maxdisk']))
|
||||
<div class="flex items-center justify-between py-3 px-4 bg-background/50 rounded-xl">
|
||||
<span class="text-color-muted text-sm font-medium flex items-center gap-2">
|
||||
<x-ri-hard-drive-2-line class="size-4" /> Storage
|
||||
</span>
|
||||
<span class="font-bold text-color-base">{{ $disk }} GB</span>
|
||||
<span class="font-bold text-color-base">{{ Illuminate\Support\Number::fileSize(bytes: $vmStatus['maxdisk']) }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@php
|
||||
$bandwidth = $service->product->settings()->where('key', 'bandwidth')->first()?->value;
|
||||
@endphp
|
||||
@if($bandwidth)
|
||||
<div class="flex items-center justify-between py-3 px-4 bg-background/50 rounded-xl">
|
||||
<span class="text-color-muted text-sm font-medium flex items-center gap-2">
|
||||
|
||||
Reference in New Issue
Block a user