From a61d2889d45f3084db59844167f416ff14a68ee2 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:05:29 -0500 Subject: [PATCH 1/9] netbox-community#10055 - Add loop for NAT Outside --- netbox/templates/dcim/device.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 8286f2c61..217362311 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -179,8 +179,8 @@ {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} (NAT for {{ object.primary_ip4.nat_inside.address.ip|linkify }}) - {% elif object.primary_ip4.nat_outside %} - (NAT: {{ object.primary_ip4.nat_outside.address.ip|linkify }}) + {% elif object.primary_ip4.nat_outside.count > 0 %} + (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} {{ ''|placeholder }} @@ -194,8 +194,8 @@ {{ object.primary_ip6.address.ip }} {% if object.primary_ip6.nat_inside %} (NAT for {{ object.primary_ip6.nat_inside.address.ip|linkify }}) - {% elif object.primary_ip6.nat_outside %} - (NAT: {{ object.primary_ip6.nat_outside.address.ip|linkify }}) + {% elif object.primary_ip6.nat_outside.count > 0 %} + (NAT for {% for nat in object.primary_ip6.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} {{ ''|placeholder }} From 7463b75fb4538d788ea308aa5cb35b8d81237ae6 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:09:36 -0500 Subject: [PATCH 2/9] netbox-community#10055 - Add loop for NAT Outside --- netbox/templates/virtualization/virtualmachine.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index f62da6fed..3826e0cf2 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -45,8 +45,8 @@ {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) - {% elif object.primary_ip4.nat_outside %} - (NAT: {{ object.primary_ip4.nat_outside.address.ip }}) + {% elif object.primary_ip4.nat_outside.count > 0 %} + (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} {{ ''|placeholder }} @@ -60,8 +60,8 @@ {{ object.primary_ip6.address.ip }} {% if object.primary_ip6.nat_inside %} (NAT for {{ object.primary_ip6.nat_inside.address.ip }}) - {% elif object.primary_ip6.nat_outside %} - (NAT: {{ object.primary_ip6.nat_outside.address.ip }}) + {% elif object.primary_ip4.nat_outside.count > 0 %} + (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} {{ ''|placeholder }} From fe500d1c441960b8f656e6db9287013fae81bf61 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:18:29 -0500 Subject: [PATCH 3/9] netbox-community#10055 - Add template for NAT Outside Fixes 'ipam.IPAddress.None' text --- netbox/ipam/tables/ip.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 20e63fe55..493488dac 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -56,6 +56,12 @@ VRF_LINK = """ {% endif %} """ +NAT_OUTSIDE_LINK = """ +{% if record.nat_outside.count > 0 %} + {% for nat in record.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %} +{% endif %} +""" + # # RIRs @@ -360,8 +366,8 @@ class IPAddressTable(TenancyColumnsMixin, NetBoxTable): orderable=False, verbose_name='NAT (Inside)' ) - nat_outside = tables.Column( - linkify=True, + nat_outside = tables.TemplateColumn( + template_code=NAT_OUTSIDE_LINK, orderable=False, verbose_name='NAT (Outside)' ) From 97099c376c29482ab750cd05c0ecb003b936036c Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:22:22 -0500 Subject: [PATCH 4/9] netbox-community#10055 - Align NAT Outside with NAT Inside --- netbox/templates/ipam/ipaddress.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netbox/templates/ipam/ipaddress.html b/netbox/templates/ipam/ipaddress.html index 8b628c2f7..ba0f0c5e6 100644 --- a/netbox/templates/ipam/ipaddress.html +++ b/netbox/templates/ipam/ipaddress.html @@ -91,10 +91,13 @@ - Outside NAT IPs + NAT (Outside) {% for ip in object.nat_outside.all %} - {{ ip|linkify }}
+ {{ ip|linkify }} + {% if ip.assigned_object %} + ({{ ip.assigned_object.parent_object|linkify }}) + {% endif %}
{% empty %} {{ ''|placeholder }} {% endfor %} From a1ccaef7c9095072e8a4857b8cedb8f64442e5ba Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Thu, 18 Aug 2022 17:12:44 -0500 Subject: [PATCH 5/9] netbox-community#10055: Added empty text --- netbox/ipam/tables/ip.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 493488dac..52b1c4393 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -59,6 +59,8 @@ VRF_LINK = """ NAT_OUTSIDE_LINK = """ {% if record.nat_outside.count > 0 %} {% for nat in record.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %} +{% else %} + — {% endif %} """ From 69feb561f435584e0a1db77c721b8485aa7a3e5f Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:17:35 -0500 Subject: [PATCH 6/9] Updated exists evaluation --- netbox/templates/dcim/device.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 217362311..a798a34b0 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -179,7 +179,7 @@ {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} (NAT for {{ object.primary_ip4.nat_inside.address.ip|linkify }}) - {% elif object.primary_ip4.nat_outside.count > 0 %} + {% elif object.primary_ip4.nat_outside.exists %} (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} @@ -194,7 +194,7 @@ {{ object.primary_ip6.address.ip }} {% if object.primary_ip6.nat_inside %} (NAT for {{ object.primary_ip6.nat_inside.address.ip|linkify }}) - {% elif object.primary_ip6.nat_outside.count > 0 %} + {% elif object.primary_ip6.nat_outside.exists %} (NAT for {% for nat in object.primary_ip6.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} From ce62efda549f40559ff8e4034653b952ed3826f4 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:18:25 -0500 Subject: [PATCH 7/9] Updated exists evaluation --- netbox/templates/virtualization/virtualmachine.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 3826e0cf2..8b69374f1 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -45,7 +45,7 @@ {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) - {% elif object.primary_ip4.nat_outside.count > 0 %} + {% elif object.primary_ip4.nat_outside.exists %} (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} @@ -60,7 +60,7 @@ {{ object.primary_ip6.address.ip }} {% if object.primary_ip6.nat_inside %} (NAT for {{ object.primary_ip6.nat_inside.address.ip }}) - {% elif object.primary_ip4.nat_outside.count > 0 %} + {% elif object.primary_ip4.nat_outside.exists %} (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} From 66999a7c74758088b5ccfe0c5af51432ce9db111 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:22:53 -0500 Subject: [PATCH 8/9] Corrected IPv6 family --- netbox/templates/virtualization/virtualmachine.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 8b69374f1..5756d939a 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -60,8 +60,8 @@ {{ object.primary_ip6.address.ip }} {% if object.primary_ip6.nat_inside %} (NAT for {{ object.primary_ip6.nat_inside.address.ip }}) - {% elif object.primary_ip4.nat_outside.exists %} - (NAT for {% for nat in object.primary_ip4.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) + {% elif object.primary_ip6.nat_outside.exists %} + (NAT for {% for nat in object.primary_ip6.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% endif %} {% else %} {{ ''|placeholder }} From c7f862a31cf370a096372826fd425f5b407afa57 Mon Sep 17 00:00:00 2001 From: atownson <52260120+atownson@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:34:44 -0500 Subject: [PATCH 9/9] Changed nat_outside to ManyToManyColumn --- netbox/ipam/tables/ip.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 52b1c4393..82f4686c0 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -56,14 +56,6 @@ VRF_LINK = """ {% endif %} """ -NAT_OUTSIDE_LINK = """ -{% if record.nat_outside.count > 0 %} - {% for nat in record.nat_outside.all %}{{ nat.address.ip }}{% if not forloop.last %}, {% endif %}{% endfor %} -{% else %} - — -{% endif %} -""" - # # RIRs @@ -368,8 +360,8 @@ class IPAddressTable(TenancyColumnsMixin, NetBoxTable): orderable=False, verbose_name='NAT (Inside)' ) - nat_outside = tables.TemplateColumn( - template_code=NAT_OUTSIDE_LINK, + nat_outside = tables.ManyToManyColumn( + linkify_item=True, orderable=False, verbose_name='NAT (Outside)' )