adds config option 'host_nic_exclude_by_mac_list' #280

This commit is contained in:
Ricardo Bartels
2023-05-23 21:58:03 +02:00
parent 3089543f31
commit b899f4869f
3 changed files with 36 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ from module.config.group import ConfigOptionGroup
from module.sources.common.conifg import *
from module.sources.common.permitted_subnets import PermittedSubnets
from module.common.logging import get_logger
from module.common.support import normalize_mac_address
log = get_logger()
@@ -329,6 +330,13 @@ class VMWareConfig(ConfigBase):
synchronisation by setting this option to 'False'
""",
default_value=True),
ConfigOption("host_nic_exclude_by_mac_list",
str,
description="""defines a comma separated list of MAC addresses which should be excluded
from sync. Any host NIC with a matching MAC address will be excluded from sync.
""",
config_example="AA:BB:CC:11:22:33, 66:77:88:AA:BB:CC"
),
# removed settings
ConfigOption("netbox_host_device_role",
@@ -474,6 +482,22 @@ class VMWareConfig(ConfigBase):
log.error("Config option 'ip_tenant_inheritance_order' can contain only 2 items max")
self.set_validation_failed()
if option.key == "host_nic_exclude_by_mac_list":
value_list = list()
for mac_address in quoted_split(option.value) or list():
normalized_mac_address = normalize_mac_address(mac_address)
if len(f"{normalized_mac_address}") != 17:
log.error(f"MAC address '{mac_address}' for 'host_nic_exclude_by_mac_list' invalid.")
self.set_validation_failed()
else:
value_list.append(normalized_mac_address)
option.set_value(value_list)
permitted_subnets_option = self.get_option_by_name("permitted_subnets")
if permitted_subnets_option is not None:

View File

@@ -493,7 +493,7 @@ class VMWareHandler(SourceBase):
the highest amount of matching interfaces. If the ration of matching interfaces
exceeds 2.0 then the top matching machine is chosen as desired object.
If the ration is below 2.0 then None will be returned. The probability is to low that
If the ration is below 2.0 then None will be returned. The probability is too low that
this one is the correct one.
None will also be returned if no machine was found at all.
@@ -1738,10 +1738,16 @@ class VMWareHandler(SourceBase):
"vid": pg_data.get("vlan_id")
})
pnic_mac_address = normalize_mac_address(grab(pnic, "mac"))
if pnic_mac_address in self.settings.host_nic_exclude_by_mac_list:
log.debug2(f"Host NIC with MAC '{pnic_mac_address}' excluded from sync. Skipping")
continue
pnic_data = {
"name": unquote(pnic_name),
"device": None, # will be set once we found the correct device
"mac_address": normalize_mac_address(grab(pnic, "mac")),
"mac_address": pnic_mac_address,
"enabled": bool(grab(pnic, "linkSpeed")),
"description": unquote(pnic_description),
"type": NetBoxInterfaceType(pnic_link_speed).get_this_netbox_type()

View File

@@ -350,6 +350,10 @@ password = super-secret
; setting this option to 'False'
;sync_vm_interface_mtu = True
; defines a comma separated list of MAC addresses which should be excluded from sync. Any
; host NIC with a matching MAC address will be excluded from sync.
;host_nic_exclude_by_mac_list = AA:BB:CC:11:22:33, 66:77:88:AA:BB:CC
[source/my-redfish-example]
; Defines if this source is enabled or not