add tenant to aggregate startup_script
This commit is contained in:
parent
90018fc6d7
commit
0f1cc9eea0
|
@ -3,6 +3,7 @@ import sys
|
||||||
from ipam.models import Aggregate, RIR
|
from ipam.models import Aggregate, RIR
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
from startup_script_utils import *
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
||||||
|
|
||||||
|
@ -13,6 +14,10 @@ required_assocs = {
|
||||||
'rir': (RIR, 'name')
|
'rir': (RIR, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name'),
|
||||||
|
}
|
||||||
|
|
||||||
for params in aggregates:
|
for params in aggregates:
|
||||||
custom_field_data = pop_custom_fields(params)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
@ -24,6 +29,13 @@ for params in aggregates:
|
||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
aggregate, created = Aggregate.objects.get_or_create(**params)
|
aggregate, created = Aggregate.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
|
Loading…
Reference in New Issue