File tree 3 files changed +40
-4
lines changed
3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change
1
+ # - asn: 1
2
+ # rir: RFC1918
3
+ # tenant: tenant1
4
+ # - asn: 2
5
+ # rir: RFC4193 ULA
6
+ # - asn: 3
7
+ # rir: RFC3849
Original file line number Diff line number Diff line change 3
3
# region: Downtown
4
4
# status: active
5
5
# facility: Amsterdam 1
6
- # asn: 12345
7
6
# custom_field_data:
8
7
# text_field: Description for AMS1
9
8
# - name: AMS 2
10
9
# slug: ams2
11
10
# region: Downtown
12
11
# status: active
13
12
# facility: Amsterdam 2
14
- # asn: 54321
15
13
# custom_field_data:
16
14
# text_field: Description for AMS2
17
15
# - name: AMS 3
18
16
# slug: ams3
19
17
# region: Suburbs
20
18
# status: active
21
19
# facility: Amsterdam 3
22
- # asn: 67890
23
20
# tenant: tenant1
24
21
# custom_field_data:
25
22
# text_field: Description for AMS3
28
25
# region: Singapore
29
26
# status: active
30
27
# facility: Singapore 1
31
- # asn: 09876
32
28
# tenant: tenant2
33
29
# custom_field_data:
34
30
# text_field: Description for SING1
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ from ipam .models import ASN , RIR
4
+ from startup_script_utils import load_yaml
5
+ from tenancy .models import Tenant
6
+
7
+ asns = load_yaml ("/opt/netbox/initializers/asns.yml" )
8
+
9
+ if asns is None :
10
+ sys .exit ()
11
+
12
+ required_assocs = {"rir" : (RIR , "name" )}
13
+
14
+ optional_assocs = {"tenant" : (Tenant , "name" )}
15
+
16
+ for params in asns :
17
+ for assoc , details in required_assocs .items ():
18
+ model , field = details
19
+ query = {field : params .pop (assoc )}
20
+
21
+ params [assoc ] = model .objects .get (** query )
22
+
23
+ for assoc , details in optional_assocs .items ():
24
+ if assoc in params :
25
+ model , field = details
26
+ query = {field : params .pop (assoc )}
27
+
28
+ params [assoc ] = model .objects .get (** query )
29
+
30
+ asn , created = ASN .objects .get_or_create (** params )
31
+
32
+ if created :
33
+ print (f"🔡 Created ASN { asn .asn } " )
You can’t perform that action at this time.
0 commit comments