update assign ip windows

This commit is contained in:
Pham Bao
2025-07-29 23:49:33 +07:00
parent 21a2dfe855
commit 5d6e2060a8
4 changed files with 132 additions and 28 deletions
+50 -17
View File
@@ -456,9 +456,11 @@ class vCenter
Log::info('Data payload', ['data' => $body]);
try {
Log::info('Bắt đầu clone VM với timeout 300 giây', ['template' => $template, 'target_name' => $body['spec']['name']]);
$response = Http::withoutVerifying()
->timeout(120)
->connectTimeout(120)
->timeout(300) // Tăng timeout lên 5 phút cho quá trình clone
->connectTimeout(30) // Giữ connect timeout ngắn để phát hiện lỗi kết nối sớm
->withHeaders([
'vmware-api-session-id' => $this->token,
'Content-Type' => 'application/json',
@@ -2130,29 +2132,60 @@ class vCenter
public function assignIPWindows($product, $vmware_id = ''): array|string
{
try {
// Kiểm tra null safety
if (!$product || !$product->ipAddress || !$product->ipAddress->host || !$product->ipAddress->host->datacenter || !$product->ipAddress->host->datacenter->vCenter) {
// Support both old Product structure and new ModuleVmware structure
$ipAddress = null;
$gateway = null;
$netmask = '255.255.255.0';
$dns = '8.8.8.8';
$vmware_name = '';
$vCenter = null;
// Check if it's ModuleVmware (new structure)
if ($product && isset($product->ipAddress) && $product->ipAddress) {
Log::info('✅ Using ModuleVmware structure for assignIPWindows', [
'module_vmware_id' => $product->id,
'vmware_id' => $vmware_id
]);
// Extract from ModuleVmware->ipAddress relationship
$ipAddress = $product->ipAddress->ip ?? null;
$gateway = $product->ipAddress->gateway ?? null;
$netmask = $product->ipAddress->netmask ?? '255.255.255.0';
$dns = $product->ipAddress->dns ?? '8.8.8.8';
$vmware_name = $product->name ?? $vmware_id;
$vCenter = $product->ipAddress->host->datacenter->vCenter ?? null;
} elseif ($product && isset($product->IpAddress) && $product->IpAddress) {
Log::info('✅ Using old Product structure for assignIPWindows', [
'product_id' => $product->id,
'vmware_id' => $vmware_id
]);
// Extract from old Product->IpAddress relationship
$ipAddress = $product->IpAddress->ip ?? null;
$gateway = $product->IpAddress->gateway ?? null;
$netmask = $product->IpAddress->netmask ?? '255.255.255.0';
$dns = $product->IpAddress->dns ?? '8.8.8.8';
$vmware_name = $product->name ?? $vmware_id;
$vCenter = $product->IpAddress->Host->Datacenter->vCenter ?? null;
}
// Validate required data
if (!$ipAddress || !$gateway || !$vCenter) {
Log::error('❌ assignIPWindows: Missing required data', [
'vmware_id' => $vmware_id,
'product_id' => $product?->id ?? 'unknown',
'ip_address' => $product?->ipAddress?->ip ?? 'unknown',
'host' => $product?->ipAddress?->host?->name ?? 'unknown',
'datacenter' => $product?->ipAddress?->host?->datacenter?->name ?? 'unknown',
'vcenter' => $product?->ipAddress?->host?->datacenter?->vCenter?->host ?? 'unknown'
'ip_address' => $ipAddress,
'gateway' => $gateway,
'has_vcenter' => $vCenter ? 'yes' : 'no',
'product_class' => get_class($product)
]);
return [
'error' => true,
'data' => 'Missing required data for IP assignment'
'data' => 'Missing required data for IP assignment (IP, Gateway, or vCenter)'
];
}
$this->SetConfig($product->ipAddress->host->datacenter->vCenter);
$vmware_name = (string) $product->name;
$ipAddress = $product->ipAddress->ip;
$gateway = $product->ipAddress->gateway;
$netmask = $product->ipAddress->netmask ?? '255.255.255.0';
$dns = $product->ipAddress->dns ?? '8.8.8.8';
$this->SetConfig($vCenter);
// Convert netmask to prefix length (e.g., 255.255.255.0 = 24)
$maskBits = $this->convertNetmaskToPrefixLength($netmask);