Files
Virtnet.bond/extensions/Servers/Proxmox/Jobs/ReinstallJob.php
Joseph.Rawlings 5f2e591c6e feat: add LXC container support to Proxmox extension
- Add is_lxc boolean column to ext_proxmox_nodes (default false, existing nodes unaffected)
- Add LXC checkbox to admin node creation form (disabled on edit)
- Dynamic API path selection via Node::vmType() (returns 'lxc' or 'qemu')
- LXC deployment: syncLxcSettings() for cores, memory, swap, hostname, rootfs, net config
- LXC network uses name=eth0 format with applyLxcPoolSettings() for VLAN/firewall/MTU
- All lifecycle operations LXC-aware: install, suspend, unsuspend, terminate, upgrade, reinstall
- VNC/xterm console uses correct type (lxc vs kvm)
- All 20+ Livewire components use vmType() for Proxmox API paths
- LXC user interface shows basic-only view (no advanced toggle, no KVM-specific tabs)
- Basic tabs for LXC: Overview, Network Configuration, Backups, Console
2026-03-02 07:11:25 -05:00

85 lines
2.8 KiB
PHP

<?php
namespace Paymenter\Extensions\Servers\Proxmox\Jobs;
use App\Helpers\ExtensionHelper;
use App\Helpers\NotificationHelper;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
class ReinstallJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 5;
public int $timeout = 600; // 10 minutes
/**
* Exponential backoff between retries (seconds).
*/
public array $backoff = [10, 30, 60, 120, 300];
public function __construct(public Server $server) {}
public function handle(): void
{
$proxmox = new Proxmox;
$vmType = $this->server->node->vmType();
// Stop and delete existing VM/CT if it exists
try {
$proxmox->requestAndWait(
'/nodes/' . $this->server->node->name . '/' . $vmType . '/' . $this->server->vm_id . '/status/stop',
'post',
['vmid' => $this->server->vm_id],
$this->server->node->name
);
$proxmox->requestAndWait(
'/nodes/' . $this->server->node->name . '/' . $vmType . '/' . $this->server->vm_id,
'delete',
[],
$this->server->node->name
);
} catch (Exception $e) {
$msg = strtolower($e->getMessage());
// Allow reinstall to proceed if VM doesn't exist or is already stopped
if (!str_contains($msg, 'does not exist')
&& !str_contains($msg, 'not running')
&& !str_contains($msg, 'already stopped')
&& !str_contains($msg, 'is not running')) {
throw $e;
}
}
// Generate a new password
$password = Str::password(16);
// Reinstall server — install() will now use the updated password
$settings = array_merge(ExtensionHelper::settingsToArray($this->server->service->product->settings), ExtensionHelper::getServiceProperties($this->server->service));
$proxmox->install($this->server, $settings, $password);
// Send notification to the user
NotificationHelper::serverCreatedNotification(
$this->server->service->user,
$this->server->service,
[
'password' => $password,
'ip' => $this->server->primaryIpv4?->ip,
'ipv6' => $this->server->primaryIpv6?->ip,
'hostname' => $this->server->hostname,
]
);
}
}