From 8ad1b158ee8c9c33bc3085cc198d93a0a7d795ad Mon Sep 17 00:00:00 2001 From: "ricardo.bartels@telekom.de" Date: Wed, 24 Jan 2024 23:27:03 +0100 Subject: [PATCH] adds config options overwrite_device/vm_platform to VMware source #362 --- module/sources/common/source_base.py | 1 - module/sources/vmware/config.py | 16 +++++++++++++--- module/sources/vmware/connection.py | 9 +++++++++ settings-example.ini | 7 +++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/module/sources/common/source_base.py b/module/sources/common/source_base.py index 53a1f09..11926e9 100644 --- a/module/sources/common/source_base.py +++ b/module/sources/common/source_base.py @@ -747,7 +747,6 @@ def add_vlan_object_to_netbox(self, vlan_data, site_name=None): for excluded_vlan in vlan_sync_exclude_by_name or list(): if excluded_vlan.matches(vlan_name, site_name): - print("return FALSE") return False for excluded_vlan in vlan_sync_exclude_by_id or list(): diff --git a/module/sources/vmware/config.py b/module/sources/vmware/config.py index 856dc36..7d0465d 100644 --- a/module/sources/vmware/config.py +++ b/module/sources/vmware/config.py @@ -123,9 +123,9 @@ def __init__(self): A VM always depends on the cluster site relation a cluster can be specified as "Cluster-name" or "Datacenter-name/Cluster-name" if multiple clusters have the same name. - When a vCenter cluster consists of hosts from multiple NetBox sites, - it is possible to leave the site for a NetBox cluster empty. All VMs from - this cluster will then also have no site reference. + When a vCenter cluster consists of hosts from multiple NetBox sites, + it is possible to leave the site for a NetBox cluster empty. All VMs from + this cluster will then also have no site reference. The keyword "" can be used as a value for this. """, config_example="Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio, Cluster_MultiSite = "), @@ -336,6 +336,16 @@ def __init__(self): description="""define if the name of the VM interface discovered overwrites the interface name in NetBox. The interface will only be matched by identical MAC address""", default_value=True), + ConfigOption("overwrite_device_platform", + bool, + description="""define if the platform of the device discovered overwrites the device + platform in NetBox.""", + default_value=True), + ConfigOption("overwrite_vm_platform", + bool, + description="""define if the platform of the VM discovered overwrites the VM + platform in NetBox.""", + default_value=True), ConfigOption("host_management_interface_match", str, description="""set a matching value for ESXi host management interface description diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index 66757f8..aa5b1d2 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -1065,6 +1065,15 @@ def add_device_vm_to_inventory(self, object_type, object_data, pnic_data=None, v log.debug(f"No existing {object_type.name} object for {object_name}. Creating a new {object_type.name}.") device_vm_object = self.inventory.add_object(object_type, data=object_data, source=self) else: + + if object_type == NBVM and self.settings.overwrite_vm_platform is False and \ + object_data.get("platform") is not None: + del object_data["platform"] + + if object_type == NBDevice and self.settings.overwrite_device_platform is False and \ + object_data.get("platform") is not None: + del object_data["platform"] + device_vm_object.update(data=object_data, source=self) # add object to cache diff --git a/settings-example.ini b/settings-example.ini index d00fb4f..cebe456 100644 --- a/settings-example.ini +++ b/settings-example.ini @@ -344,6 +344,13 @@ password = super-secret ; NetBox. The interface will only be matched by identical MAC address ;overwrite_vm_interface_name = True +; define if the platform of the device discovered overwrites the device platform in +; NetBox. +;overwrite_device_platform = True + +; define if the platform of the VM discovered overwrites the VM platform in NetBox. +;overwrite_vm_platform = True + ; set a matching value for ESXi host management interface description (case insensitive, ; comma separated). Used to figure out the ESXi primary IP address ;host_management_interface_match = management, mgmt