File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ # - name: 65000:1001
2
+ # tenant: tenant1
3
+ # - name: 65000:1002
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ from ipam .models import RouteTarget
4
+ from startup_script_utils import *
5
+ from tenancy .models import Tenant
6
+
7
+ route_targets = load_yaml ('/opt/netbox/initializers/route_targets.yml' )
8
+
9
+ if route_targets is None :
10
+ sys .exit ()
11
+
12
+ optional_assocs = {
13
+ 'tenant' : (Tenant , 'name' )
14
+ }
15
+
16
+ for params in route_targets :
17
+ custom_field_data = pop_custom_fields (params )
18
+
19
+ for assoc , details in optional_assocs .items ():
20
+ if assoc in params :
21
+ model , field = details
22
+ query = { field : params .pop (assoc ) }
23
+
24
+ params [assoc ] = model .objects .get (** query )
25
+
26
+ route_target , created = RouteTarget .objects .get_or_create (** params )
27
+
28
+ if created :
29
+ set_custom_fields_values (route_target , custom_field_data )
30
+
31
+ print ("🎯 Created Route Target" , route_target .name )
You can’t perform that action at this time.
0 commit comments