From 5399f8c890dd0f2566d29b0f9617a229af0eaef2 Mon Sep 17 00:00:00 2001 From: Schylar Utley Date: Fri, 18 Dec 2020 15:06:08 -0600 Subject: [PATCH 1/3] 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) From 584566b0f0df53d82c2441255373a067104ec616 Mon Sep 17 00:00:00 2001 From: Schylar Utley Date: Fri, 15 Jan 2021 23:44:10 -0600 Subject: [PATCH 2/3] allow simultaneous virtual machine and device primary ip initialization --- startup_scripts/270_primary_ips.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/startup_scripts/270_primary_ips.py b/startup_scripts/270_primary_ips.py index b5a3d84..33af3b7 100644 --- a/startup_scripts/270_primary_ips.py +++ b/startup_scripts/270_primary_ips.py @@ -42,3 +42,6 @@ elif devices is not None: link_primary_ip(devices, Device) elif virtual_machines is not None: link_primary_ip(virtual_machines, VirtualMachine) +else: + link_primary_ip(devices, Device) + link_primary_ip(virtual_machines, VirtualMachine) From 385c66e30ded889ce240b2d68e48cc80e9f9f821 Mon Sep 17 00:00:00 2001 From: Schylar Utley Date: Tue, 19 Jan 2021 12:54:52 -0600 Subject: [PATCH 3/3] Update startup_scripts/270_primary_ips.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ah, of course.. I would agree. :) Co-authored-by: Christian Mäder --- startup_scripts/270_primary_ips.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/startup_scripts/270_primary_ips.py b/startup_scripts/270_primary_ips.py index 33af3b7..7a7400e 100644 --- a/startup_scripts/270_primary_ips.py +++ b/startup_scripts/270_primary_ips.py @@ -38,10 +38,7 @@ optional_assocs = { 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) -else: +if devices is not None: link_primary_ip(devices, Device) +if virtual_machines is not None: link_primary_ip(virtual_machines, VirtualMachine)