mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-11-07 16:44:02 +01:00
added services startup_script
This commit is contained in:
parent
dfb0327340
commit
818266ace1
10
initializers/services.yml
Normal file
10
initializers/services.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# - name: SSH
|
||||
# protocol: TCP
|
||||
# ports:
|
||||
# - 22
|
||||
# virtual_machine: virtual machine 1
|
||||
# - name: FTP
|
||||
# protocol: TCP
|
||||
# ports:
|
||||
# - 21
|
||||
# device: server01
|
29
startup_scripts/320_services.py
Normal file
29
startup_scripts/320_services.py
Normal file
@ -0,0 +1,29 @@
|
||||
from ipam.models import Service
|
||||
from dcim.models import Device
|
||||
from virtualization.models import VirtualMachine
|
||||
from startup_script_utils import load_yaml
|
||||
import sys
|
||||
|
||||
services = load_yaml('/opt/netbox/initializers/services.yml')
|
||||
|
||||
if services is None:
|
||||
sys.exit()
|
||||
|
||||
optional_assocs = {
|
||||
'device': (Device, 'name'),
|
||||
'virtual_machine': (VirtualMachine, 'name')
|
||||
}
|
||||
|
||||
for params in services:
|
||||
|
||||
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)
|
||||
|
||||
service, created = Service.objects.get_or_create(**params)
|
||||
|
||||
if created:
|
||||
print("🧰 Created Service", service.name)
|
Loading…
Reference in New Issue
Block a user