circuits model startup_scripts
This commit is contained in:
parent
4e8588accf
commit
6ab38472be
6
initializers/circuit_types.yml
Normal file
6
initializers/circuit_types.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# - name: VPLS
|
||||
# slug: vpls
|
||||
# - name: MPLS
|
||||
# slug: mpls
|
||||
# - name: Internet
|
||||
# slug: internet
|
6
initializers/circuits.yml
Normal file
6
initializers/circuits.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# - cid: Circuit_ID-1
|
||||
# provider: Provider1
|
||||
# type: Internet
|
||||
# - name: Circuit_ID-2
|
||||
# provider: Provider2
|
||||
# type: MPLS
|
6
initializers/providers.yml
Normal file
6
initializers/providers.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# - name: Provider1
|
||||
# slug: provider1
|
||||
# asn: 121
|
||||
# - name: Provider2
|
||||
# slug: provider2
|
||||
# asn: 122
|
18
startup_scripts/280_providers.py
Normal file
18
startup_scripts/280_providers.py
Normal 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)
|
18
startup_scripts/290_circuit_types.py
Normal file
18
startup_scripts/290_circuit_types.py
Normal 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)
|
29
startup_scripts/300_circuits.py
Normal file
29
startup_scripts/300_circuits.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user