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
@@ -44,8 +44,48 @@ class CheckIPAddress implements ShouldQueue
throw new \Exception(json_encode($DetailVirtualMachine['message']));
}
if (!$DetailVirtualMachine['data']['ip_address'] === $this->data->IpAddress->ip) {
throw new \Exception(json_encode($DetailVirtualMachine['message']));
// Get expected IP address with null safety
$expectedIP = null;
// Try to get IP from old relationship first
if ($this->data && isset($this->data->IpAddress) && $this->data->IpAddress) {
$expectedIP = $this->data->IpAddress->ip;
}
// If no IP from old relationship, try to get from ModuleVmware
if (!$expectedIP && $this->data) {
// Try to find ModuleVmware by vmware_id
$moduleVmware = \App\Models\ModuleVmware::with('ipAddress')
->where('vmware_id', $this->vmware_id)
->first();
if ($moduleVmware && $moduleVmware->ipAddress) {
$expectedIP = $moduleVmware->ipAddress->ip;
}
}
// If still no expected IP, log warning but don't fail
if (!$expectedIP) {
\Illuminate\Support\Facades\Log::warning('⚠️ Không tìm thấy expected IP cho VM', [
'vmware_id' => $this->vmware_id,
'data_class' => $this->data ? get_class($this->data) : 'null',
'has_ip_address_relation' => isset($this->data->IpAddress) && $this->data->IpAddress ? 'yes' : 'no'
]);
// Skip IP check and continue to next job
$jobs_configDB = new ConfigDatabase($this->data, $this->info);
dispatch($jobs_configDB)->delay(now()->addSeconds(5));
return;
}
// Compare actual vs expected IP
if ($DetailVirtualMachine['data']['ip_address'] !== $expectedIP) {
\Illuminate\Support\Facades\Log::warning('⚠️ IP address mismatch', [
'vmware_id' => $this->vmware_id,
'actual_ip' => $DetailVirtualMachine['data']['ip_address'],
'expected_ip' => $expectedIP
]);
throw new \Exception('IP address mismatch: actual=' . $DetailVirtualMachine['data']['ip_address'] . ', expected=' . $expectedIP);
}
$jobs_configDB = new ConfigDatabase($this->data,$this->info);
dispatch($jobs_configDB)->delay(now()->addSeconds(5));