feat: Enhance vCenter integration with resource pool and folder support

- Added methods to ResourceService for fetching resource pools and updated existing methods to include datacenter filtering.
- Modified CreateVirtualMachine to accept folder and resource pool parameters from product data.
- Updated various jobs to synchronize resource pools and include them in the provisioning process.
- Introduced new ModuleResourcePool model and migration for resource pool management.
- Enhanced existing models (ModuleDatastore, ModuleNetwork, Os) to include relationships with vCenter and resource pools.
- Added netmask field to IpPool and updated related logic for IP reservation.
- Improved error handling and logging in VM creation and IP reservation processes.
- Updated API routes to include sync functionality for vCenter.
This commit is contained in:
baodev0
2026-07-21 21:37:28 +07:00
parent 2d43e95855
commit 5d3ed57b32
33 changed files with 708 additions and 152 deletions
+44 -13
View File
@@ -59,10 +59,8 @@ class ResourceService
])
->get("https://{$this->client->apiUri}/rest/vcenter/folder", [
'filter.datacenters.1' => $datacenter,
'filter.type' => "VIRTUAL_MACHINE",
'filter.names' => "vm"
])->json();
if (!isset($response['type'])) {
return $response['value'];
}
@@ -71,11 +69,37 @@ class ResourceService
return "Login_Again";
}
public function getAllDataStore($host = '')
public function getAllResourcePool($host = '', $datacenter = '')
{
if ($this->client->checkApiExits()) {
$params = [];
if (!empty($host)) {
$params['filter.hosts'] = $host;
}
if (!empty($datacenter)) {
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
->get("https://{$this->client->apiUri}/rest/vcenter/resource-pool", $params)->json();
if (!isset($response['type'])) {
return $response['value'];
}
return false;
}
return "Login_Again";
}
public function getAllDataStore($host = '', $datacenter = '')
{
Log::info('[vCenter] getAllDataStore call', [
'api' => $this->client->apiUri,
'host_filter' => $host
'host_filter' => $host,
'datacenter_filter' => $datacenter
]);
if (!$this->client->checkApiExits()) {
@@ -87,6 +111,9 @@ class ResourceService
if (!empty($host)) {
$params['filter.hosts'] = $host;
}
if (!empty($datacenter)) {
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
->withHeaders([
@@ -107,13 +134,14 @@ class ResourceService
return false;
}
public function loadDatastore($host_id = '')
public function loadDatastore($host_id = '', $datacenter_id = '')
{
Log::info('[vCenter] loadDatastore()', [
'esxi_host' => $host_id
'esxi_host' => $host_id,
'datacenter' => $datacenter_id
]);
$allDatastore = $this->getAllDataStore($host_id);
$allDatastore = $this->getAllDataStore($host_id, $datacenter_id);
if ($allDatastore === "Login_Again") {
Log::warning('[vCenter] Token expired when getAllDataStore');
@@ -132,13 +160,16 @@ class ResourceService
return $allDatastore;
}
public function getAllNetwork($host = '')
public function getAllNetwork($host = '', $datacenter = '')
{
if ($this->client->checkApiExits()) {
$params = [];
if (!empty($host)) {
$params['filter.hosts'] = $host;
}
if (!empty($datacenter)) {
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
->withHeaders([
@@ -154,14 +185,14 @@ class ResourceService
return "Login_Again";
}
public function loadNetWork($host_id = '')
public function loadNetWork($host_id = '', $datacenter_id = '')
{
return $this->getAllNetwork($host_id);
return $this->getAllNetwork($host_id, $datacenter_id);
}
public function getNetwork($host = ''): array|bool|string
public function getNetwork($host = '', $datacenter = ''): array|bool|string
{
return $this->getAllNetwork($host);
return $this->getAllNetwork($host, $datacenter);
}
public function GetFolderByHost($datacenter = '')