Add region seeds
This commit is contained in:
parent
f1ebd4d246
commit
819f325bd5
10
initializers/regions.yml
Normal file
10
initializers/regions.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# - name: Singapore
|
||||
# slug: singapore
|
||||
# - name: Amsterdam
|
||||
# slug: amsterdam
|
||||
# - name: Downtown
|
||||
# slug: downtown
|
||||
# parent: Amsterdam
|
||||
# - name: Suburbs
|
||||
# slug: suburbs
|
||||
# parent: Amsterdam
|
17
startup_scripts/40_regions.py
Normal file
17
startup_scripts/40_regions.py
Normal file
@ -0,0 +1,17 @@
|
||||
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)
|
Loading…
Reference in New Issue
Block a user