From 5399f8c890dd0f2566d29b0f9617a229af0eaef2 Mon Sep 17 00:00:00 2001 From: Schylar Utley Date: Fri, 18 Dec 2020 15:06:08 -0600 Subject: [PATCH] Update 270_primary_ips.py fix issue where user has no virtual machines defined, but startup script still tries to iterate over empty file. --- startup_scripts/270_primary_ips.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/startup_scripts/270_primary_ips.py b/startup_scripts/270_primary_ips.py index 74acece..b5a3d84 100644 --- a/startup_scripts/270_primary_ips.py +++ b/startup_scripts/270_primary_ips.py @@ -31,13 +31,14 @@ def link_primary_ip(assets, asset_model): devices = load_yaml('/opt/netbox/initializers/devices.yml') virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml') -if devices is None and virtual_machines is None: - sys.exit() - optional_assocs = { 'primary_ip4': (IPAddress, 'address'), 'primary_ip6': (IPAddress, 'address') } -link_primary_ip(devices, Device) -link_primary_ip(virtual_machines, VirtualMachine) +if devices is None and virtual_machines is None: + sys.exit() +elif devices is not None: + link_primary_ip(devices, Device) +elif virtual_machines is not None: + link_primary_ip(virtual_machines, VirtualMachine)