feat: implement VM snapshot management, enhance client resource loading, and refactor deployment workflow for production
This commit is contained in:
@@ -103,6 +103,39 @@ class vCenter
|
||||
return "Login_Again";
|
||||
}
|
||||
|
||||
/**
|
||||
* Search VM by exact name in vCenter.
|
||||
* Returns the first matching VM array or null if not found.
|
||||
*/
|
||||
public function findVirtualMachineByName(string $vmName): ?array
|
||||
{
|
||||
$check = $this->checkApiExits();
|
||||
if (!$check) {
|
||||
Log::warning('findVirtualMachineByName: API check failed');
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = Http::withoutVerifying()
|
||||
->withHeaders([
|
||||
'vmware-api-session-id' => $this->token
|
||||
])
|
||||
->get("https://$this->apiUri/rest/vcenter/vm", [
|
||||
'filter.names.1' => $vmName,
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::warning('findVirtualMachineByName: HTTP failed', ['status' => $response->status()]);
|
||||
return null;
|
||||
}
|
||||
|
||||
$json = $response->json();
|
||||
if (isset($json['type']) || empty($json['value'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $json['value'][0] ?? null;
|
||||
}
|
||||
|
||||
public function checkApiExits(): bool
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user