Refactor VM provisioning pipeline into focused services and add IP pool

management
This commit is contained in:
baodev0
2026-05-29 12:03:35 +07:00
parent 6bb4a47bfb
commit 7ae237ee9d
32 changed files with 1170 additions and 1200 deletions
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Services\VirtualMachine;
use App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Throwable;
class VmPowerService
{
public function start(vCenter $vCenter, string $vmId): array|string
{
try {
if (!$vCenter->checkApiExits()) {
return 'Login_Again';
}
$response = Http::withoutVerifying()
->withHeaders(['vmware-api-session-id' => $vCenter->token])
->post("https://{$vCenter->apiUri}/rest/vcenter/vm/{$vmId}/power/start");
if ($response->status() === 200) {
return ['error' => false, 'data' => 'success'];
}
return ['error' => true, 'data' => $response->body()];
} catch (Throwable $e) {
Log::error('VmPowerService: start VM failed: ' . $e->getMessage());
return ['error' => true, 'data' => $e->getMessage()];
}
}
}