netbox-docker/startup_scripts/40_regions.py
Aleksandar Radunovic 819f325bd5 Add region seeds
2018-10-15 15:13:26 +02:00

18 lines
524 B
Python

from dcim.models import Region
from ruamel.yaml import YAML
with open('/opt/netbox/initializers/regions.yml', 'r') as stream:
yaml=YAML(typ='safe')
regions = yaml.load(stream)
if regions is not None:
for region_params in regions:
if "parent" in region_params:
parent = Region.objects.get(name=region_params.pop('parent'))
region_params['parent'] = parent
region, created = Region.objects.get_or_create(**region_params)
if created:
print("Created region", region.name)