From 160977afe7c74a4c80a405cd29e61f60146e8dcb Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Mon, 11 Apr 2022 13:08:35 +0100 Subject: [PATCH 1/4] better catching of error --- netbox_gateways/template_content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_gateways/template_content.py b/netbox_gateways/template_content.py index 340b195..66726b0 100644 --- a/netbox_gateways/template_content.py +++ b/netbox_gateways/template_content.py @@ -32,7 +32,7 @@ def x_page(self): if not gateways_obj: try: gateways_obj = Gateway.objects.get(prefix=prefix) - except: + except Gateway.DoesNotExist: gateways_obj = None return self.render( From 23ab6e3076cf278093d25db10a3ac2854a54f4a7 Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Mon, 11 Apr 2022 13:10:58 +0100 Subject: [PATCH 2/4] version bump --- netbox_gateways/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox_gateways/__init__.py b/netbox_gateways/__init__.py index 620cd11..30e18ee 100644 --- a/netbox_gateways/__init__.py +++ b/netbox_gateways/__init__.py @@ -5,7 +5,7 @@ class NetBoxGatewayConfig(PluginConfig): name = "netbox_gateways" verbose_name = " Netbox Gateway" description = "Manage simple prefix default gateways" - version = "0.3" + version = "0.4" base_url = "nb_gateways" diff --git a/setup.py b/setup.py index c365493..ae2ec66 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="netbox-gateways", - version="0.3", + version="0.4", description="Manage simple prefix default gateways", install_requires=[], packages=find_packages(), From 8e69e0cbc813ddd65755a37f8dfb2c5342bcb911 Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Tue, 12 Apr 2022 20:44:56 +0100 Subject: [PATCH 3/4] found a value error bug. make sure it doesnt happen in future --- netbox_gateways/template_content.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/netbox_gateways/template_content.py b/netbox_gateways/template_content.py index 66726b0..9bc9691 100644 --- a/netbox_gateways/template_content.py +++ b/netbox_gateways/template_content.py @@ -23,17 +23,26 @@ def x_page(self): prefix__net_contains_or_equals=str(obj.address.ip), status="active", # Only search for "active" prefixes ).prefetch_related("site", "role") - prefix = related_prefixs[ - len(related_prefixs) - 1 - ] # get last prefix in the recordset above + if len(related_prefixs) > 1: + try: + prefix = related_prefixs[ + len(related_prefixs) - 1 + ] # get last prefix in the recordset above + except Prefix.ValueError: + prefix = None + else: + prefix = None else: prefix = gateways_obj.prefix - if not gateways_obj: - try: - gateways_obj = Gateway.objects.get(prefix=prefix) - except Gateway.DoesNotExist: - gateways_obj = None + if not prefix: + gateways_obj = None + else: + if not gateways_obj: + try: + gateways_obj = Gateway.objects.get(prefix=prefix) + except Gateway.DoesNotExist: + gateways_obj = None return self.render( "netbox_gateways/ip_card.html", From a758117d818e27777fe7789b880c71ceaee0eb9e Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Tue, 12 Apr 2022 20:49:32 +0100 Subject: [PATCH 4/4] fixes --- netbox_gateways/__init__.py | 2 +- netbox_gateways/template_content.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_gateways/__init__.py b/netbox_gateways/__init__.py index 30e18ee..cf431ff 100644 --- a/netbox_gateways/__init__.py +++ b/netbox_gateways/__init__.py @@ -5,7 +5,7 @@ class NetBoxGatewayConfig(PluginConfig): name = "netbox_gateways" verbose_name = " Netbox Gateway" description = "Manage simple prefix default gateways" - version = "0.4" + version = "0.4.1" base_url = "nb_gateways" diff --git a/netbox_gateways/template_content.py b/netbox_gateways/template_content.py index 9bc9691..df05e25 100644 --- a/netbox_gateways/template_content.py +++ b/netbox_gateways/template_content.py @@ -23,7 +23,7 @@ def x_page(self): prefix__net_contains_or_equals=str(obj.address.ip), status="active", # Only search for "active" prefixes ).prefetch_related("site", "role") - if len(related_prefixs) > 1: + if len(related_prefixs) >= 1: try: prefix = related_prefixs[ len(related_prefixs) - 1 diff --git a/setup.py b/setup.py index ae2ec66..d58f76b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="netbox-gateways", - version="0.4", + version="0.4.1", description="Manage simple prefix default gateways", install_requires=[], packages=find_packages(),