Add site seeds
This commit is contained in:
parent
819f325bd5
commit
791027f77b
24
initializers/sites.yml
Normal file
24
initializers/sites.yml
Normal file
@ -0,0 +1,24 @@
|
||||
# - name: AMS 1
|
||||
# slug: ams1
|
||||
# region: Downtown
|
||||
# status: 1
|
||||
# facility: Amsterdam 1
|
||||
# asn: 12345
|
||||
# - name: AMS 2
|
||||
# slug: ams2
|
||||
# region: Downtown
|
||||
# status: 1
|
||||
# facility: Amsterdam 2
|
||||
# asn: 54321
|
||||
# - name: AMS 3
|
||||
# slug: ams3
|
||||
# region: Suburbs
|
||||
# status: 1
|
||||
# facility: Amsterdam 3
|
||||
# asn: 67890
|
||||
# - name: SING 1
|
||||
# slug: sing1
|
||||
# region: Singapore
|
||||
# status: 1
|
||||
# facility: Singapore 1
|
||||
# asn: 09876
|
20
startup_scripts/41_sites.py
Normal file
20
startup_scripts/41_sites.py
Normal file
@ -0,0 +1,20 @@
|
||||
from dcim.models import Site
|
||||
from dcim.models import Region
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
with open('/opt/netbox/initializers/sites.yml', 'r') as stream:
|
||||
yaml = YAML(typ='safe')
|
||||
sites = yaml.load(stream)
|
||||
|
||||
if sites is not None:
|
||||
for site_params in sites:
|
||||
if "region" in site_params:
|
||||
region = Region.objects.get(name=site_params.pop('region', None))
|
||||
site_params['region'] = region
|
||||
|
||||
|
||||
site, created = Site.objects.get_or_create(**site_params)
|
||||
|
||||
if created:
|
||||
print("Created site", site.name)
|
||||
|
Loading…
Reference in New Issue
Block a user