Skip to content

Commit

Permalink
Show OSPF Ares per OSPF instance
Browse files Browse the repository at this point in the history
Define convenience method 'get_areas' that naturally sorts the areas in the instance
  • Loading branch information
LuPo committed Nov 28, 2024
1 parent e059416 commit dfda841
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netbox_routing/models/ospf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import netaddr
import ipaddress
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
Expand Down Expand Up @@ -48,6 +49,12 @@ class Meta:

def __str__(self):
return f'{self.name} ({self.router_id})'

def get_areas(self):
instance_areas = OSPFArea.objects.filter(interfaces__instance=self).distinct("area_id")
return sorted(instance_areas.iterator(), key=lambda area: ipaddress.IPv4Address(
int(area.area_id) if area.area_id.isdigit() else area.area_id)
)

def get_absolute_url(self):
return reverse('plugins:netbox_routing:ospfinstance', args=[self.pk])
Expand Down
17 changes: 17 additions & 0 deletions netbox_routing/templates/netbox_routing/ospfinstance.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ <h5 class="card-header">OSPF Details</h5>
</tr>
</table>
</div>
</div>
<div class="card">
<h5 class="card-header">OSPF Areas</h5>
<div class="card-body">
<table class="table table-hover attr-table">
{% for area in object.get_areas %}
<tr>
<td>
{{ area|linkify }}
</td>
<td>
{{ area.get_area_type_display }}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% plugin_left_page object %}
</div>
Expand Down

0 comments on commit dfda841

Please sign in to comment.