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:
@@ -43,11 +43,11 @@ class VmActiveProviderService
|
||||
|
||||
/** type → [modelClass, parentColumn|null (null = global), childTypes[]] */
|
||||
private const MAP = [
|
||||
self::TYPE_VCENTER => [vCenter::class, null, [self::TYPE_DATACENTER]],
|
||||
self::TYPE_VCENTER => [vCenter::class, null, [self::TYPE_DATACENTER, self::TYPE_DATASTORE, self::TYPE_NETWORK]],
|
||||
self::TYPE_DATACENTER => [ModuleDatacenter::class, 'vcenter_id', [self::TYPE_HOST]],
|
||||
self::TYPE_HOST => [ModuleHost::class, 'module_datacenter_id', [self::TYPE_DATASTORE, self::TYPE_NETWORK]],
|
||||
self::TYPE_DATASTORE => [ModuleDatastore::class, 'module_host_id', []],
|
||||
self::TYPE_NETWORK => [ModuleNetwork::class, 'module_host_id', []],
|
||||
self::TYPE_HOST => [ModuleHost::class, 'module_datacenter_id', []],
|
||||
self::TYPE_DATASTORE => [ModuleDatastore::class, 'vcenter_id', []],
|
||||
self::TYPE_NETWORK => [ModuleNetwork::class, 'vcenter_id', []],
|
||||
];
|
||||
|
||||
public function __construct(private readonly VmProviderSettingsService $providerSettings)
|
||||
@@ -77,16 +77,16 @@ class VmActiveProviderService
|
||||
->first();
|
||||
}
|
||||
|
||||
public function activeDatastore(int $hostId): ?ModuleDatastore
|
||||
public function activeDatastore(int $vcenterId): ?ModuleDatastore
|
||||
{
|
||||
return ModuleDatastore::where('module_host_id', $hostId)
|
||||
return ModuleDatastore::where('vcenter_id', $vcenterId)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function activeNetwork(int $hostId): ?ModuleNetwork
|
||||
public function activeNetwork(int $vcenterId): ?ModuleNetwork
|
||||
{
|
||||
return ModuleNetwork::where('module_host_id', $hostId)
|
||||
return ModuleNetwork::where('vcenter_id', $vcenterId)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
}
|
||||
@@ -113,14 +113,14 @@ class VmActiveProviderService
|
||||
throw new RuntimeException("Datacenter active id={$datacenter->id} chưa có Host nào active.");
|
||||
}
|
||||
|
||||
$datastore = $this->activeDatastore($host->id);
|
||||
$datastore = $this->activeDatastore($vcenter->id);
|
||||
if (!$datastore) {
|
||||
throw new RuntimeException("Host active id={$host->id} chưa có Datastore nào active.");
|
||||
throw new RuntimeException("vCenter active id={$vcenter->id} chưa có Datastore nào active.");
|
||||
}
|
||||
|
||||
$network = $this->activeNetwork($host->id);
|
||||
$network = $this->activeNetwork($vcenter->id);
|
||||
if (!$network) {
|
||||
throw new RuntimeException("Host active id={$host->id} chưa có Network nào active.");
|
||||
throw new RuntimeException("vCenter active id={$vcenter->id} chưa có Network nào active.");
|
||||
}
|
||||
|
||||
return compact('vcenter', 'datacenter', 'host', 'datastore', 'network');
|
||||
|
||||
Reference in New Issue
Block a user