mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Optimize console/power/interface connection lists
This commit is contained in:
parent
5737f6fca0
commit
f8800b8303
@ -67,8 +67,8 @@ INTERFACE_TAGGED_VLANS = """
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CONNECTION_STATUS = """
|
PATH_STATUS = """
|
||||||
<span class="label label-{% if record.connection_status %}success{% else %}danger{% endif %}">{{ record.get_connection_status_display }}</span>
|
<span class="label label-{% if value %}success{% else %}danger{% endif %}">{% if value %}Connected{% else %}Not Connected{% endif %}</span>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -813,13 +813,13 @@ class CableTable(BaseTable):
|
|||||||
|
|
||||||
class ConsoleConnectionTable(BaseTable):
|
class ConsoleConnectionTable(BaseTable):
|
||||||
console_server = tables.Column(
|
console_server = tables.Column(
|
||||||
accessor=Accessor('path__destination__device'),
|
accessor=Accessor('_path__destination__device'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Console Server'
|
verbose_name='Console Server'
|
||||||
)
|
)
|
||||||
console_server_port = tables.Column(
|
console_server_port = tables.Column(
|
||||||
accessor=Accessor('path__destination'),
|
accessor=Accessor('_path__destination'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Port'
|
verbose_name='Port'
|
||||||
@ -831,27 +831,28 @@ class ConsoleConnectionTable(BaseTable):
|
|||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Console Port'
|
verbose_name='Console Port'
|
||||||
)
|
)
|
||||||
connection_status = tables.TemplateColumn(
|
path_status = tables.TemplateColumn(
|
||||||
accessor=Accessor('path__is_connected'),
|
accessor=Accessor('_path__is_connected'),
|
||||||
orderable=False,
|
template_code=PATH_STATUS,
|
||||||
template_code=CONNECTION_STATUS,
|
verbose_name='Path Status'
|
||||||
verbose_name='Status'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_prefetch = False
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = ConsolePort
|
model = ConsolePort
|
||||||
fields = ('console_server', 'console_server_port', 'device', 'name', 'connection_status')
|
fields = ('console_server', 'console_server_port', 'device', 'name', 'path_status')
|
||||||
|
|
||||||
|
|
||||||
class PowerConnectionTable(BaseTable):
|
class PowerConnectionTable(BaseTable):
|
||||||
pdu = tables.Column(
|
pdu = tables.Column(
|
||||||
accessor=Accessor('path__destination__device'),
|
accessor=Accessor('_path__destination__device'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='PDU'
|
verbose_name='PDU'
|
||||||
)
|
)
|
||||||
outlet = tables.Column(
|
outlet = tables.Column(
|
||||||
accessor=Accessor('path__destination'),
|
accessor=Accessor('_path__destination'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Outlet'
|
verbose_name='Outlet'
|
||||||
@ -863,16 +864,17 @@ class PowerConnectionTable(BaseTable):
|
|||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Power Port'
|
verbose_name='Power Port'
|
||||||
)
|
)
|
||||||
connection_status = tables.TemplateColumn(
|
path_status = tables.TemplateColumn(
|
||||||
accessor=Accessor('path__is_connected'),
|
accessor=Accessor('_path__is_connected'),
|
||||||
orderable=False,
|
template_code=PATH_STATUS,
|
||||||
template_code=CONNECTION_STATUS,
|
verbose_name='Path Status'
|
||||||
verbose_name='Status'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_prefetch = False
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = PowerPort
|
model = PowerPort
|
||||||
fields = ('pdu', 'outlet', 'device', 'name', 'connection_status')
|
fields = ('pdu', 'outlet', 'device', 'name', 'path_status')
|
||||||
|
|
||||||
|
|
||||||
class InterfaceConnectionTable(BaseTable):
|
class InterfaceConnectionTable(BaseTable):
|
||||||
@ -887,29 +889,28 @@ class InterfaceConnectionTable(BaseTable):
|
|||||||
verbose_name='Interface A'
|
verbose_name='Interface A'
|
||||||
)
|
)
|
||||||
device_b = tables.Column(
|
device_b = tables.Column(
|
||||||
accessor=Accessor('path__destination__device'),
|
accessor=Accessor('_path__destination__device'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Device B'
|
verbose_name='Device B'
|
||||||
)
|
)
|
||||||
interface_b = tables.Column(
|
interface_b = tables.Column(
|
||||||
accessor=Accessor('path__destination'),
|
accessor=Accessor('_path__destination'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Interface B'
|
verbose_name='Interface B'
|
||||||
)
|
)
|
||||||
connection_status = tables.TemplateColumn(
|
path_status = tables.TemplateColumn(
|
||||||
accessor=Accessor('path__is_connected'),
|
accessor=Accessor('_path__is_connected'),
|
||||||
orderable=False,
|
template_code=PATH_STATUS,
|
||||||
template_code=CONNECTION_STATUS,
|
verbose_name='Path Status'
|
||||||
verbose_name='Status'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_prefetch = False
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = Interface
|
model = Interface
|
||||||
fields = (
|
fields = ('device_a', 'interface_a', 'device_b', 'interface_b', 'path_status')
|
||||||
'device_a', 'interface_a', 'device_b', 'interface_b', 'connection_status',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -2079,12 +2079,8 @@ class CableBulkDeleteView(BulkDeleteView):
|
|||||||
|
|
||||||
class ConsoleConnectionsListView(ObjectListView):
|
class ConsoleConnectionsListView(ObjectListView):
|
||||||
queryset = ConsolePort.objects.prefetch_related(
|
queryset = ConsolePort.objects.prefetch_related(
|
||||||
'device', 'connected_endpoint__device'
|
'device', '_path__destination__device'
|
||||||
).filter(
|
).filter(_path__isnull=False).order_by('device')
|
||||||
connected_endpoint__isnull=False
|
|
||||||
).order_by(
|
|
||||||
'cable', 'connected_endpoint__device__name', 'connected_endpoint__name'
|
|
||||||
)
|
|
||||||
filterset = filters.ConsoleConnectionFilterSet
|
filterset = filters.ConsoleConnectionFilterSet
|
||||||
filterset_form = forms.ConsoleConnectionFilterForm
|
filterset_form = forms.ConsoleConnectionFilterForm
|
||||||
table = tables.ConsoleConnectionTable
|
table = tables.ConsoleConnectionTable
|
||||||
@ -2097,11 +2093,11 @@ class ConsoleConnectionsListView(ObjectListView):
|
|||||||
]
|
]
|
||||||
for obj in self.queryset:
|
for obj in self.queryset:
|
||||||
csv = csv_format([
|
csv = csv_format([
|
||||||
obj.connected_endpoint.device.identifier if obj.connected_endpoint else None,
|
obj._path.destination.device.identifier if obj._path.destination else None,
|
||||||
obj.connected_endpoint.name if obj.connected_endpoint else None,
|
obj._path.destination.name if obj._path.destination else None,
|
||||||
obj.device.identifier,
|
obj.device.identifier,
|
||||||
obj.name,
|
obj.name,
|
||||||
obj.get_connection_status_display(),
|
'Connected' if obj._path.is_connected else 'Not Connected',
|
||||||
])
|
])
|
||||||
csv_data.append(csv)
|
csv_data.append(csv)
|
||||||
|
|
||||||
@ -2110,12 +2106,8 @@ class ConsoleConnectionsListView(ObjectListView):
|
|||||||
|
|
||||||
class PowerConnectionsListView(ObjectListView):
|
class PowerConnectionsListView(ObjectListView):
|
||||||
queryset = PowerPort.objects.prefetch_related(
|
queryset = PowerPort.objects.prefetch_related(
|
||||||
'device', '_connected_poweroutlet__device'
|
'device', '_path__destination__device'
|
||||||
).filter(
|
).filter(_path__isnull=False).order_by('device')
|
||||||
_connected_poweroutlet__isnull=False
|
|
||||||
).order_by(
|
|
||||||
'cable', '_connected_poweroutlet__device__name', '_connected_poweroutlet__name'
|
|
||||||
)
|
|
||||||
filterset = filters.PowerConnectionFilterSet
|
filterset = filters.PowerConnectionFilterSet
|
||||||
filterset_form = forms.PowerConnectionFilterForm
|
filterset_form = forms.PowerConnectionFilterForm
|
||||||
table = tables.PowerConnectionTable
|
table = tables.PowerConnectionTable
|
||||||
@ -2128,11 +2120,11 @@ class PowerConnectionsListView(ObjectListView):
|
|||||||
]
|
]
|
||||||
for obj in self.queryset:
|
for obj in self.queryset:
|
||||||
csv = csv_format([
|
csv = csv_format([
|
||||||
obj.connected_endpoint.device.identifier if obj.connected_endpoint else None,
|
obj._path.destination.device.identifier if obj._path.destination else None,
|
||||||
obj.connected_endpoint.name if obj.connected_endpoint else None,
|
obj._path.destination.name if obj._path.destination else None,
|
||||||
obj.device.identifier,
|
obj.device.identifier,
|
||||||
obj.name,
|
obj.name,
|
||||||
obj.get_connection_status_display(),
|
'Connected' if obj._path.is_connected else 'Not Connected',
|
||||||
])
|
])
|
||||||
csv_data.append(csv)
|
csv_data.append(csv)
|
||||||
|
|
||||||
@ -2141,14 +2133,12 @@ class PowerConnectionsListView(ObjectListView):
|
|||||||
|
|
||||||
class InterfaceConnectionsListView(ObjectListView):
|
class InterfaceConnectionsListView(ObjectListView):
|
||||||
queryset = Interface.objects.prefetch_related(
|
queryset = Interface.objects.prefetch_related(
|
||||||
'device', 'cable', '_connected_interface__device'
|
'device', '_path__destination__device'
|
||||||
).filter(
|
).filter(
|
||||||
# Avoid duplicate connections by only selecting the lower PK in a connected pair
|
# Avoid duplicate connections by only selecting the lower PK in a connected pair
|
||||||
_connected_interface__isnull=False,
|
_path__isnull=False,
|
||||||
pk__lt=F('_connected_interface')
|
pk__lt=F('_connected_interface')
|
||||||
).order_by(
|
).order_by('device')
|
||||||
'device'
|
|
||||||
)
|
|
||||||
filterset = filters.InterfaceConnectionFilterSet
|
filterset = filters.InterfaceConnectionFilterSet
|
||||||
filterset_form = forms.InterfaceConnectionFilterForm
|
filterset_form = forms.InterfaceConnectionFilterForm
|
||||||
table = tables.InterfaceConnectionTable
|
table = tables.InterfaceConnectionTable
|
||||||
@ -2163,11 +2153,11 @@ class InterfaceConnectionsListView(ObjectListView):
|
|||||||
]
|
]
|
||||||
for obj in self.queryset:
|
for obj in self.queryset:
|
||||||
csv = csv_format([
|
csv = csv_format([
|
||||||
obj.connected_endpoint.device.identifier if obj.connected_endpoint else None,
|
obj._path.destination.device.identifier if obj._path.destination else None,
|
||||||
obj.connected_endpoint.name if obj.connected_endpoint else None,
|
obj._path.destination.name if obj._path.destination else None,
|
||||||
obj.device.identifier,
|
obj.device.identifier,
|
||||||
obj.name,
|
obj.name,
|
||||||
obj.get_connection_status_display(),
|
'Connected' if obj._path.is_connected else 'Not Connected',
|
||||||
])
|
])
|
||||||
csv_data.append(csv)
|
csv_data.append(csv)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user