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;
|
||||
|
||||
Reference in New Issue
Block a user