mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 19:08:38 -06:00
Allow for creation of interfaces and tenants in startup / initializers
This commit is contained in:
parent
fff05b3154
commit
64de66e2d5
1
docker/initializers/interfaces.yml
Normal file
1
docker/initializers/interfaces.yml
Normal file
@ -0,0 +1 @@
|
||||
device_role: 'customer-network-locker'
|
11
docker/initializers/tenants.yml
Normal file
11
docker/initializers/tenants.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- slug: e9622cff-0286-4e98-9662-01f91ab907ff
|
||||
name: vaportest
|
||||
|
||||
- slug: 5ec5a570-4b7e-4151-b9df-2d6f9379776c
|
||||
name: VaporProvider
|
||||
|
||||
- slug: c26a3f7c-a854-4d4f-93cc-4fb4d6e34c08
|
||||
name: Test Org1
|
||||
|
||||
- slug: 3cd715b1-42a5-4c6f-ba4d-2fb20f6f06c4
|
||||
name: Test Org2
|
20
docker/startup_scripts/001_tenants.py
Normal file
20
docker/startup_scripts/001_tenants.py
Normal file
@ -0,0 +1,20 @@
|
||||
from tenancy.models import Tenant
|
||||
from ruamel.yaml import YAML
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
file = Path('/opt/netbox/initializers/tenants.yml')
|
||||
if not file.is_file():
|
||||
sys.exit()
|
||||
|
||||
with file.open('r') as stream:
|
||||
yaml = YAML(typ='safe')
|
||||
tenants = yaml.load(stream)
|
||||
|
||||
if tenants is not None:
|
||||
for params in tenants:
|
||||
|
||||
tenant, created = Tenant.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("🏠 Created tenant", tenant.name)
|
36
docker/startup_scripts/120_interfaces.py
Normal file
36
docker/startup_scripts/120_interfaces.py
Normal file
@ -0,0 +1,36 @@
|
||||
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, locler.name))
|
Loading…
Reference in New Issue
Block a user