mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
✨ Allow for interface generation across multiple device types
This commit is contained in:
parent
bb7191e953
commit
8ff5258070
@ -1,3 +1,13 @@
|
||||
- device_role: Access Switch
|
||||
device_type: QFX5120-48Y-8C
|
||||
face: front
|
||||
name: EFR1.EMUL8R.000
|
||||
site: Local Emulator
|
||||
- device_role: Access Switch
|
||||
device_type: QFX5120-48Y-8C
|
||||
face: front
|
||||
name: EFR2.EMUL8R.000
|
||||
site: Local Emulator
|
||||
- custom_fields:
|
||||
sf_id: a6d8c2a0-b4cf-4940-a53f-e356354d78c9
|
||||
device_role: Customer Compute Locker
|
||||
|
@ -1 +1,6 @@
|
||||
device_role: 'customer-network-locker'
|
||||
- device_role: 'customer-network-locker'
|
||||
template: 'customer-locker'
|
||||
ports: 12
|
||||
- device_role: 'access-switch'
|
||||
template: 'efr'
|
||||
ports: 46
|
||||
|
@ -6,22 +6,10 @@ from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
file = Path('/opt/netbox/initializers/interfaces.yml')
|
||||
if not file.is_file():
|
||||
sys.exit()
|
||||
def template_customer_locker(devices, port_count):
|
||||
from dcim.models import Interface
|
||||
|
||||
with file.open('r') as stream:
|
||||
yaml = YAML(typ='safe')
|
||||
config = yaml.load(stream)
|
||||
|
||||
device_role = DeviceRole.objects.get(slug=config.get('device_role'))
|
||||
|
||||
if not device_role:
|
||||
sys.exit()
|
||||
|
||||
network_lockers = Device.objects.all().filter(device_role=device_role.id)
|
||||
|
||||
for locker in network_lockers:
|
||||
for locker in devices:
|
||||
i = 1
|
||||
while i < 24:
|
||||
strand0 = i
|
||||
@ -33,3 +21,47 @@ with file.open('r') as stream:
|
||||
interface, created = Interface.objects.get_or_create(name=name, device=locker, type='keystone')
|
||||
if created:
|
||||
print("🔗 Created interface {} for {}".format(interface.name, locker.name))
|
||||
|
||||
|
||||
def template_efr(devices, port_count):
|
||||
from dcim.models import Interface
|
||||
|
||||
for switch in devices:
|
||||
i = 1
|
||||
while i <= port_count:
|
||||
interface, created = Interface.objects.get_or_create(name=f'xe-0/0/{i}', device=switch, type='10gbase-x-sfpp')
|
||||
i += 1
|
||||
if created:
|
||||
print("🔗 Created interface {} for {}".format(interface.name, switch.name))
|
||||
|
||||
|
||||
templates = {
|
||||
'efr': template_efr,
|
||||
'customer-locker': template_customer_locker,
|
||||
}
|
||||
|
||||
file = Path('/opt/netbox/initializers/interfaces.yml')
|
||||
if not file.is_file():
|
||||
sys.exit()
|
||||
|
||||
with file.open('r') as stream:
|
||||
yaml = YAML(typ='safe')
|
||||
config = yaml.load(stream)
|
||||
|
||||
|
||||
for c in config:
|
||||
device_role = DeviceRole.objects.get(slug=c.get('device_role'))
|
||||
|
||||
if not device_role:
|
||||
continue
|
||||
|
||||
interface_template = c.get('template')
|
||||
|
||||
if not interface_template or interface_template not in templates:
|
||||
continue
|
||||
|
||||
port_count = c.get('ports', 0)
|
||||
|
||||
devices = Device.objects.all().filter(device_role=device_role.id)
|
||||
|
||||
templates[interface_template](devices, port_count)
|
||||
|
Loading…
Reference in New Issue
Block a user