Update 270_primary_ips.py

fix issue where user has no virtual machines defined, but startup script still tries to iterate over empty file.
This commit is contained in:
Schylar Utley 2020-12-18 15:06:08 -06:00 committed by Schylar Utley
parent aa4d630a0f
commit 5399f8c890

View File

@ -31,13 +31,14 @@ def link_primary_ip(assets, asset_model):
devices = load_yaml('/opt/netbox/initializers/devices.yml') devices = load_yaml('/opt/netbox/initializers/devices.yml')
virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml') virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml')
if devices is None and virtual_machines is None:
sys.exit()
optional_assocs = { optional_assocs = {
'primary_ip4': (IPAddress, 'address'), 'primary_ip4': (IPAddress, 'address'),
'primary_ip6': (IPAddress, 'address') 'primary_ip6': (IPAddress, 'address')
} }
link_primary_ip(devices, Device) if devices is None and virtual_machines is None:
link_primary_ip(virtual_machines, VirtualMachine) sys.exit()
elif devices is not None:
link_primary_ip(devices, Device)
elif virtual_machines is not None:
link_primary_ip(virtual_machines, VirtualMachine)