Compare commits

..

6 Commits

Author SHA1 Message Date
Brian Tiemann
087a2adb3c Also include vminterface.html 2026-01-22 22:16:12 -05:00
Brian Tiemann
a145dbc44a Ensure "-" null placeholder still shows up on detail page 2026-01-22 22:13:12 -05:00
Brian Tiemann
9b1f033c73 Use mac_address_display in interface detail page 2026-01-22 22:08:30 -05:00
Brian Tiemann
60e37e868b Fix docstring 2026-01-22 22:02:40 -05:00
Brian Tiemann
c1287de970 Fix docstring 2026-01-22 22:00:42 -05:00
Brian Tiemann
3891b2a25f Richer display of MAC addresses in InterfaceTable when multiple MACs are present 2026-01-22 21:56:33 -05:00
6 changed files with 32 additions and 22 deletions

View File

@@ -732,6 +732,25 @@ 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,

View File

@@ -616,6 +616,7 @@ class BaseInterfaceTable(NetBoxTable):
)
primary_mac_address = tables.Column(
verbose_name=_('MAC Address'),
accessor=Accessor('mac_address_display'),
linkify=True
)

View File

@@ -86,7 +86,7 @@ def enqueue_event(queue, instance, request, event_type):
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
user = None # To be resolved from the username if needed
user = User.objects.get(username=username) if username else None
for event_rule in event_rules:
@@ -134,10 +134,6 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
# Resolve the script from action parameters
script = event_rule.action_object.python_class()
# Retrieve the User if not already resolved
if user is None:
user = User.objects.get(username=username)
# Enqueue a Job to record the script's execution
from extras.jobs import ScriptJob
params = {

View File

@@ -1,6 +1,5 @@
import re
from collections import namedtuple
import logging
from django.conf import settings
from django.contrib import messages
@@ -29,8 +28,6 @@ __all__ = (
'SearchView',
)
logger = logging.getLogger(f'netbox.{__name__}')
Link = namedtuple('Link', ('label', 'viewname', 'permission', 'count'))
@@ -53,14 +50,7 @@ class HomeView(ConditionalLoginRequiredMixin, View):
# Check whether a new release is available. (Only for superusers.)
new_release = None
if request.user.is_superuser:
# cache.get() can raise if the cached value can't be unpickled after dependency upgrades
try:
latest_release = cache.get('latest_release')
except Exception:
logger.debug("Failed to read 'latest_release' from cache; deleting key", exc_info=True)
cache.delete('latest_release')
latest_release = None
latest_release = cache.get('latest_release')
if latest_release:
release_version, release_url = latest_release
if release_version > version.parse(settings.RELEASE.version):

View File

@@ -143,9 +143,11 @@
<tr>
<th scope="row">{% trans "MAC Address" %}</th>
<td>
{% if object.primary_mac_address %}
<span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
{% 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 %}
{% else %}
{{ ''|placeholder }}
{% endif %}

View File

@@ -78,9 +78,11 @@
<tr>
<th scope="row">{% trans "MAC Address" %}</th>
<td>
{% if object.mac_address %}
<span class="font-monospace">{{ object.mac_address }}</span>
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
{% 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 %}
{% else %}
{{ ''|placeholder }}
{% endif %}