Files
Virtnet.bond/extensions/Servers/Proxmox/Livewire/Reinstall.php
Joseph.Rawlings f394483daa feat: Update Proxmox extension with various improvements and bug fixes
- Change listStates method to accept nullable integer for limit parameter.
- Modify TechnitiumDns class to return structured error messages on failure.
- Enhance VNC and xterm popup routes with user authorization checks.
- Update backups view to improve loading states and add unique keys for dynamic elements.
- Refactor cloud-init view to ensure proper data binding and improve user experience.
- Add wire:key attributes to various elements in views for better Livewire performance.
- Improve error handling and user feedback in the firewall view.
- Update server overview and statistics views to handle potential null values gracefully.
- Add new migration files to extend database schema with user-set icons and notes for Proxmox nodes.
2026-02-23 17:23:01 -05:00

83 lines
2.3 KiB
PHP

<?php
namespace Paymenter\Extensions\Servers\Proxmox\Livewire;
use Paymenter\Extensions\Servers\Proxmox\Models\OS;
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
class Reinstall extends Component
{
public $os;
public bool $visible = false;
public $confirmReinstall = false;
public bool $isProtected = false;
public function mount(Server $server): void
{
parent::mount($server);
$this->os = $server->os_id;
$this->checkProtectedStatus();
}
protected function checkProtectedStatus(): void
{
try {
$proxmox = new Proxmox;
$config = $proxmox->request('/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config')->json()['data'] ?? [];
// Protected can be 1, '1', true, or missing/null
$this->isProtected = isset($config['protection']) && ($config['protection'] == 1 || $config['protection'] === '1' || $config['protection'] === true);
} catch (\Throwable $e) {
// If we can't check, assume not protected
$this->isProtected = false;
}
}
public function reinstall()
{
// Check protected status again before proceeding
$this->checkProtectedStatus();
if ($this->isProtected) {
$this->notify('Cannot reinstall: This server is protected in Proxmox', 'error');
return;
}
$this->validate([
'os' => 'required',
]);
if (!$this->confirmReinstall) {
$this->notify('Please confirm the reinstall', 'error');
return;
}
$this->server->os_id = $this->os;
$this->server->save();
$proxmox = new Proxmox;
$proxmox->reinstall($this->server);
sleep(10);
$this->redirect(route('proxmox.index'), true);
}
public function render()
{
// assuming Server has relation `node()` -> Node model
$locationId = $this->server->node->location_id;
$osList = \Paymenter\Extensions\Servers\Proxmox\Models\Location::findOrFail($locationId)
->os()
->get();
return view('proxmox::reinstall', [
'osList' => $osList,
'isProtected' => $this->isProtected,
]);
}
}