feat: implement VM snapshot management, enhance client resource loading, and refactor deployment workflow for production
This commit is contained in:
@@ -6,8 +6,10 @@ use App\Actions\VM\ChangeIpVMAction;
|
||||
use App\Actions\VM\ChangePortVMAction;
|
||||
use App\Actions\VM\PowerOffVMAction;
|
||||
use App\Actions\VM\PowerOnVMAction;
|
||||
use App\Http\Controllers\Api\Service\Concerns\ResolvesVm;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -16,6 +18,9 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class VmController extends Controller
|
||||
{
|
||||
use ResolvesVm {
|
||||
ResolvesVm::resolveVmById as resolveVmForClient;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Power ON
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -240,6 +245,65 @@ class VmController extends Controller
|
||||
], 400);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Console Ticket
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function consoleTicket(Request $request, vCenter $serviceVCenter): JsonResponse
|
||||
{
|
||||
$productId = $request->get('product');
|
||||
if (!$productId) {
|
||||
return response()->json(['error' => true, 'message' => 'Please choose product']);
|
||||
}
|
||||
|
||||
$vm = ModuleVmware::with('vCenter')->find((int) $productId);
|
||||
if (!$vm) {
|
||||
return response()->json(['error' => true, 'message' => "Can't find product"]);
|
||||
}
|
||||
|
||||
$result = $this->getConsoleTicket($serviceVCenter, $vm);
|
||||
if ($result instanceof JsonResponse) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $result['data'],
|
||||
]);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Restart VM
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function restart(Request $request, vCenter $serviceVCenter): JsonResponse
|
||||
{
|
||||
$productId = $request->input('product');
|
||||
if (!$productId) {
|
||||
return response()->json(['error' => true, 'message' => 'Thiếu product id'], 422);
|
||||
}
|
||||
|
||||
$vm = $this->resolveVmForClient($productId, $request);
|
||||
if ($vm instanceof JsonResponse) {
|
||||
return $vm;
|
||||
}
|
||||
|
||||
$result = $serviceVCenter->restartVM($vm, $vm->vmware_id);
|
||||
|
||||
if (is_string($result) || ($result['error'] ?? true)) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => is_string($result) ? $result : ($result['data'] ?? 'Không thể restart VM'),
|
||||
], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã gửi lệnh restart VM',
|
||||
'data' => $result['data'] ?? 'success',
|
||||
]);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Shared helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user