Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9892 fhrpgroup name #10424

Merged
merged 8 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/models/ipam/fhrpgroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion netbox/ipam/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

Expand Down
5 changes: 3 additions & 2 deletions netbox/ipam/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,14 @@ 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():
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):
Expand Down
8 changes: 6 additions & 2 deletions netbox/ipam/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,21 @@ class FHRPGroupBulkEditForm(NetBoxModelBulkEditForm):
required=False,
label='Authentication key'
)
name = forms.CharField(
max_length=100,
required=False
)
description = forms.CharField(
max_length=200,
required=False
)

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):
Expand Down
2 changes: 1 addition & 1 deletion netbox/ipam/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion netbox/ipam/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions netbox/ipam/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,15 @@ 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'))
)

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):
Expand Down
18 changes: 18 additions & 0 deletions netbox/ipam/migrations/0061_fhrpgroup_name.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
10 changes: 9 additions & 1 deletion netbox/ipam/models/fhrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,7 +59,11 @@ class Meta:
verbose_name = 'FHRP group'

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
if self.pk:
Expand Down
2 changes: 1 addition & 1 deletion netbox/ipam/tables/fhrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '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')
Expand Down
1 change: 1 addition & 0 deletions netbox/ipam/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
6 changes: 5 additions & 1 deletion netbox/ipam/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = (
Expand Down
1 change: 1 addition & 0 deletions netbox/ipam/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand Down
4 changes: 4 additions & 0 deletions netbox/templates/ipam/fhrpgroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ <h5 class="card-header">FHRP Group</h5>
<td>Group ID</td>
<td>{{ object.group_id }}</td>
</tr>
<tr>
<td>Name</td>
<td>{{ object.name|placeholder }}</td>
</tr>
<tr>
<td>Description</td>
<td>{{ object.description|placeholder }}</td>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/ipam/fhrpgroup_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h5 class="offset-sm-3">FHRP Group</h5>
</div>
{% render_field form.protocol %}
{% render_field form.group_id %}
{% render_field form.name %}
{% render_field form.description %}
{% render_field form.tags %}
</div>
Expand Down