Skip to content

Commit

Permalink
adds config options overwrite_device/vm_platform to VMware source #362
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Jan 24, 2024
1 parent 824263d commit 8ad1b15
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 0 additions & 1 deletion module/sources/common/source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
16 changes: 13 additions & 3 deletions module/sources/vmware/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<NONE>" can be used as a value for this.
""",
config_example="Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio, Cluster_MultiSite = <NONE>"),
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions module/sources/vmware/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions settings-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ad1b15

Please sign in to comment.