Added device type interface startup script and sample YAML initializer
Renumber startup scripts to place platform initialization before the devices to enable platform specification during device creation
This commit is contained in:
parent
61a3afbb3b
commit
036d3f881e
23 changed files with 45 additions and 0 deletions
27
startup_scripts/180_platforms.py
Normal file
27
startup_scripts/180_platforms.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import sys
|
||||
|
||||
from dcim.models import Manufacturer, Platform
|
||||
from startup_script_utils import load_yaml
|
||||
|
||||
platforms = load_yaml("/opt/netbox/initializers/platforms.yml")
|
||||
|
||||
if platforms is None:
|
||||
sys.exit()
|
||||
|
||||
optional_assocs = {
|
||||
"manufacturer": (Manufacturer, "name"),
|
||||
}
|
||||
|
||||
for params in platforms:
|
||||
|
||||
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)
|
||||
|
||||
platform, created = Platform.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("💾 Created platform", platform.name)
|
Loading…
Add table
Add a link
Reference in a new issue