mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-12-02 04:43:33 +01:00
8860d32f97
* Cleanup & Reorg startup scripts
24 lines
587 B
Python
24 lines
587 B
Python
import sys
|
|
|
|
from dcim.models import Location, Site
|
|
from startup_script_utils import load_yaml
|
|
|
|
rack_groups = load_yaml("/opt/netbox/initializers/locations.yml")
|
|
|
|
if rack_groups is None:
|
|
sys.exit()
|
|
|
|
required_assocs = {"site": (Site, "name")}
|
|
|
|
for params in rack_groups:
|
|
|
|
for assoc, details in required_assocs.items():
|
|
model, field = details
|
|
query = {field: params.pop(assoc)}
|
|
params[assoc] = model.objects.get(**query)
|
|
|
|
location, created = Location.objects.get_or_create(**params)
|
|
|
|
if created:
|
|
print("🎨 Created location", location.name)
|