From 5d07f2c837a140b316598206fa76ead1792a3fde Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 20 Sep 2022 16:03:55 -0700 Subject: [PATCH 1/7] 9892 add FHRP group name --- netbox/ipam/migrations/0061_fhrpgroup_name.py | 18 ++++++++++++++++++ netbox/ipam/models/fhrp.py | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 netbox/ipam/migrations/0061_fhrpgroup_name.py diff --git a/netbox/ipam/migrations/0061_fhrpgroup_name.py b/netbox/ipam/migrations/0061_fhrpgroup_name.py new file mode 100644 index 0000000000..7e232c18fe --- /dev/null +++ b/netbox/ipam/migrations/0061_fhrpgroup_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.7 on 2022-09-20 23:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ipam', '0060_alter_l2vpn_slug'), + ] + + operations = [ + migrations.AddField( + model_name='fhrpgroup', + name='name', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/ipam/models/fhrp.py b/netbox/ipam/models/fhrp.py index 2862514440..b022386c84 100644 --- a/netbox/ipam/models/fhrp.py +++ b/netbox/ipam/models/fhrp.py @@ -22,6 +22,10 @@ class FHRPGroup(NetBoxModel): group_id = models.PositiveSmallIntegerField( verbose_name='Group ID' ) + name = models.CharField( + max_length=100, + blank=True + ) protocol = models.CharField( max_length=50, choices=FHRPGroupProtocolChoices From a5421ae1707142c0ceb74399757df765a2a9f8d4 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 20 Sep 2022 16:13:01 -0700 Subject: [PATCH 2/7] 9892 add FHRP group name --- netbox/ipam/filtersets.py | 2 +- netbox/ipam/tables/fhrp.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index 3c0ab1ac86..1eb1ee8638 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -653,7 +653,7 @@ class FHRPGroupFilterSet(NetBoxModelFilterSet): class Meta: model = FHRPGroup - fields = ['id', 'group_id', 'auth_key'] + fields = ['id', 'group_id', 'name', 'auth_key'] def search(self, queryset, name, value): if not value.strip(): diff --git a/netbox/ipam/tables/fhrp.py b/netbox/ipam/tables/fhrp.py index f709bfeb22..dc4982e269 100644 --- a/netbox/ipam/tables/fhrp.py +++ b/netbox/ipam/tables/fhrp.py @@ -36,7 +36,7 @@ class FHRPGroupTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = FHRPGroup fields = ( - 'pk', 'group_id', 'protocol', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'member_count', + 'pk', 'name', 'group_id', 'protocol', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'member_count', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'member_count') From e11d5941222312cde96429b411d04c88db8f300c Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 26 Sep 2022 11:39:43 -0700 Subject: [PATCH 3/7] 9892 add supporting tests, form fields --- docs/models/ipam/fhrpgroup.md | 8 ++++++++ netbox/ipam/api/serializers.py | 2 +- netbox/ipam/filtersets.py | 3 ++- netbox/ipam/forms/bulk_edit.py | 4 ++-- netbox/ipam/forms/bulk_import.py | 2 +- netbox/ipam/forms/filtersets.py | 5 ++++- netbox/ipam/forms/models.py | 4 ++-- netbox/ipam/tables/fhrp.py | 2 +- netbox/ipam/tests/test_api.py | 1 + netbox/ipam/tests/test_filtersets.py | 6 +++++- netbox/ipam/tests/test_views.py | 1 + netbox/templates/ipam/fhrpgroup.html | 4 ++++ netbox/templates/ipam/fhrpgroup_edit.html | 1 + 13 files changed, 33 insertions(+), 10 deletions(-) diff --git a/docs/models/ipam/fhrpgroup.md b/docs/models/ipam/fhrpgroup.md index 4da390310e..ddb3010e26 100644 --- a/docs/models/ipam/fhrpgroup.md +++ b/docs/models/ipam/fhrpgroup.md @@ -19,6 +19,14 @@ The wire protocol employed by cooperating servers to maintain the virtual [IP ad The group's numeric identifier. +### Name + +An optional name for the FHRP group. + +### Description + +A brief description of the FHRP group. + ### Authentication Type The type of authentication employed by group nodes, if any. diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py index fa8b563e95..8a8fc03d63 100644 --- a/netbox/ipam/api/serializers.py +++ b/netbox/ipam/api/serializers.py @@ -123,7 +123,7 @@ class FHRPGroupSerializer(NetBoxModelSerializer): class Meta: model = FHRPGroup fields = [ - 'id', 'url', 'display', 'protocol', 'group_id', 'auth_type', 'auth_key', 'description', 'ip_addresses', + 'id', 'name', 'url', 'display', 'protocol', 'group_id', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'tags', 'custom_fields', 'created', 'last_updated', ] diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index 1eb1ee8638..360cf2a56f 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -659,7 +659,8 @@ def search(self, queryset, name, value): if not value.strip(): return queryset return queryset.filter( - Q(description__icontains=value) + Q(description__icontains=value) | + Q(name__icontains=value) ) def filter_related_ip(self, queryset, name, value): diff --git a/netbox/ipam/forms/bulk_edit.py b/netbox/ipam/forms/bulk_edit.py index 5f579b07f0..7746b6625b 100644 --- a/netbox/ipam/forms/bulk_edit.py +++ b/netbox/ipam/forms/bulk_edit.py @@ -328,10 +328,10 @@ class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm): model = FHRPGroup fieldsets = ( - (None, ('protocol', 'group_id', 'description')), + (None, ('protocol', 'group_id', 'name', 'description')), ('Authentication', ('auth_type', 'auth_key')), ) - nullable_fields = ('auth_type', 'auth_key', 'description') + nullable_fields = ('auth_type', 'auth_key', 'name', 'description') class VLANGroupBulkEditForm(NetBoxModelBulkEditForm): diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 880d2722f4..6a9dd91aca 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -326,7 +326,7 @@ class FHRPGroupCSVForm(NetBoxModelCSVForm): class Meta: model = FHRPGroup - fields = ('protocol', 'group_id', 'auth_type', 'auth_key', 'description') + fields = ('protocol', 'group_id', 'auth_type', 'auth_key', 'name', 'description') class VLANGroupCSVForm(NetBoxModelCSVForm): diff --git a/netbox/ipam/forms/filtersets.py b/netbox/ipam/forms/filtersets.py index ecf63b49f3..a2ff7085b9 100644 --- a/netbox/ipam/forms/filtersets.py +++ b/netbox/ipam/forms/filtersets.py @@ -335,9 +335,12 @@ class FHRPGroupFilterForm(NetBoxModelFilterSetForm): model = FHRPGroup fieldsets = ( (None, ('q', 'tag')), - ('Attributes', ('protocol', 'group_id')), + ('Attributes', ('name', 'protocol', 'group_id')), ('Authentication', ('auth_type', 'auth_key')), ) + name = forms.CharField( + required=False + ) protocol = MultipleChoiceField( choices=FHRPGroupProtocolChoices, required=False diff --git a/netbox/ipam/forms/models.py b/netbox/ipam/forms/models.py index 7248125856..dea42065c0 100644 --- a/netbox/ipam/forms/models.py +++ b/netbox/ipam/forms/models.py @@ -527,7 +527,7 @@ class FHRPGroupForm(NetBoxModelForm): ) fieldsets = ( - ('FHRP Group', ('protocol', 'group_id', 'description', 'tags')), + ('FHRP Group', ('protocol', 'group_id', 'name', 'description', 'tags')), ('Authentication', ('auth_type', 'auth_key')), ('Virtual IP Address', ('ip_vrf', 'ip_address', 'ip_status')) ) @@ -535,7 +535,7 @@ class FHRPGroupForm(NetBoxModelForm): class Meta: model = FHRPGroup fields = ( - 'protocol', 'group_id', 'auth_type', 'auth_key', 'description', 'ip_vrf', 'ip_address', 'ip_status', 'tags', + 'protocol', 'group_id', 'auth_type', 'auth_key', 'name', 'description', 'ip_vrf', 'ip_address', 'ip_status', 'tags', ) def save(self, *args, **kwargs): diff --git a/netbox/ipam/tables/fhrp.py b/netbox/ipam/tables/fhrp.py index dc4982e269..cfbfb036b1 100644 --- a/netbox/ipam/tables/fhrp.py +++ b/netbox/ipam/tables/fhrp.py @@ -36,7 +36,7 @@ class FHRPGroupTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = FHRPGroup fields = ( - 'pk', 'name', 'group_id', 'protocol', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'member_count', + 'pk', 'group_id', 'protocol', 'auth_type', 'auth_key', 'name', 'description', 'ip_addresses', 'member_count', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'member_count') diff --git a/netbox/ipam/tests/test_api.py b/netbox/ipam/tests/test_api.py index 0fefb01629..1bbeb04878 100644 --- a/netbox/ipam/tests/test_api.py +++ b/netbox/ipam/tests/test_api.py @@ -552,6 +552,7 @@ class FHRPGroupTest(APIViewTestCases.APIViewTestCase): 'group_id': 200, 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_key': 'foobarbaz999', + 'name': 'foobar-999' 'description': 'New description', } diff --git a/netbox/ipam/tests/test_filtersets.py b/netbox/ipam/tests/test_filtersets.py index 5c41137866..abb5a3cc30 100644 --- a/netbox/ipam/tests/test_filtersets.py +++ b/netbox/ipam/tests/test_filtersets.py @@ -932,7 +932,7 @@ def setUpTestData(cls): fhrp_groups = ( FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP2, group_id=10, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_PLAINTEXT, auth_key='foo123'), - FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP3, group_id=20, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, auth_key='bar456'), + FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP3, group_id=20, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, auth_key='bar456', name='bar123'), FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP, group_id=30), ) FHRPGroup.objects.bulk_create(fhrp_groups) @@ -956,6 +956,10 @@ def test_auth_key(self): params = {'auth_key': ['foo123', 'bar456']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) + def test_name(self): + params = {'name': ['bar123', ]} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_related_ip(self): # Create some regular IPs to query for related IPs ipaddresses = ( diff --git a/netbox/ipam/tests/test_views.py b/netbox/ipam/tests/test_views.py index 27520229a0..dc9b891417 100644 --- a/netbox/ipam/tests/test_views.py +++ b/netbox/ipam/tests/test_views.py @@ -524,6 +524,7 @@ def setUpTestData(cls): 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_key': 'abc123def456', 'description': 'Blah blah blah', + 'name': 'test123 name' 'tags': [t.pk for t in tags], } diff --git a/netbox/templates/ipam/fhrpgroup.html b/netbox/templates/ipam/fhrpgroup.html index b4911ce440..89fc7083c1 100644 --- a/netbox/templates/ipam/fhrpgroup.html +++ b/netbox/templates/ipam/fhrpgroup.html @@ -26,6 +26,10 @@
FHRP Group
Group ID {{ object.group_id }} + + Name + {{ object.name|placeholder }} + Description {{ object.description|placeholder }} diff --git a/netbox/templates/ipam/fhrpgroup_edit.html b/netbox/templates/ipam/fhrpgroup_edit.html index 858d265ab2..02816b440c 100644 --- a/netbox/templates/ipam/fhrpgroup_edit.html +++ b/netbox/templates/ipam/fhrpgroup_edit.html @@ -8,6 +8,7 @@
FHRP Group
{% render_field form.protocol %} {% render_field form.group_id %} + {% render_field form.name %} {% render_field form.description %} {% render_field form.tags %} From 3eeb31d5777a434a5e0250cd128a4fdb83039515 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 26 Sep 2022 11:49:51 -0700 Subject: [PATCH 4/7] 9892 doh - fix tests --- netbox/ipam/tests/test_api.py | 2 +- netbox/ipam/tests/test_views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/tests/test_api.py b/netbox/ipam/tests/test_api.py index 1bbeb04878..ea64416502 100644 --- a/netbox/ipam/tests/test_api.py +++ b/netbox/ipam/tests/test_api.py @@ -552,7 +552,7 @@ class FHRPGroupTest(APIViewTestCases.APIViewTestCase): 'group_id': 200, 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_key': 'foobarbaz999', - 'name': 'foobar-999' + 'name': 'foobar-999', 'description': 'New description', } diff --git a/netbox/ipam/tests/test_views.py b/netbox/ipam/tests/test_views.py index dc9b891417..5cc8fad247 100644 --- a/netbox/ipam/tests/test_views.py +++ b/netbox/ipam/tests/test_views.py @@ -524,7 +524,7 @@ def setUpTestData(cls): 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_key': 'abc123def456', 'description': 'Blah blah blah', - 'name': 'test123 name' + 'name': 'test123 name', 'tags': [t.pk for t in tags], } From 5ce805db2e2051b96e174014bbf6d258f65a8433 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 26 Sep 2022 12:56:16 -0700 Subject: [PATCH 5/7] 9892 doh - fix tests --- netbox/ipam/forms/bulk_edit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netbox/ipam/forms/bulk_edit.py b/netbox/ipam/forms/bulk_edit.py index 7746b6625b..67bcf83fb2 100644 --- a/netbox/ipam/forms/bulk_edit.py +++ b/netbox/ipam/forms/bulk_edit.py @@ -321,6 +321,10 @@ class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm): required=False, label='Authentication key' ) + name = forms.CharField( + max_length=100, + required=False + ) description = forms.CharField( max_length=200, required=False From 10cb3c2c3d3550baea4d22ec7c998e1497856571 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 26 Sep 2022 13:54:49 -0700 Subject: [PATCH 6/7] 9892 add name to str --- netbox/ipam/models/fhrp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/ipam/models/fhrp.py b/netbox/ipam/models/fhrp.py index b022386c84..fe61a7fecb 100644 --- a/netbox/ipam/models/fhrp.py +++ b/netbox/ipam/models/fhrp.py @@ -59,7 +59,7 @@ class Meta: verbose_name = 'FHRP group' def __str__(self): - name = f'{self.get_protocol_display()}: {self.group_id}' + name = f'{self.name} {self.get_protocol_display()}: {self.group_id}' # Append the first assigned IP addresses (if any) to serve as an additional identifier if self.pk: From 8103ad3b9e441bedf09f22278604b9d966caddc3 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 26 Sep 2022 13:57:09 -0700 Subject: [PATCH 7/7] 9892 add name to str --- netbox/ipam/models/fhrp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/models/fhrp.py b/netbox/ipam/models/fhrp.py index fe61a7fecb..88e6e19d91 100644 --- a/netbox/ipam/models/fhrp.py +++ b/netbox/ipam/models/fhrp.py @@ -59,7 +59,11 @@ class Meta: verbose_name = 'FHRP group' def __str__(self): - name = f'{self.name} {self.get_protocol_display()}: {self.group_id}' + name = '' + if self.name: + name = f'{self.name} ' + + name += f'{self.get_protocol_display()}: {self.group_id}' # Append the first assigned IP addresses (if any) to serve as an additional identifier if self.pk: