14
14
from module .config .option import ConfigOption
15
15
from module .sources .common .conifg import *
16
16
from module .common .logging import get_logger
17
+ from module .common .misc import quoted_split
17
18
from module .sources .common .permitted_subnets import PermittedSubnets
18
19
19
20
log = get_logger ()
@@ -71,7 +72,21 @@ def __init__(self):
71
72
bool ,
72
73
description = """define if existing interface attributes are overwritten with data discovered
73
74
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
+ ),
75
90
]
76
91
77
92
super ().__init__ ()
@@ -93,6 +108,18 @@ def validate_options(self):
93
108
log .error (f"Inventory file path '{ option .value } ' not readable." )
94
109
self .set_validation_failed ()
95
110
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
+
96
123
permitted_subnets_option = self .get_option_by_name ("permitted_subnets" )
97
124
98
125
if permitted_subnets_option is not None :
0 commit comments