From a7e2b8184b1e99230af1a3dccdb2d12267dfc46f Mon Sep 17 00:00:00 2001 From: "ricardo.bartels@telekom.de" Date: Mon, 23 Jan 2023 21:46:33 +0100 Subject: [PATCH] fixes issue with IPs moved from offline devices/VMs in vcenter source #224 --- module/sources/common/source_base.py | 7 ++++++- module/sources/vmware/connection.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/module/sources/common/source_base.py b/module/sources/common/source_base.py index 8865fd5..0a2f0b9 100644 --- a/module/sources/common/source_base.py +++ b/module/sources/common/source_base.py @@ -425,6 +425,10 @@ class SourceBase: current_nic_enabled = grab(current_ip_nic, "data.enabled", fallback=True) this_nic_enabled = grab(interface_object, "data.enabled", fallback=True) + # if device or VM is NOT active, set current nic status to disabled + if "active" not in str(grab(current_ip_device, "data.status")): + current_nic_enabled = False + if current_nic_enabled is True and this_nic_enabled is False: log.debug(f"Current interface '{current_ip_nic.get_display_name()}' for IP '{ip_object}'" f" is enabled and this one '{interface_object.get_display_name()}' is disabled. " @@ -447,7 +451,8 @@ class SourceBase: f"'{ip_object}' and this one '{interface_object.get_display_name()}' are " f"both {state}.") - if hasattr(self, "objects_to_reevaluate") and vmware_object is not None: + if hasattr(self, "objects_to_reevaluate") and vmware_object is not None and \ + getattr(self, "parsing_objects_to_reevaluate", True) is False: if vmware_object not in self.objects_to_reevaluate: self.objects_to_reevaluate.append(vmware_object) this_log_handler = log.debug diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index d92b11c..9d9af1b 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -211,6 +211,7 @@ class VMWareHandler(SourceBase): self.object_cache = dict() self.parsing_vms_the_first_time = True self.objects_to_reevaluate = list() + self.parsing_objects_to_reevaluate = False def parse_config_settings(self, config_settings): """ @@ -635,8 +636,11 @@ class VMWareHandler(SourceBase): container_view.Destroy() + self.parsing_objects_to_reevaluate = True + log.info("Parsing objects which were marked to be reevaluated") + for obj in self.objects_to_reevaluate: - log.info("Parsing objects which were marked to be reevaluated") + if isinstance(obj, vim.HostSystem): self.add_host(obj) elif isinstance(obj, vim.VirtualMachine):