initial commit
This commit is contained in:
55
app/Http/Controllers/Web/VmIsoController.php
Normal file
55
app/Http/Controllers/Web/VmIsoController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user