2021-02-08 11:59:33 +01:00
|
|
|
import sys
|
|
|
|
|
2018-10-30 14:22:04 +01:00
|
|
|
from dcim.models import Manufacturer, Platform
|
2020-02-05 15:31:01 +01:00
|
|
|
from startup_script_utils import load_yaml
|
2018-12-19 14:25:58 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
platforms = load_yaml("/opt/netbox/initializers/platforms.yml")
|
2018-12-19 14:25:58 +01:00
|
|
|
|
2020-02-05 15:31:01 +01:00
|
|
|
if platforms is None:
|
2021-02-08 11:59:33 +01:00
|
|
|
sys.exit()
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2020-02-05 15:31:01 +01:00
|
|
|
optional_assocs = {
|
2021-02-08 11:59:33 +01:00
|
|
|
"manufacturer": (Manufacturer, "name"),
|
2020-02-05 15:31:01 +01:00
|
|
|
}
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2020-02-05 15:31:01 +01:00
|
|
|
for params in platforms:
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
for assoc, details in optional_assocs.items():
|
|
|
|
if assoc in params:
|
|
|
|
model, field = details
|
|
|
|
query = {field: params.pop(assoc)}
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
params[assoc] = model.objects.get(**query)
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
platform, created = Platform.objects.get_or_create(**params)
|
2018-10-30 14:22:04 +01:00
|
|
|
|
2021-02-08 11:59:33 +01:00
|
|
|
if created:
|
|
|
|
print("💾 Created platform", platform.name)
|