Rack groups have been renamed to locations
This commit is contained in:
parent
9ab202f921
commit
5944086435
6 changed files with 10 additions and 10 deletions
23
startup_scripts/075_locations.py
Normal file
23
startup_scripts/075_locations.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue