Skip to content

Commit 94509f8

Browse files
committed
added route_targets startup_script
1 parent 818266a commit 94509f8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

initializers/route_targets.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# - name: 65000:1001
2+
# tenant: tenant1
3+
# - name: 65000:1002

startup_scripts/175_route_targets.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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)

0 commit comments

Comments
 (0)