CluPilotCloud/app/Services/Proxmox/HttpProxmoxClient.php

53 lines
1.5 KiB
PHP

<?php
namespace App\Services\Proxmox;
use App\Models\Host;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
/**
* Real Proxmox VE REST client (read-only in A: capacity + reachability). Token
* auth over the WireGuard tunnel; the PVE certificate is self-signed so TLS
* verification is disabled (traffic already runs inside the encrypted tunnel).
* Not unit-tested (live I/O). The automation token itself is bootstrapped via
* SSH `pveum` (see CreateAutomationToken), not here.
*/
class HttpProxmoxClient implements ProxmoxClient
{
private string $baseUrl = '';
private string $token = '';
public function forHost(Host $host): static
{
$this->baseUrl = 'https://'.$host->wg_ip.':8006/api2/json';
$this->token = (string) $host->api_token_ref;
return $this;
}
private function http(): PendingRequest
{
return Http::withoutVerifying()
->withHeaders(['Authorization' => 'PVEAPIToken='.$this->token])
->baseUrl($this->baseUrl)
->timeout(15);
}
public function listNodes(): array
{
return $this->http()->get('/nodes')->throw()->json('data', []);
}
public function nodeStatus(string $node): array
{
return $this->http()->get("/nodes/{$node}/status")->throw()->json('data', []);
}
public function nodeStorage(string $node): array
{
return $this->http()->get("/nodes/{$node}/storage")->throw()->json('data', []);
}
}