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
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Http\Facade\SignRSA;
use App\Models\Vcenter;
use Exception;
class Client
{
public ?string $token = null;
public string $apiUri;
private string $username;
private string $password;
public function loginServer(Vcenter $vcenterModel): bool|string
{
$this->apiUri = $vcenterModel->host;
$this->username = $vcenterModel->user;
$this->password = SignRSA::DecryptFunc($vcenterModel->password);
$response = Http::withoutVerifying()
->withBasicAuth($this->username, $this->password)
->post("https://{$this->apiUri}/rest/com/vmware/cis/session", []);
if ($response->successful()) {
$json = $response->json();
if (isset($json['value'])) {
$this->token = $json['value'];
$vcenterModel->update(['token' => $this->token]);
return $this->token;
}
$body = $response->body();
if (!empty($body)) {
$this->token = $body;
$vcenterModel->update(['token' => $this->token]);
return $this->token;
}
}
return false;
}
public function checkApiExits(): bool
{
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->token
])
->get("https://$this->apiUri/rest/com/vmware/content/library")->json();
if (isset($response['type'])) {
return false;
}
return true;
}
public function getUsername(): string
{
return $this->username;
}
public function getPassword(): string
{
return $this->password;
}
}