Skip to content

Commit f4f0959

Browse files
committed
enable settings ip_tenant_inheritance_order with import_inventory
1 parent 14408ed commit f4f0959

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

module/sources/check_redfish/config.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from module.config.option import ConfigOption
1515
from module.sources.common.conifg import *
1616
from module.common.logging import get_logger
17+
from module.common.misc import quoted_split
1718
from module.sources.common.permitted_subnets import PermittedSubnets
1819

1920
log = get_logger()
@@ -71,7 +72,21 @@ def __init__(self):
7172
bool,
7273
description="""define if existing interface attributes are overwritten with data discovered
7374
via check_redfish if False only data which is not preset in NetBox will be added""",
74-
default_value=True)
75+
default_value=True),
76+
77+
ConfigOption("ip_tenant_inheritance_order",
78+
str,
79+
description="""\
80+
define in which order the IP address tenant will be assigned if tenant is undefined.
81+
possible values:
82+
* device : host or VM tenant will be assigned to the IP address
83+
* prefix : if the IP address belongs to an existing prefix and this prefix has a tenant assigned, then this one is used
84+
* disabled : no tenant assignment to the IP address will be performed
85+
the order of the definition is important, the default is "device, prefix" which means:
86+
If the device has a tenant then this one will be used. If not, the prefix tenant will be used if defined
87+
""",
88+
default_value="device, prefix"
89+
),
7590
]
7691

7792
super().__init__()
@@ -93,6 +108,18 @@ def validate_options(self):
93108
log.error(f"Inventory file path '{option.value}' not readable.")
94109
self.set_validation_failed()
95110

111+
if option.key == "ip_tenant_inheritance_order":
112+
option.set_value(quoted_split(option.value))
113+
for ip_tenant_inheritance in option.value:
114+
if ip_tenant_inheritance not in ["device", "prefix", "disabled"]:
115+
log.error(f"Config value '{ip_tenant_inheritance}' invalid for "
116+
f"config option 'ip_tenant_inheritance_order'!")
117+
self.set_validation_failed()
118+
119+
if len(option.value) > 2:
120+
log.error("Config option 'ip_tenant_inheritance_order' can contain only 2 items max")
121+
self.set_validation_failed()
122+
96123
permitted_subnets_option = self.get_option_by_name("permitted_subnets")
97124

98125
if permitted_subnets_option is not None:

module/sources/common/source_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ def add_update_interface(self, interface_object, device_object, interface_data,
271271
disable_vlan_sync = self.disable_vlan_sync
272272

273273
ip_tenant_inheritance_order = None
274-
if hasattr(self, "ip_tenant_inheritance_order"):
275-
ip_tenant_inheritance_order = self.ip_tenant_inheritance_order
274+
if hasattr(self.settings, "ip_tenant_inheritance_order"):
275+
ip_tenant_inheritance_order = self.settings.ip_tenant_inheritance_order
276276

277277
if not isinstance(interface_data, dict):
278278
log.error(f"Attribute 'interface_data' must be a dict() got {type(interface_data)}.")

settings-example.ini

+9
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,13 @@ inventory_file_path = /full/path/to/inventory/files
376376
; check_redfish if False only data which is not preset in NetBox will be added
377377
;overwrite_interface_attributes = True
378378

379+
; define in which order the IP address tenant will be assigned if tenant is undefined.
380+
; possible values:
381+
; * device : host or VM tenant will be assigned to the IP address
382+
; * prefix : if the IP address belongs to an existing prefix and this prefix has a tenant assigned, then this one is used
383+
; * disabled : no tenant assignment to the IP address will be performed
384+
; the order of the definition is important, the default is "device, prefix" which means:
385+
; If the device has a tenant then this one will be used. If not, the prefix tenant will be used if defined
386+
;ip_tenant_inheritance_order = device, prefix
387+
379388
;EOF

0 commit comments

Comments
 (0)