Add Plaform seeds

This commit is contained in:
Aleksandar Radunovic 2018-10-30 14:22:04 +01:00
parent a10cd805ae
commit aa68548f41
4 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,19 @@
# # Allowed rpc clients are: juniper-junos, cisco-ios, opengear
# - name: Platform 1
# slug: platform-1
# manufacturer: Manufacturer 1
# napalm_driver: driver1
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
# rpc_client: juniper-junos
# - name: Platform 2
# slug: platform-2
# manufacturer: Manufacturer 2
# napalm_driver: driver2
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
# rpc_client: opengear
# - name: Platform 3
# slug: platform-3
# manufacturer: NoName
# napalm_driver: driver3
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
# rpc_client: juniper-junos

View File

@ -11,4 +11,3 @@ with open('/opt/netbox/initializers/manufacturers.yml', 'r') as stream:
if created:
print("🏭 Created Manufacturer", manufacturer.name)

View File

@ -0,0 +1,25 @@
from dcim.models import Manufacturer, Platform
from ruamel.yaml import YAML
with open('/opt/netbox/initializers/platforms.yml', '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)