Просмотр исходного кода

Closes #1202: Support overlapping assignment of NAT IP addresses

jeremystretch 3 лет назад
Родитель
Сommit
01d2ede097

+ 8 - 0
docs/release-notes/version-3.3.md

@@ -2,8 +2,13 @@
 
 
 ## v3.3.0 (FUTURE)
 ## v3.3.0 (FUTURE)
 
 
+### Breaking Changes
+
+* The `nat_outside` relation on the IP address model now returns a list of zero or more related IP addresses, rather than a single instance (or None).
+
 ### Enhancements
 ### Enhancements
 
 
+* [#1202](https://github.com/netbox-community/netbox/issues/1202) - Support overlapping assignment of NAT IP addresses
 * [#8495](https://github.com/netbox-community/netbox/issues/8495) - Enable custom field grouping
 * [#8495](https://github.com/netbox-community/netbox/issues/8495) - Enable custom field grouping
 * [#8995](https://github.com/netbox-community/netbox/issues/8995) - Enable arbitrary ordering of REST API results
 * [#8995](https://github.com/netbox-community/netbox/issues/8995) - Enable arbitrary ordering of REST API results
 
 
@@ -15,3 +20,6 @@
 
 
 * extras.CustomField
 * extras.CustomField
     * Added `group_name` field
     * Added `group_name` field
+* ipam.IPAddress
+    * The `nat_inside` field no longer requires a unique value
+    * The `nat_outside` field has changed from a single IP address instance to a list of multiple IP addresses

+ 1 - 2
netbox/ipam/api/serializers.py

@@ -360,7 +360,7 @@ class IPAddressSerializer(NetBoxModelSerializer):
     )
     )
     assigned_object = serializers.SerializerMethodField(read_only=True)
     assigned_object = serializers.SerializerMethodField(read_only=True)
     nat_inside = NestedIPAddressSerializer(required=False, allow_null=True)
     nat_inside = NestedIPAddressSerializer(required=False, allow_null=True)
-    nat_outside = NestedIPAddressSerializer(required=False, read_only=True)
+    nat_outside = NestedIPAddressSerializer(many=True, read_only=True)
 
 
     class Meta:
     class Meta:
         model = IPAddress
         model = IPAddress
@@ -369,7 +369,6 @@ class IPAddressSerializer(NetBoxModelSerializer):
             'assigned_object_id', 'assigned_object', 'nat_inside', 'nat_outside', 'dns_name', 'description', 'tags',
             'assigned_object_id', 'assigned_object', 'nat_inside', 'nat_outside', 'dns_name', 'description', 'tags',
             'custom_fields', 'created', 'last_updated',
             'custom_fields', 'created', 'last_updated',
         ]
         ]
-        read_only_fields = ['family', 'nat_outside']
 
 
     @swagger_serializer_method(serializer_or_field=serializers.DictField)
     @swagger_serializer_method(serializer_or_field=serializers.DictField)
     def get_assigned_object(self, obj):
     def get_assigned_object(self, obj):

+ 17 - 0
netbox/ipam/migrations/0058_ipaddress_nat_inside_nonunique.py

@@ -0,0 +1,17 @@
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ipam', '0057_created_datetimefield'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='ipaddress',
+            name='nat_inside',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='nat_outside', to='ipam.ipaddress'),
+        ),
+    ]

+ 1 - 1
netbox/ipam/models/ip.py

@@ -813,7 +813,7 @@ class IPAddress(NetBoxModel):
         ct_field='assigned_object_type',
         ct_field='assigned_object_type',
         fk_field='assigned_object_id'
         fk_field='assigned_object_id'
     )
     )
-    nat_inside = models.OneToOneField(
+    nat_inside = models.ForeignKey(
         to='self',
         to='self',
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name='nat_outside',
         related_name='nat_outside',

+ 8 - 2
netbox/templates/ipam/ipaddress.html

@@ -91,8 +91,14 @@
                       </td>
                       </td>
                   </tr>
                   </tr>
                   <tr>
                   <tr>
-                      <th scope="row">NAT (outside)</th>
-                      <td>{{ object.nat_outside|linkify|placeholder }}</td>
+                      <th scope="row">Outside NAT IPs</th>
+                      <td>
+                        {% for ip in object.nat_outside.all %}
+                          {{ ip|linkify }}<br/>
+                        {% empty %}
+                          {{ ''|placeholder }}
+                        {% endfor %}
+                      </td>
                   </tr>
                   </tr>
               </table>
               </table>
           </div>
           </div>