Add ConceptComponent.peer, returning the component on the other end of its cable (whichever termination isn't itself). Use it in the component tables' "Connection" column (Device > Port, both linked, mirroring NetBox's own link_peer style) instead of just linking to the cable object, and on the component detail page's "Connected to" row in place of the manual termination_a/b branch. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
183 lines
7.5 KiB
Python
183 lines
7.5 KiB
Python
import django_tables2 as tables
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from netbox.tables import NetBoxTable, columns
|
|
|
|
from .models import ConceptCable, ConceptComponent, ConceptDeployment, ConceptDevice, RackConcept
|
|
|
|
__all__ = (
|
|
'ConceptCableTable',
|
|
'ConceptComponentTable',
|
|
'ConceptDeploymentTable',
|
|
'ConceptDeviceElevationTable',
|
|
'ConceptDeviceTable',
|
|
'RackConceptTable',
|
|
)
|
|
|
|
|
|
class RackConceptTable(NetBoxTable):
|
|
name = tables.Column(linkify=True)
|
|
status = columns.ChoiceFieldColumn()
|
|
tenant_group = tables.Column(linkify=True, verbose_name=_('Tenant group'))
|
|
tenant = tables.Column(linkify=True)
|
|
rack_type = tables.Column(linkify=True)
|
|
device_count = columns.LinkedCountColumn(
|
|
viewname='plugins:netbox_rack_concept:conceptdevice_list',
|
|
url_params={'concept_id': 'pk'},
|
|
verbose_name=_('Devices')
|
|
)
|
|
utilization = columns.UtilizationColumn(
|
|
accessor='utilization',
|
|
orderable=False,
|
|
verbose_name=_('Utilization')
|
|
)
|
|
source_rack = tables.Column(linkify=True, verbose_name=_('Copied from'))
|
|
comments = columns.MarkdownColumn()
|
|
tags = columns.TagColumn(url_name='plugins:netbox_rack_concept:rackconcept_list')
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = RackConcept
|
|
fields = (
|
|
'pk', 'id', 'name', 'status', 'tenant_group', 'tenant', 'rack_type', 'form_factor', 'width',
|
|
'u_height', 'starting_unit', 'desc_units', 'device_count', 'utilization', 'source_rack',
|
|
'description', 'comments', 'tags', 'created', 'last_updated',
|
|
)
|
|
default_columns = (
|
|
'name', 'status', 'tenant', 'u_height', 'width', 'device_count', 'utilization', 'description',
|
|
)
|
|
|
|
|
|
class ConceptDeviceTable(NetBoxTable):
|
|
name = tables.Column(linkify=True, empty_values=())
|
|
concept = tables.Column(linkify=True, verbose_name=_('Concept'))
|
|
status = columns.ChoiceFieldColumn()
|
|
device_type = tables.Column(linkify=True, verbose_name=_('Type'))
|
|
manufacturer = tables.Column(
|
|
accessor='device_type__manufacturer',
|
|
linkify=True,
|
|
verbose_name=_('Manufacturer')
|
|
)
|
|
role = columns.ColoredLabelColumn()
|
|
platform = tables.Column(linkify=True)
|
|
tenant = tables.Column(linkify=True)
|
|
position = tables.Column(verbose_name=_('Position (U)'))
|
|
# A plain column, not ChoiceFieldColumn: WidthFractionChoices carries no colours.
|
|
width_fraction = tables.Column(
|
|
accessor='get_width_fraction_display',
|
|
order_by='width_fraction',
|
|
verbose_name=_('Width')
|
|
)
|
|
source_device = tables.Column(linkify=True, verbose_name=_('Copied from'))
|
|
comments = columns.MarkdownColumn()
|
|
tags = columns.TagColumn(url_name='plugins:netbox_rack_concept:conceptdevice_list')
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = ConceptDevice
|
|
fields = (
|
|
'pk', 'id', 'name', 'label', 'concept', 'status', 'device_type', 'manufacturer', 'role', 'platform',
|
|
'tenant', 'position', 'face', 'width_fraction', 'horizontal_position', 'u_height', 'is_full_depth',
|
|
'serial', 'source_device', 'description', 'comments', 'tags', 'created', 'last_updated',
|
|
)
|
|
default_columns = (
|
|
'name', 'concept', 'status', 'device_type', 'role', 'position', 'face', 'width_fraction',
|
|
)
|
|
|
|
def render_name(self, record):
|
|
return record.display_label
|
|
|
|
|
|
class ConceptDeviceElevationTable(ConceptDeviceTable):
|
|
"""Device list shown on the concept detail page, without the redundant concept column."""
|
|
|
|
class Meta(ConceptDeviceTable.Meta):
|
|
default_columns = (
|
|
'name', 'status', 'device_type', 'role', 'position', 'face', 'width_fraction', 'horizontal_position',
|
|
)
|
|
|
|
|
|
class ConceptDeploymentTable(tables.Table):
|
|
rack_name = tables.Column(verbose_name=_('Rack'))
|
|
rack = tables.Column(linkify=True, verbose_name=_('Link'))
|
|
device_count = tables.Column(verbose_name=_('Devices'))
|
|
user = tables.Column(verbose_name=_('Deployed by'))
|
|
created = columns.DateTimeColumn(verbose_name=_('Deployed'))
|
|
|
|
class Meta:
|
|
model = ConceptDeployment
|
|
fields = ('rack_name', 'rack', 'device_count', 'user', 'created')
|
|
attrs = {'class': 'table table-hover object-list'}
|
|
empty_text = _('This concept has not been deployed yet.')
|
|
|
|
|
|
class ConceptComponentTable(NetBoxTable):
|
|
name = tables.Column(linkify=True)
|
|
device = tables.Column(linkify=True, verbose_name=_('Device'))
|
|
concept = tables.Column(accessor='device__concept', linkify=True, verbose_name=_('Concept'))
|
|
component_type = columns.ChoiceFieldColumn()
|
|
color = columns.ColorColumn()
|
|
connection = tables.TemplateColumn(
|
|
template_code="""
|
|
{% with peer=record.peer %}
|
|
{% if peer %}
|
|
<a href="{{ peer.device.get_absolute_url }}">{{ peer.device }}</a>
|
|
<i class="mdi mdi-chevron-right"></i>
|
|
<a href="{{ peer.get_absolute_url }}">{{ peer }}</a>
|
|
{% else %}
|
|
{{ ''|placeholder }}
|
|
{% endif %}
|
|
{% endwith %}
|
|
""",
|
|
verbose_name=_('Connection'),
|
|
orderable=False,
|
|
empty_values=()
|
|
)
|
|
connect = tables.TemplateColumn(
|
|
template_code="""
|
|
{% load i18n %}
|
|
{% if not record.is_connected %}
|
|
<a href="{% url 'plugins:netbox_rack_concept:conceptcable_add' %}?concept={{ record.device.concept_id }}&termination_a_device={{ record.device_id }}&termination_a={{ record.pk }}"
|
|
class="btn btn-sm btn-primary">{% trans "Connect" %}</a>
|
|
{% endif %}
|
|
""",
|
|
verbose_name='',
|
|
orderable=False
|
|
)
|
|
tags = columns.TagColumn(url_name='plugins:netbox_rack_concept:conceptcomponent_list')
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = ConceptComponent
|
|
fields = (
|
|
'pk', 'id', 'name', 'label', 'device', 'concept', 'component_type', 'port_type', 'positions', 'color',
|
|
'connection', 'connect', 'description', 'tags', 'created', 'last_updated',
|
|
)
|
|
default_columns = ('name', 'device', 'component_type', 'port_type', 'connection', 'connect')
|
|
|
|
|
|
class ConceptCableTable(NetBoxTable):
|
|
id = tables.Column(linkify=True, verbose_name=_('ID'))
|
|
label = tables.Column(linkify=True)
|
|
concept = tables.Column(accessor='termination_a__device__concept', linkify=True, verbose_name=_('Concept'))
|
|
status = columns.ChoiceFieldColumn()
|
|
type = columns.ChoiceFieldColumn()
|
|
color = columns.ColorColumn()
|
|
termination_a_device = tables.Column(
|
|
accessor='termination_a__device', linkify=True, verbose_name=_('Device A')
|
|
)
|
|
termination_a = tables.Column(linkify=True, verbose_name=_('Component A'))
|
|
termination_b_device = tables.Column(
|
|
accessor='termination_b__device', linkify=True, verbose_name=_('Device B')
|
|
)
|
|
termination_b = tables.Column(linkify=True, verbose_name=_('Component B'))
|
|
tags = columns.TagColumn(url_name='plugins:netbox_rack_concept:conceptcable_list')
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = ConceptCable
|
|
fields = (
|
|
'pk', 'id', 'label', 'concept', 'status', 'type', 'color', 'termination_a_device', 'termination_a',
|
|
'termination_b_device', 'termination_b', 'description', 'tags', 'created', 'last_updated',
|
|
)
|
|
default_columns = (
|
|
'id', 'concept', 'status', 'type', 'termination_a_device', 'termination_a', 'termination_b_device',
|
|
'termination_b',
|
|
)
|