mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-23 12:08:43 -06:00
Compare commits
1 Commits
19129-mac-
...
19869-prov
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45b6b170d |
@@ -732,25 +732,6 @@ class BaseInterface(models.Model):
|
||||
if self.primary_mac_address:
|
||||
return self.primary_mac_address.mac_address
|
||||
|
||||
@property
|
||||
def mac_address_display(self):
|
||||
"""
|
||||
Rich representation of MAC addresses for use in table columns (e.g. InterfaceTable).
|
||||
Handles various configurations of MAC addresses for an interface:
|
||||
11:22:33:44:55:66 <-- Single MAC address on interface, assigned as primary
|
||||
11:22:33:44:55:66 (2) <-- Multiple MAC addresses on interface, one assigned as primary
|
||||
2 available <-- 1 or more MAC addresses on interface, none assigned as primary
|
||||
- <-- No MAC addresses on interface
|
||||
"""
|
||||
available_mac_count = self.mac_addresses.count()
|
||||
if self.primary_mac_address:
|
||||
if available_mac_count > 1:
|
||||
return f"{self.primary_mac_address} ({available_mac_count})"
|
||||
return self.primary_mac_address
|
||||
if available_mac_count:
|
||||
return f"{available_mac_count} available"
|
||||
return None
|
||||
|
||||
|
||||
class Interface(
|
||||
InterfaceValidationMixin,
|
||||
|
||||
@@ -27,6 +27,7 @@ __all__ = (
|
||||
'DeviceTable',
|
||||
'FrontPortTable',
|
||||
'InterfaceTable',
|
||||
'InterfaceLAGMemberTable',
|
||||
'InventoryItemRoleTable',
|
||||
'InventoryItemTable',
|
||||
'MACAddressTable',
|
||||
@@ -616,7 +617,6 @@ class BaseInterfaceTable(NetBoxTable):
|
||||
)
|
||||
primary_mac_address = tables.Column(
|
||||
verbose_name=_('MAC Address'),
|
||||
accessor=Accessor('mac_address_display'),
|
||||
linkify=True
|
||||
)
|
||||
|
||||
@@ -690,6 +690,33 @@ class InterfaceTable(BaseInterfaceTable, ModularDeviceComponentTable, PathEndpoi
|
||||
default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
|
||||
|
||||
|
||||
class InterfaceLAGMemberTable(PathEndpointTable, NetBoxTable):
|
||||
parent = tables.Column(
|
||||
verbose_name=_('Parent'),
|
||||
accessor=Accessor('device'),
|
||||
linkify=True,
|
||||
)
|
||||
name = tables.Column(
|
||||
verbose_name=_('Name'),
|
||||
linkify=True,
|
||||
order_by=('_name',),
|
||||
)
|
||||
connection = columns.TemplateColumn(
|
||||
accessor='connected_endpoints',
|
||||
template_code=INTERFACE_LAG_MEMBERS_LINKTERMINATION,
|
||||
verbose_name=_('Peer'),
|
||||
orderable=False,
|
||||
)
|
||||
tags = columns.TagColumn(
|
||||
url_name='dcim:interface_list'
|
||||
)
|
||||
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = models.Interface
|
||||
fields = ('pk', 'parent', 'name', 'type', 'connection')
|
||||
default_columns = ('pk', 'parent', 'name', 'type', 'connection')
|
||||
|
||||
|
||||
class DeviceInterfaceTable(InterfaceTable):
|
||||
name = tables.TemplateColumn(
|
||||
verbose_name=_('Name'),
|
||||
|
||||
@@ -24,6 +24,24 @@ INTERFACE_LINKTERMINATION = """
|
||||
{% else %}""" + LINKTERMINATION + """{% endif %}
|
||||
"""
|
||||
|
||||
INTERFACE_LAG_MEMBERS_LINKTERMINATION = """
|
||||
{% for termination in value %}
|
||||
{% if termination.parent_object %}
|
||||
<a href="{{ termination.parent_object.get_absolute_url }}">{{ termination.parent_object }}</a>
|
||||
<i class="mdi mdi-chevron-right"></i>
|
||||
{% endif %}
|
||||
<a href="{{ termination.get_absolute_url }}">{{ termination }}</a>
|
||||
{% if termination.lag %}
|
||||
<i class="mdi mdi-chevron-right"></i>
|
||||
<a href="{{ termination.lag.get_absolute_url }}">{{ termination.lag }}</a>
|
||||
<span class="text-muted">(LAG)</span>
|
||||
{% endif %}
|
||||
{% if not forloop.last %}<br />{% endif %}
|
||||
{% empty %}
|
||||
{{ ''|placeholder }}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
CABLE_LENGTH = """
|
||||
{% load helpers %}
|
||||
{% if record.length %}{{ record.length|floatformat:"-2" }} {{ record.length_unit }}{% endif %}
|
||||
|
||||
@@ -3135,6 +3135,14 @@ class InterfaceView(generic.ObjectView):
|
||||
)
|
||||
child_interfaces_table.configure(request)
|
||||
|
||||
# Get LAG interfaces
|
||||
lag_interfaces = Interface.objects.restrict(request.user, 'view').filter(lag=instance)
|
||||
lag_interfaces_table = tables.InterfaceLAGMemberTable(
|
||||
lag_interfaces,
|
||||
orderable=False
|
||||
)
|
||||
lag_interfaces_table.configure(request)
|
||||
|
||||
# Get assigned VLANs and annotate whether each is tagged or untagged
|
||||
vlans = []
|
||||
if instance.untagged_vlan is not None:
|
||||
@@ -3164,6 +3172,7 @@ class InterfaceView(generic.ObjectView):
|
||||
'bridge_interfaces': bridge_interfaces,
|
||||
'bridge_interfaces_table': bridge_interfaces_table,
|
||||
'child_interfaces_table': child_interfaces_table,
|
||||
'lag_interfaces_table': lag_interfaces_table,
|
||||
'vlan_table': vlan_table,
|
||||
'vlan_translation_table': vlan_translation_table,
|
||||
}
|
||||
|
||||
@@ -143,11 +143,9 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans "MAC Address" %}</th>
|
||||
<td>
|
||||
{% if object.mac_address_display %}
|
||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% endif %}
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
@@ -372,33 +370,6 @@
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if object.is_lag %}
|
||||
<div class="card">
|
||||
<h2 class="card-header">{% trans "LAG Members" %}</h2>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Parent" %}</th>
|
||||
<th>{% trans "Interface" %}</th>
|
||||
<th>{% trans "Type" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for member in object.member_interfaces.all %}
|
||||
<tr>
|
||||
<td>{{ member.device|linkify }}</td>
|
||||
<td>{{ member|linkify }}</td>
|
||||
<td>{{ member.get_type_display }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="3" class="text-muted">{% trans "No member interfaces" %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'ipam/inc/panels/fhrp_groups.html' %}
|
||||
{% include 'dcim/inc/panels/inventory_items.html' %}
|
||||
{% plugin_right_page object %}
|
||||
@@ -443,6 +414,13 @@
|
||||
{% include 'inc/panel_table.html' with table=vlan_table heading="VLANs" %}
|
||||
</div>
|
||||
</div>
|
||||
{% if object.is_lag %}
|
||||
<div class="row mb-3">
|
||||
<div class="col col-md-12">
|
||||
{% include 'inc/panel_table.html' with table=lag_interfaces_table heading="LAG Members" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if object.vlan_translation_policy %}
|
||||
<div class="row mb-3">
|
||||
<div class="col col-md-12">
|
||||
|
||||
@@ -78,11 +78,9 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans "MAC Address" %}</th>
|
||||
<td>
|
||||
{% if object.mac_address_display %}
|
||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% endif %}
|
||||
{% if object.mac_address %}
|
||||
<span class="font-monospace">{{ object.mac_address }}</span>
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user