feat: Implement comprehensive vCenter integration with new services for VM configuration, power management, templates, snapshots, and resource management, alongside infrastructure management and synchronization job updates.

This commit is contained in:
pbao9
2026-02-12 17:23:01 +07:00
parent f3a679d7f3
commit 64c3182b00
16 changed files with 1979 additions and 223 deletions
@@ -0,0 +1,175 @@
<?php
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class PowerManagementService
{
protected Client $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function SuspendVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id/power/suspend");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function RebootVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id/guest/power?action=reboot");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function StartVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id/power/start");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function ShutdownGuestVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id/guest/power?action=shutdown");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function PowerOffVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id/power/stop");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function DeleteVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->delete("https://{$this->client->apiUri}/rest/vcenter/vm/$vmware_id");
if ($response->status() === 200) {
return [
'error' => false,
'data' => 'success'
];
}
return [
'error' => true,
'data' => $response['value']
];
}
return "Login_Again";
}
public function GetConsoleTickets($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->post("https://{$this->client->apiUri}/api/vcenter/vm/$vmware_id/console/tickets", [
"type" => "WEBMKS"
])->json();
if (!isset($response['error_type'])) {
$start = strpos($response['ticket'], '/ticket/');
$ticket = str_replace('/ticket/', '', substr($response['ticket'], $start));
return [
'error' => false,
'data' => $ticket
];
}
return [
'error' => true,
'data' => $response['messages']
];
}
return "Login_Again";
}
}