File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 3
3
from ipam .models import Aggregate , RIR
4
4
from netaddr import IPNetwork
5
5
from startup_script_utils import *
6
+ from tenancy .models import Tenant
6
7
7
8
aggregates = load_yaml ('/opt/netbox/initializers/aggregates.yml' )
8
9
13
14
'rir' : (RIR , 'name' )
14
15
}
15
16
17
+ optional_assocs = {
18
+ 'tenant' : (Tenant , 'name' ),
19
+ }
20
+
16
21
for params in aggregates :
17
22
custom_field_data = pop_custom_fields (params )
18
23
24
29
25
30
params [assoc ] = model .objects .get (** query )
26
31
32
+ for assoc , details in optional_assocs .items ():
33
+ if assoc in params :
34
+ model , field = details
35
+ query = { field : params .pop (assoc ) }
36
+
37
+ params [assoc ] = model .objects .get (** query )
38
+
27
39
aggregate , created = Aggregate .objects .get_or_create (** params )
28
40
29
41
if created :
You can’t perform that action at this time.
0 commit comments