Add site seeds

This commit is contained in:
Aleksandar Radunovic 2018-10-15 15:13:51 +02:00
parent 819f325bd5
commit 791027f77b
2 changed files with 44 additions and 0 deletions

24
initializers/sites.yml Normal file
View 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

View 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)