Merge pull request #10424 from netbox-community/9892-fhrpgroup-name

9892 fhrpgroup name
This commit is contained in:
Jeremy Stretch 2022-09-27 09:48:11 -04:00 committed by GitHub
commit d08d5620da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 65 additions and 12 deletions

View File

@ -19,6 +19,14 @@ The wire protocol employed by cooperating servers to maintain the virtual [IP ad
The group's numeric identifier. The group's numeric identifier.
### Name
An optional name for the FHRP group.
### Description
A brief description of the FHRP group.
### Authentication Type ### Authentication Type
The type of authentication employed by group nodes, if any. The type of authentication employed by group nodes, if any.

View File

@ -123,7 +123,7 @@ class FHRPGroupSerializer(NetBoxModelSerializer):
class Meta: class Meta:
model = FHRPGroup model = FHRPGroup
fields = [ 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', 'tags', 'custom_fields', 'created', 'last_updated',
] ]

View File

@ -653,13 +653,14 @@ class FHRPGroupFilterSet(NetBoxModelFilterSet):
class Meta: class Meta:
model = FHRPGroup model = FHRPGroup
fields = ['id', 'group_id', 'auth_key'] fields = ['id', 'group_id', 'name', 'auth_key']
def search(self, queryset, name, value): def search(self, queryset, name, value):
if not value.strip(): if not value.strip():
return queryset return queryset
return queryset.filter( return queryset.filter(
Q(description__icontains=value) Q(description__icontains=value) |
Q(name__icontains=value)
) )
def filter_related_ip(self, queryset, name, value): def filter_related_ip(self, queryset, name, value):

View File

@ -321,6 +321,10 @@ class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm):
required=False, required=False,
label='Authentication key' label='Authentication key'
) )
name = forms.CharField(
max_length=100,
required=False
)
description = forms.CharField( description = forms.CharField(
max_length=200, max_length=200,
required=False required=False
@ -328,10 +332,10 @@ class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm):
model = FHRPGroup model = FHRPGroup
fieldsets = ( fieldsets = (
(None, ('protocol', 'group_id', 'description')), (None, ('protocol', 'group_id', 'name', 'description')),
('Authentication', ('auth_type', 'auth_key')), ('Authentication', ('auth_type', 'auth_key')),
) )
nullable_fields = ('auth_type', 'auth_key', 'description') nullable_fields = ('auth_type', 'auth_key', 'name', 'description')
class VLANGroupBulkEditForm(NetBoxModelBulkEditForm): class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):

View File

@ -326,7 +326,7 @@ class FHRPGroupCSVForm(NetBoxModelCSVForm):
class Meta: class Meta:
model = FHRPGroup model = FHRPGroup
fields = ('protocol', 'group_id', 'auth_type', 'auth_key', 'description') fields = ('protocol', 'group_id', 'auth_type', 'auth_key', 'name', 'description')
class VLANGroupCSVForm(NetBoxModelCSVForm): class VLANGroupCSVForm(NetBoxModelCSVForm):

View File

@ -335,9 +335,12 @@ class FHRPGroupFilterForm(NetBoxModelFilterSetForm):
model = FHRPGroup model = FHRPGroup
fieldsets = ( fieldsets = (
(None, ('q', 'tag')), (None, ('q', 'tag')),
('Attributes', ('protocol', 'group_id')), ('Attributes', ('name', 'protocol', 'group_id')),
('Authentication', ('auth_type', 'auth_key')), ('Authentication', ('auth_type', 'auth_key')),
) )
name = forms.CharField(
required=False
)
protocol = MultipleChoiceField( protocol = MultipleChoiceField(
choices=FHRPGroupProtocolChoices, choices=FHRPGroupProtocolChoices,
required=False required=False

View File

@ -527,7 +527,7 @@ class FHRPGroupForm(NetBoxModelForm):
) )
fieldsets = ( fieldsets = (
('FHRP Group', ('protocol', 'group_id', 'description', 'tags')), ('FHRP Group', ('protocol', 'group_id', 'name', 'description', 'tags')),
('Authentication', ('auth_type', 'auth_key')), ('Authentication', ('auth_type', 'auth_key')),
('Virtual IP Address', ('ip_vrf', 'ip_address', 'ip_status')) ('Virtual IP Address', ('ip_vrf', 'ip_address', 'ip_status'))
) )
@ -535,7 +535,7 @@ class FHRPGroupForm(NetBoxModelForm):
class Meta: class Meta:
model = FHRPGroup model = FHRPGroup
fields = ( 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): def save(self, *args, **kwargs):

View File

@ -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),
),
]

View File

@ -22,6 +22,10 @@ class FHRPGroup(NetBoxModel):
group_id = models.PositiveSmallIntegerField( group_id = models.PositiveSmallIntegerField(
verbose_name='Group ID' verbose_name='Group ID'
) )
name = models.CharField(
max_length=100,
blank=True
)
protocol = models.CharField( protocol = models.CharField(
max_length=50, max_length=50,
choices=FHRPGroupProtocolChoices choices=FHRPGroupProtocolChoices
@ -55,7 +59,11 @@ class FHRPGroup(NetBoxModel):
verbose_name = 'FHRP group' verbose_name = 'FHRP group'
def __str__(self): def __str__(self):
name = f'{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 # Append the first assigned IP addresses (if any) to serve as an additional identifier
if self.pk: if self.pk:

View File

@ -36,7 +36,7 @@ class FHRPGroupTable(NetBoxTable):
class Meta(NetBoxTable.Meta): class Meta(NetBoxTable.Meta):
model = FHRPGroup model = FHRPGroup
fields = ( fields = (
'pk', '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', 'tags', 'created', 'last_updated',
) )
default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'member_count') default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'member_count')

View File

@ -552,6 +552,7 @@ class FHRPGroupTest(APIViewTestCases.APIViewTestCase):
'group_id': 200, 'group_id': 200,
'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5,
'auth_key': 'foobarbaz999', 'auth_key': 'foobarbaz999',
'name': 'foobar-999',
'description': 'New description', 'description': 'New description',
} }

View File

@ -932,7 +932,7 @@ class FHRPGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
fhrp_groups = ( fhrp_groups = (
FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP2, group_id=10, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_PLAINTEXT, auth_key='foo123'), 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(protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP, group_id=30),
) )
FHRPGroup.objects.bulk_create(fhrp_groups) FHRPGroup.objects.bulk_create(fhrp_groups)
@ -956,6 +956,10 @@ class FHRPGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
params = {'auth_key': ['foo123', 'bar456']} params = {'auth_key': ['foo123', 'bar456']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) 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): def test_related_ip(self):
# Create some regular IPs to query for related IPs # Create some regular IPs to query for related IPs
ipaddresses = ( ipaddresses = (

View File

@ -524,6 +524,7 @@ class FHRPGroupTestCase(ViewTestCases.PrimaryObjectViewTestCase):
'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, 'auth_type': FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5,
'auth_key': 'abc123def456', 'auth_key': 'abc123def456',
'description': 'Blah blah blah', 'description': 'Blah blah blah',
'name': 'test123 name',
'tags': [t.pk for t in tags], 'tags': [t.pk for t in tags],
} }

View File

@ -26,6 +26,10 @@
<td>Group ID</td> <td>Group ID</td>
<td>{{ object.group_id }}</td> <td>{{ object.group_id }}</td>
</tr> </tr>
<tr>
<td>Name</td>
<td>{{ object.name|placeholder }}</td>
</tr>
<tr> <tr>
<td>Description</td> <td>Description</td>
<td>{{ object.description|placeholder }}</td> <td>{{ object.description|placeholder }}</td>

View File

@ -8,6 +8,7 @@
</div> </div>
{% render_field form.protocol %} {% render_field form.protocol %}
{% render_field form.group_id %} {% render_field form.group_id %}
{% render_field form.name %}
{% render_field form.description %} {% render_field form.description %}
{% render_field form.tags %} {% render_field form.tags %}
</div> </div>