Add site seeds
This commit is contained in:
parent
819f325bd5
commit
791027f77b
2 changed files with 44 additions and 0 deletions
startup_scripts
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…
Add table
Add a link
Reference in a new issue