Added device type interface startup script and sample YAML initializer
Renumber startup scripts to place platform initialization before the devices to enable platform specification during device creation
This commit is contained in:
parent
61a3afbb3b
commit
036d3f881e
23 changed files with 45 additions and 0 deletions
18
initializers/device_type_interfaces.yml
Normal file
18
initializers/device_type_interfaces.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
# - device_type: Other
|
||||
# name: GigabitEthernet1
|
||||
# type: 10gbase-t
|
||||
# mgmt_only: true
|
||||
# description: Management interface
|
||||
#
|
||||
# - device_type: Other
|
||||
# name: GigabitEthernet2
|
||||
# type: 10gbase-t
|
||||
# mgmt_only: false
|
||||
# description: Data interface
|
||||
#
|
||||
# - device_type: Other
|
||||
# name: GigabitEthernet3
|
||||
# type: 1000base-t
|
||||
# description: GigE data interface
|
||||
---
|
||||
|
27
startup_scripts/210_device_type_interfaces.py
Normal file
27
startup_scripts/210_device_type_interfaces.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import DeviceType, InterfaceTemplate
|
||||
from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values
|
||||
|
||||
interfaces = load_yaml("/opt/netbox/initializers/device_type_interfaces.yml")
|
||||
|
||||
if interfaces is None:
|
||||
sys.exit()
|
||||
|
||||
required_assocs = {"device_type": (DeviceType, "model")}
|
||||
|
||||
for params in interfaces:
|
||||
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)
|
||||
|
||||
interface, created = InterfaceTemplate.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
set_custom_fields_values(interface, custom_field_data)
|
||||
|
||||
print("🧷 Created interface template", interface.device_type, interface.name)
|
Loading…
Add table
Add a link
Reference in a new issue