56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Customer;
|
|
use App\Services\Hosting\Proxmox\ProxmoxClient;
|
|
use App\Services\Hosting\Proxmox\VmManagementService;
|
|
use App\Services\Hosting\Snapshots\SnapshotService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class VmIsoController extends Controller
|
|
{
|
|
public function store(Request $request, Customer $vm, VmManagementService $management, SnapshotService $snapshots): RedirectResponse
|
|
{
|
|
$this->authorize('manage', $vm);
|
|
|
|
$data = $request->validate([
|
|
'iso_volid' => ['required', 'string', 'max:255'],
|
|
]);
|
|
|
|
$snapshots->autoBeforeDestructive($vm, $request->user(), 'iso-mount');
|
|
|
|
try {
|
|
$management->mountIso($vm, $data['iso_volid'], $request->user());
|
|
} catch (\Throwable $e) {
|
|
return back()->withErrors(['iso' => $e->getMessage()]);
|
|
}
|
|
|
|
return back()->with('success', 'ISO wurde eingebunden. VM ggf. neu starten, um vom Installationsmedium zu booten.');
|
|
}
|
|
|
|
public function destroy(Request $request, Customer $vm, VmManagementService $management): RedirectResponse
|
|
{
|
|
$this->authorize('manage', $vm);
|
|
|
|
try {
|
|
$management->unmountIso($vm, $request->user());
|
|
} catch (\Throwable $e) {
|
|
return back()->withErrors(['iso' => $e->getMessage()]);
|
|
}
|
|
|
|
return back()->with('success', 'ISO wurde entfernt.');
|
|
}
|
|
|
|
public function index(ProxmoxClient $proxmox): \Illuminate\Http\JsonResponse
|
|
{
|
|
try {
|
|
return response()->json(['isos' => $proxmox->listIsos()]);
|
|
} catch (\Throwable $e) {
|
|
return response()->json(['error' => $e->getMessage()], 502);
|
|
}
|
|
}
|
|
}
|