circuits model startup_scripts

This commit is contained in:
ryanmerolle 2020-12-29 16:24:16 -05:00
parent 4e8588accf
commit 6ab38472be
6 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,6 @@
# - name: VPLS
# slug: vpls
# - name: MPLS
# slug: mpls
# - name: Internet
# slug: internet

View File

@ -0,0 +1,6 @@
# - cid: Circuit_ID-1
# provider: Provider1
# type: Internet
# - name: Circuit_ID-2
# provider: Provider2
# type: MPLS

View File

@ -0,0 +1,6 @@
# - name: Provider1
# slug: provider1
# asn: 121
# - name: Provider2
# slug: provider2
# asn: 122

View File

@ -0,0 +1,18 @@
from circuits.models import Provider
from startup_script_utils import *
import sys
providers = load_yaml('/opt/netbox/initializers/providers.yml')
if providers is None:
sys.exit()
for params in providers:
custom_field_data = pop_custom_fields(params)
provider, created = Provider.objects.get_or_create(**params)
if created:
set_custom_fields_values(name, custom_field_data)
print("📡 Created provider", provider.name)

View File

@ -0,0 +1,18 @@
from circuits.models import CircuitType
from startup_script_utils import *
import sys
circuit_types = load_yaml('/opt/netbox/initializers/circuit_types.yml')
if circuit_types is None:
sys.exit()
for params in circuit_types:
custom_field_data = pop_custom_fields(params)
circuit_type, created = CircuitType.objects.get_or_create(**params)
if created:
set_custom_fields_values(name, custom_field_data)
print("⚡ Created Circuit Type", circuit_type.name)

View File

@ -0,0 +1,29 @@
from circuits.models import Circuit, Provider, CircuitType
from startup_script_utils import *
import sys
circuits = load_yaml('/opt/netbox/initializers/circuits.yml')
if circuits is None:
sys.exit()
required_assocs = {
'provider': (Provider, 'name'),
'circuit_type': (CircuitType, 'name')
}
for params in circuits:
custom_field_data = pop_custom_fields(params)
for assoc, details in required_assocs.items():
model, field = details
query = { field: params.pop(assoc) }
params[assoc] = model.objects.get(**query)
circuit, created = Circuit.objects.get_or_create(**params)
if created:
set_custom_fields_values(cid, custom_field_data)
print("⚡ Created Circuit", circuit.cid)