48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Provisioning\Steps\Customer;
|
|
|
|
use App\Models\ProvisioningRun;
|
|
use App\Provisioning\StepResult;
|
|
use App\Services\Proxmox\ProxmoxClient;
|
|
|
|
class ConfigureNetwork extends CustomerStep
|
|
{
|
|
public function __construct(private ProxmoxClient $pve) {}
|
|
|
|
public function key(): string
|
|
{
|
|
return 'configure_network';
|
|
}
|
|
|
|
public function maxDuration(): int
|
|
{
|
|
return 120;
|
|
}
|
|
|
|
public function execute(ProvisioningRun $run): StepResult
|
|
{
|
|
$instance = $this->instance($run);
|
|
$node = (string) $run->context('node');
|
|
$vmid = (int) $run->context('vmid');
|
|
$pve = $this->pve->forHost($instance->host);
|
|
|
|
$this->guest($pve, $run, 'hostnamectl set-hostname '.escapeshellarg($instance->subdomain));
|
|
|
|
// Capture the guest's own address so Traefik can route to the VM (not the host).
|
|
$ipOut = trim($pve->guestExec($node, $vmid, "hostname -I")['out-data'] ?? '');
|
|
$guestIp = trim(strtok($ipOut, ' ') ?: '');
|
|
if ($guestIp !== '') {
|
|
$instance->update(['guest_ip' => $guestIp]);
|
|
}
|
|
|
|
// Allow HTTP/HTTPS, deny everything else (management stays on the tunnel).
|
|
$pve->applyFirewall($node, $vmid, [
|
|
['type' => 'in', 'action' => 'ACCEPT', 'proto' => 'tcp', 'dport' => '80'],
|
|
['type' => 'in', 'action' => 'ACCEPT', 'proto' => 'tcp', 'dport' => '443'],
|
|
]);
|
|
|
|
return StepResult::advance();
|
|
}
|
|
}
|