mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-11-24 08:54:05 +01:00
e46a7d2f7f
Previously, the startup_scripts would fail if an initializer file was not present. Now they just ignore missing files.
33 lines
780 B
Python
33 lines
780 B
Python
from dcim.models import Manufacturer, Platform
|
|
from ruamel.yaml import YAML
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
file = Path('/opt/netbox/initializers/platforms.yml')
|
|
if not file.is_file():
|
|
sys.exit()
|
|
|
|
with file.open('r') as stream:
|
|
yaml = YAML(typ='safe')
|
|
platforms = yaml.load(stream)
|
|
|
|
optional_assocs = {
|
|
'manufacturer': (Manufacturer, 'name'),
|
|
}
|
|
|
|
if platforms is not None:
|
|
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)
|