initial commit
This commit is contained in:
40
app/Services/Hosting/Reinstall/ReinstallService.php
Normal file
40
app/Services/Hosting/Reinstall/ReinstallService.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user