mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-11-29 19:33:14 +01:00
93dee74459
Fixes #192 Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
32 lines
733 B
Python
32 lines
733 B
Python
from dcim.models import Site,RackGroup
|
|
from ruamel.yaml import YAML
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
file = Path('/opt/netbox/initializers/rack_groups.yml')
|
|
if not file.is_file():
|
|
sys.exit()
|
|
|
|
with file.open('r') as stream:
|
|
yaml=YAML(typ='safe')
|
|
rack_groups= yaml.load(stream)
|
|
|
|
required_assocs = {
|
|
'site': (Site, 'name')
|
|
}
|
|
|
|
if rack_groups is not None:
|
|
for params in rack_groups:
|
|
|
|
for assoc, details in required_assocs.items():
|
|
model, field = details
|
|
query = { field: params.pop(assoc) }
|
|
params[assoc] = model.objects.get(**query)
|
|
|
|
rack_group, created = RackGroup.objects.get_or_create(**params)
|
|
|
|
if created:
|
|
print("🎨 Created rack group", rack_group.name)
|
|
|