mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 12:22:23 -06:00
37 lines
983 B
Python
37 lines
983 B
Python
from dcim.models import Interface, Device, DeviceRole
|
|
from dcim.constants import IFACE_TYPE_KEYSTONE
|
|
|
|
from ruamel.yaml import YAML
|
|
from pathlib import Path
|
|
|
|
import sys
|
|
|
|
|
|
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)
|
|
|
|
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:
|
|
i = 1
|
|
while i < 24:
|
|
strand0 = i
|
|
strand1 = i + 1
|
|
name = '{}-{}'.format(strand0, strand1)
|
|
|
|
i += 2
|
|
|
|
interface, created = Interface.objects.get_or_create(name=name, device=locker, type=IFACE_TYPE_KEYSTONE)
|
|
if created:
|
|
print("🔗 Created interface {} for {}".format(interface.name, locker.name))
|