mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-11-30 03:43:22 +01:00
50ade7bce1
This commit starts to remove some code redundancy from the startup scripts for easier maintenance.
27 lines
573 B
Python
27 lines
573 B
Python
from dcim.models import Region
|
|
from startup_script_utils import load_yaml
|
|
import sys
|
|
|
|
regions = load_yaml('/opt/netbox/initializers/regions.yml')
|
|
|
|
if regions is None:
|
|
sys.exit()
|
|
|
|
optional_assocs = {
|
|
'parent': (Region, 'name')
|
|
}
|
|
|
|
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)
|