CluPilotCloud/app/Provisioning/Steps/Host/RegisterCapacity.php

49 lines
1.3 KiB
PHP

<?php
namespace App\Provisioning\Steps\Host;
use App\Models\ProvisioningRun;
use App\Provisioning\StepResult;
use App\Services\Proxmox\ProxmoxClient;
/**
* Reads node capacity from Proxmox and stores it on the host so placement can
* use it. Idempotent (overwrites).
*/
class RegisterCapacity extends HostStep
{
public function __construct(private ProxmoxClient $pve) {}
public function key(): string
{
return 'register_capacity';
}
public function execute(ProvisioningRun $run): StepResult
{
$host = $this->host($run);
$client = $this->pve->forHost($host);
$nodes = $client->listNodes();
$node = $nodes[0]['node'] ?? 'pve';
$status = $client->nodeStatus($node);
$storage = $client->nodeStorage($node);
$cores = (int) ($status['cpuinfo']['cpus'] ?? 0);
$ramMb = (int) round((int) ($status['memory']['total'] ?? 0) / 1048576);
$totalGb = (int) round(array_sum(array_column($storage, 'total')) / 1073741824);
$host->update([
'cpu_cores' => $cores,
'cpu_weight' => $cores,
'total_ram_mb' => $ramMb,
'total_gb' => $totalGb,
'pve_version' => $status['pveversion'] ?? null,
'last_seen_at' => now(),
]);
return StepResult::advance();
}
}