Skip to content

Commit 5f59f45

Browse files
committed
Fixes #7880: Include assigned IP addresses in FHRP group object representation
1 parent b6fe613 commit 5f59f45

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

docs/release-notes/version-3.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [#7768](https://github.com/netbox-community/netbox/issues/7768) - Validate IP address status when creating a new FHRP group
2525
* [#7771](https://github.com/netbox-community/netbox/issues/7771) - Group assignment should be optional when creating contacts via REST API
2626
* [#7849](https://github.com/netbox-community/netbox/issues/7849) - Fix exception when creating an FHRPGroup with an invalid IP address
27+
* [#7880](https://github.com/netbox-community/netbox/issues/7880) - Include assigned IP addresses in FHRP group object representation
2728

2829
### REST API Changes
2930

netbox/dcim/tables/template_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
INTERFACE_FHRPGROUPS = """
5454
<div class="table-badge-group">
5555
{% for assignment in value.all %}
56-
<a href="{{ assignment.group.get_absolute_url }}">{{ assignment.group.group_id }} ({{ assignment.group.get_protocol_display }})</a>
56+
<a href="{{ assignment.group.get_absolute_url }}">{{ assignment.group.get_protocol_display }}: {{ assignment.group.group_id }}</a>
5757
{% endfor %}
5858
</div>
5959
"""

netbox/ipam/api/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class FHRPGroupViewSet(CustomFieldModelViewSet):
138138
queryset = FHRPGroup.objects.prefetch_related('ip_addresses', 'tags')
139139
serializer_class = serializers.FHRPGroupSerializer
140140
filterset_class = filtersets.FHRPGroupFilterSet
141+
brief_prefetch_fields = ('ip_addresses',)
141142

142143

143144
class FHRPGroupAssignmentViewSet(CustomFieldModelViewSet):

netbox/ipam/models/fhrp.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ class Meta:
5656
verbose_name = 'FHRP group'
5757

5858
def __str__(self):
59-
return f'{self.get_protocol_display()} group {self.group_id}'
59+
name = f'{self.get_protocol_display()}: {self.group_id}'
60+
61+
# Append the list of assigned IP addresses to serve as an additional identifier
62+
if self.pk:
63+
ip_addresses = [
64+
str(ip.address) for ip in self.ip_addresses.all()
65+
]
66+
if ip_addresses:
67+
return f"{name} ({', '.join(ip_addresses)})"
68+
69+
return name
6070

6171
def get_absolute_url(self):
6272
return reverse('ipam:fhrpgroup', args=[self.pk])

netbox/templates/ipam/fhrpgroup.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
{% load plugins %}
44
{% load render_table from django_tables2 %}
55

6+
{# Omit assigned IP addresses from object representation #}
7+
{% block title %}{{ object.get_protocol_display }}: {{ object.group_id }}{% endblock %}
8+
69
{% block breadcrumbs %}
710
{{ block.super }}
811
<li class="breadcrumb-item"><a href="{% url 'ipam:fhrpgroup_list' %}?protocol={{ object.protocol }}">{{ object.get_protocol_display }}</a></li>

0 commit comments

Comments
 (0)