optional assoc to cluster & circuit startup_script
This commit is contained in:
parent
cbaaffc589
commit
8d8c58df54
@ -1,6 +1,7 @@
|
|||||||
# - cid: Circuit_ID-1
|
# - cid: Circuit_ID-1
|
||||||
# provider: Provider1
|
# provider: Provider1
|
||||||
# type: Internet
|
# type: Internet
|
||||||
|
# tenant: tenant1
|
||||||
# - cid: Circuit_ID-2
|
# - cid: Circuit_ID-2
|
||||||
# provider: Provider2
|
# provider: Provider2
|
||||||
# type: MPLS
|
# type: MPLS
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# - name: cluster1
|
# - name: cluster1
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
# group: Group 1
|
# group: Group 1
|
||||||
|
# tenant: tenant1
|
||||||
# - name: cluster2
|
# - name: cluster2
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
# site: SING 1
|
# site: SING 1
|
||||||
|
@ -3,6 +3,7 @@ import sys
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from startup_script_utils import *
|
from startup_script_utils import *
|
||||||
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
||||||
|
|
||||||
@ -15,7 +16,8 @@ required_assocs = {
|
|||||||
|
|
||||||
optional_assocs = {
|
optional_assocs = {
|
||||||
'site': (Site, 'name'),
|
'site': (Site, 'name'),
|
||||||
'group': (ClusterGroup, 'name')
|
'group': (ClusterGroup, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
for params in clusters:
|
for params in clusters:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from circuits.models import Circuit, Provider, CircuitType
|
from circuits.models import Circuit, Provider, CircuitType
|
||||||
|
from tenancy.models import Tenant
|
||||||
from startup_script_utils import *
|
from startup_script_utils import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -12,6 +13,10 @@ required_assocs = {
|
|||||||
'type': (CircuitType, 'name')
|
'type': (CircuitType, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
for params in circuits:
|
for params in circuits:
|
||||||
custom_field_data = pop_custom_fields(params)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
@ -21,6 +26,13 @@ for params in circuits:
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
circuit, created = Circuit.objects.get_or_create(**params)
|
circuit, created = Circuit.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
Loading…
Reference in New Issue
Block a user