initial commit
This commit is contained in:
42
app/Http/Controllers/Web/VmStatusController.php
Normal file
42
app/Http/Controllers/Web/VmStatusController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Services\Hosting\Proxmox\VmManagementService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VmStatusController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, Customer $vm, VmManagementService $management): JsonResponse
|
||||
{
|
||||
$this->authorize('view', $vm);
|
||||
|
||||
if (! $vm->vmid || $vm->status !== 'active') {
|
||||
return response()->json([
|
||||
'status' => $vm->status,
|
||||
'proxmox' => null,
|
||||
'message' => 'VM nicht bereit',
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$live = $management->refreshLiveStatus($vm);
|
||||
|
||||
return response()->json([
|
||||
'status' => $vm->status,
|
||||
'proxmox' => $live,
|
||||
'attached_iso' => $vm->attached_iso,
|
||||
'refreshed_at' => $vm->proxmox_status_at?->toIso8601String(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'status' => $vm->status,
|
||||
'proxmox' => null,
|
||||
'error' => $e->getMessage(),
|
||||
], 502);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user