CluPilotCloud/app/Services/Proxmox/FakeProxmoxClient.php

71 lines
1.6 KiB
PHP

<?php
namespace App\Services\Proxmox;
use App\Models\Host;
class FakeProxmoxClient implements ProxmoxClient
{
public ?Host $host = null;
/** @var array<int, array<string, mixed>> */
public array $nodes = [['node' => 'pve']];
/** @var array<string, mixed> */
public array $status = [
'cpuinfo' => ['cpus' => 16],
'memory' => ['total' => 68719476736], // 64 GiB
'pveversion' => 'pve-manager/8.2.2',
];
/** @var array<int, array<string, mixed>> */
public array $storage = [
['storage' => 'local-lvm', 'type' => 'lvmthin', 'total' => 1099511627776], // 1 TiB
];
/** @var array<int, string> */
public array $createdRoles = [];
/** @var array{token_id: string, secret: string}|null */
public ?array $createdToken = null;
public int $tokenCalls = 0;
public function forHost(Host $host): static
{
$this->host = $host;
return $this;
}
public function listNodes(): array
{
return $this->nodes;
}
public function nodeStatus(string $node): array
{
return $this->status;
}
public function nodeStorage(string $node): array
{
return $this->storage;
}
public function createRole(string $roleId, string $privs): void
{
$this->createdRoles[] = $roleId;
}
public function createUserAndToken(string $user, string $roleId): array
{
$this->tokenCalls++;
return $this->createdToken = [
'token_id' => $user.'!clupilot',
'secret' => 'fake-secret-'.substr(md5($user.$roleId), 0, 12),
];
}
}