Increase order prefix to 3 digits
This commit is contained in:
parent
7e6edd1bf5
commit
97477556e0
11 changed files with 18 additions and 16 deletions
25
startup_scripts/030_regions.py
Normal file
25
startup_scripts/030_regions.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
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)
|
||||
|
||||
optional_assocs = {
|
||||
'parent': (Region, 'name')
|
||||
}
|
||||
|
||||
if regions is not None:
|
||||
for params in regions:
|
||||
|
||||
for assoc, details in optional_assocs.items():
|
||||
if assoc in params:
|
||||
model, field = details
|
||||
query = { field: params.pop(assoc) }
|
||||
|
||||
params[assoc] = model.objects.get(**query)
|
||||
|
||||
region, created = Region.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("Created region", region.name)
|
Loading…
Add table
Add a link
Reference in a new issue