mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-11-23 00:13:11 +01:00
Add Plaform seeds
This commit is contained in:
parent
a10cd805ae
commit
aa68548f41
19
initializers/platforms.yml
Normal file
19
initializers/platforms.yml
Normal 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
|
@ -11,4 +11,3 @@ with open('/opt/netbox/initializers/manufacturers.yml', 'r') as stream:
|
||||
|
||||
if created:
|
||||
print("🏭 Created Manufacturer", manufacturer.name)
|
||||
|
||||
|
25
startup_scripts/100_platforms.py
Normal file
25
startup_scripts/100_platforms.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user