41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Hosting\Reinstall;
|
|
|
|
use App\Jobs\ProvisionCustomerJob;
|
|
use App\Models\Customer;
|
|
use App\Models\User;
|
|
use App\Services\Hosting\Proxmox\ProxmoxClient;
|
|
use App\Services\Hosting\Snapshots\SnapshotService;
|
|
|
|
class ReinstallService
|
|
{
|
|
public function __construct(
|
|
private readonly ProxmoxClient $proxmox,
|
|
private readonly SnapshotService $snapshots,
|
|
) {}
|
|
|
|
public function reinstall(Customer $vm, User $user): void
|
|
{
|
|
if (! $vm->vmid) {
|
|
throw new \RuntimeException('VM ist nicht provisioniert.');
|
|
}
|
|
|
|
$this->snapshots->autoBeforeDestructive($vm, $user, 'reinstall');
|
|
|
|
$vmid = (int) $vm->vmid;
|
|
$this->proxmox->stopVM($vmid);
|
|
$this->proxmox->deleteVM($vmid);
|
|
|
|
$vm->update([
|
|
'status' => 'pending',
|
|
'provisioning_step' => 'queued',
|
|
'proxmox_status' => null,
|
|
'proxmox_uptime' => null,
|
|
'error_message' => null,
|
|
]);
|
|
|
|
ProvisionCustomerJob::dispatch($vm->id);
|
|
}
|
|
}
|