1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Files
netbox-community-netbox/netbox/dcim/tables/devices.py

798 lines
25 KiB
Python
Raw Normal View History

2020-10-16 10:39:13 -04:00
import django_tables2 as tables
from django_tables2.utils import Accessor
from dcim.models import (
ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceRole, FrontPort, Interface, InventoryItem, Platform,
PowerOutlet, PowerPort, RearPort, VirtualChassis,
)
from tenancy.tables import TenantColumn
2020-10-16 10:39:13 -04:00
from utilities.tables import (
BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn,
MarkdownColumn, TagColumn, TemplateColumn, ToggleColumn,
2020-10-16 10:39:13 -04:00
)
from .template_code import *
2020-10-16 10:39:13 -04:00
__all__ = (
2021-09-17 15:37:19 -04:00
'BaseInterfaceTable',
2021-11-03 10:29:02 -04:00
'CableTerminationTable',
2020-10-16 10:39:13 -04:00
'ConsolePortTable',
'ConsoleServerPortTable',
'DeviceBayTable',
'DeviceConsolePortTable',
'DeviceConsoleServerPortTable',
'DeviceDeviceBayTable',
'DeviceFrontPortTable',
2020-10-16 10:39:13 -04:00
'DeviceImportTable',
'DeviceInterfaceTable',
'DeviceInventoryItemTable',
'DevicePowerPortTable',
'DevicePowerOutletTable',
'DeviceRearPortTable',
2020-10-16 10:39:13 -04:00
'DeviceRoleTable',
'DeviceTable',
2020-10-16 10:39:13 -04:00
'FrontPortTable',
'InterfaceTable',
'InventoryItemTable',
'PlatformTable',
'PowerOutletTable',
'PowerPortTable',
'RearPortTable',
'VirtualChassisTable',
)
def get_cabletermination_row_class(record):
if record.mark_connected:
return 'success'
elif record.cable:
return record.cable.get_status_class()
return ''
def get_interface_row_class(record):
if not record.enabled:
return 'danger'
elif record.is_virtual:
return 'primary'
return get_cabletermination_row_class(record)
def get_interface_state_attribute(record):
"""
Get interface enabled state as string to attach to <tr/> DOM element.
"""
if record.enabled:
return "enabled"
else:
return "disabled"
2020-10-16 10:39:13 -04:00
#
# Device roles
#
2020-10-16 10:39:13 -04:00
class DeviceRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(
linkify=True
)
2020-10-16 10:39:13 -04:00
device_count = LinkedCountColumn(
viewname='dcim:device_list',
url_params={'role_id': 'pk'},
2020-10-16 10:39:13 -04:00
verbose_name='Devices'
)
vm_count = LinkedCountColumn(
viewname='virtualization:virtualmachine_list',
url_params={'role_id': 'pk'},
2020-10-16 10:39:13 -04:00
verbose_name='VMs'
)
color = ColorColumn()
vm_role = BooleanColumn()
tags = TagColumn(
url_name='dcim:devicerole_list'
)
actions = ButtonsColumn(DeviceRole)
2020-10-16 10:39:13 -04:00
class Meta(BaseTable.Meta):
model = DeviceRole
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'tags',
'actions', 'created', 'last_updated',
)
2020-10-16 10:39:13 -04:00
default_columns = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'actions')
#
# Platforms
#
class PlatformTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(
linkify=True
)
2020-10-16 10:39:13 -04:00
device_count = LinkedCountColumn(
viewname='dcim:device_list',
url_params={'platform_id': 'pk'},
2020-10-16 10:39:13 -04:00
verbose_name='Devices'
)
vm_count = LinkedCountColumn(
viewname='virtualization:virtualmachine_list',
url_params={'platform_id': 'pk'},
2020-10-16 10:39:13 -04:00
verbose_name='VMs'
)
tags = TagColumn(
url_name='dcim:platform_list'
)
actions = ButtonsColumn(Platform)
2020-10-16 10:39:13 -04:00
class Meta(BaseTable.Meta):
model = Platform
fields = (
'pk', 'id', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'napalm_args',
'description', 'tags', 'actions', 'created', 'last_updated',
2020-10-16 10:39:13 -04:00
)
default_columns = (
'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'napalm_driver', 'description', 'actions',
)
#
# Devices
#
class DeviceTable(BaseTable):
pk = ToggleColumn()
name = tables.TemplateColumn(
order_by=('_name',),
template_code=DEVICE_LINK
)
status = ChoiceFieldColumn()
tenant = TenantColumn()
2020-10-16 10:39:13 -04:00
site = tables.Column(
linkify=True
)
location = tables.Column(
linkify=True
)
2020-10-16 10:39:13 -04:00
rack = tables.Column(
linkify=True
)
device_role = ColoredLabelColumn(
verbose_name='Role'
)
2021-04-02 17:02:12 -04:00
manufacturer = tables.Column(
accessor=Accessor('device_type__manufacturer'),
linkify=True
)
device_type = tables.Column(
linkify=True,
verbose_name='Type'
2020-10-16 10:39:13 -04:00
)
2021-10-25 14:42:20 -04:00
primary_ip = tables.Column(
linkify=True,
order_by=('primary_ip4', 'primary_ip6'),
verbose_name='IP Address'
)
2020-10-16 10:39:13 -04:00
primary_ip4 = tables.Column(
linkify=True,
verbose_name='IPv4 Address'
)
primary_ip6 = tables.Column(
linkify=True,
verbose_name='IPv6 Address'
)
cluster = tables.Column(
linkify=True
2020-10-16 10:39:13 -04:00
)
virtual_chassis = tables.Column(
linkify=True
2020-10-16 10:39:13 -04:00
)
vc_position = tables.Column(
verbose_name='VC Position'
)
vc_priority = tables.Column(
verbose_name='VC Priority'
)
comments = MarkdownColumn()
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:device_list'
)
class Meta(BaseTable.Meta):
model = Device
fields = (
'pk', 'id', 'name', 'status', 'tenant', 'device_role', 'manufacturer', 'device_type', 'platform', 'serial',
2021-11-03 10:29:02 -04:00
'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'primary_ip', 'airflow', 'primary_ip4',
'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'tags', 'created',
'last_updated',
2020-10-16 10:39:13 -04:00
)
default_columns = (
2021-04-02 17:02:12 -04:00
'pk', 'name', 'status', 'tenant', 'site', 'location', 'rack', 'device_role', 'manufacturer', 'device_type',
'primary_ip',
2020-10-16 10:39:13 -04:00
)
class DeviceImportTable(BaseTable):
name = tables.TemplateColumn(
template_code=DEVICE_LINK
)
status = ChoiceFieldColumn()
tenant = TenantColumn()
2020-10-16 10:39:13 -04:00
site = tables.Column(
linkify=True
)
rack = tables.Column(
linkify=True
)
device_role = tables.Column(
verbose_name='Role'
)
device_type = tables.Column(
verbose_name='Type'
)
class Meta(BaseTable.Meta):
model = Device
fields = ('id', 'name', 'status', 'tenant', 'site', 'rack', 'position', 'device_role', 'device_type')
2020-10-16 10:39:13 -04:00
empty_text = False
#
# Device components
#
class DeviceComponentTable(BaseTable):
pk = ToggleColumn()
device = tables.Column(
linkify=True
)
name = tables.Column(
linkify=True,
order_by=('_name',)
)
class Meta(BaseTable.Meta):
order_by = ('device', 'name')
class CableTerminationTable(BaseTable):
cable = tables.Column(
linkify=True
)
cable_color = ColorColumn(
accessor='cable__color',
orderable=False,
verbose_name='Cable Color'
)
2021-10-13 14:04:53 -04:00
link_peer = TemplateColumn(
accessor='_link_peer',
template_code=LINKTERMINATION,
2020-10-30 13:57:17 -04:00
orderable=False,
2021-10-13 14:04:53 -04:00
verbose_name='Link Peer'
)
mark_connected = BooleanColumn()
class PathEndpointTable(CableTerminationTable):
connection = TemplateColumn(
accessor='_path__last_node',
2021-10-13 14:04:53 -04:00
template_code=LINKTERMINATION,
verbose_name='Connection',
orderable=False
)
class ConsolePortTable(DeviceComponentTable, PathEndpointTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_consoleports',
'args': [Accessor('device_id')],
}
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:consoleport_list'
)
class Meta(DeviceComponentTable.Meta):
model = ConsolePort
fields = (
'pk', 'id', 'name', 'device', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable', 'cable_color',
'link_peer', 'connection', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'device', 'label', 'type', 'speed', 'description')
2020-10-16 10:39:13 -04:00
class DeviceConsolePortTable(ConsolePortTable):
name = tables.TemplateColumn(
2020-11-13 13:14:10 -05:00
template_code='<i class="mdi mdi-console"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=ConsolePort,
buttons=('edit', 'delete'),
prepend_template=CONSOLEPORT_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = ConsolePort
fields = (
'pk', 'id', 'name', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable', 'cable_color',
2021-10-13 14:04:53 -04:00
'link_peer', 'connection', 'tags', 'actions'
)
default_columns = ('pk', 'name', 'label', 'type', 'speed', 'description', 'cable', 'connection', 'actions')
row_attrs = {
'class': get_cabletermination_row_class
}
class ConsoleServerPortTable(DeviceComponentTable, PathEndpointTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_consoleserverports',
'args': [Accessor('device_id')],
}
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:consoleserverport_list'
)
class Meta(DeviceComponentTable.Meta):
model = ConsoleServerPort
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'device', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable',
'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'device', 'label', 'type', 'speed', 'description')
2020-10-16 10:39:13 -04:00
class DeviceConsoleServerPortTable(ConsoleServerPortTable):
name = tables.TemplateColumn(
2020-11-13 13:14:10 -05:00
template_code='<i class="mdi mdi-console-network-outline"></i> '
'<a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=ConsoleServerPort,
buttons=('edit', 'delete'),
prepend_template=CONSOLESERVERPORT_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = ConsoleServerPort
fields = (
'pk', 'id', 'name', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable', 'cable_color',
2021-10-13 14:04:53 -04:00
'link_peer', 'connection', 'tags', 'actions',
)
default_columns = ('pk', 'name', 'label', 'type', 'speed', 'description', 'cable', 'connection', 'actions')
row_attrs = {
'class': get_cabletermination_row_class
}
class PowerPortTable(DeviceComponentTable, PathEndpointTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_powerports',
'args': [Accessor('device_id')],
}
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:powerport_list'
)
class Meta(DeviceComponentTable.Meta):
model = PowerPort
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'device', 'label', 'type', 'description', 'mark_connected', 'maximum_draw',
'allocated_draw', 'cable', 'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated',
2020-10-16 10:39:13 -04:00
)
default_columns = ('pk', 'name', 'device', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description')
2020-10-16 10:39:13 -04:00
class DevicePowerPortTable(PowerPortTable):
name = tables.TemplateColumn(
2020-11-13 13:14:10 -05:00
template_code='<i class="mdi mdi-power-plug-outline"></i> <a href="{{ record.get_absolute_url }}">'
'{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=PowerPort,
buttons=('edit', 'delete'),
prepend_template=POWERPORT_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = PowerPort
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description', 'mark_connected',
'cable', 'cable_color', 'link_peer', 'connection', 'tags', 'actions',
)
default_columns = (
'pk', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description', 'cable', 'connection',
'actions',
)
row_attrs = {
'class': get_cabletermination_row_class
}
class PowerOutletTable(DeviceComponentTable, PathEndpointTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_poweroutlets',
'args': [Accessor('device_id')],
}
)
2020-10-16 16:33:08 -04:00
power_port = tables.Column(
linkify=True
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:poweroutlet_list'
)
class Meta(DeviceComponentTable.Meta):
model = PowerOutlet
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'device', 'label', 'type', 'description', 'power_port', 'feed_leg', 'mark_connected',
'cable', 'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'device', 'label', 'type', 'power_port', 'feed_leg', 'description')
2020-10-16 10:39:13 -04:00
class DevicePowerOutletTable(PowerOutletTable):
name = tables.TemplateColumn(
2020-11-13 13:14:10 -05:00
template_code='<i class="mdi mdi-power-socket"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=PowerOutlet,
buttons=('edit', 'delete'),
prepend_template=POWEROUTLET_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = PowerOutlet
fields = (
'pk', 'id', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description', 'mark_connected', 'cable',
2021-10-13 14:04:53 -04:00
'cable_color', 'link_peer', 'connection', 'tags', 'actions',
)
default_columns = (
'pk', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description', 'cable', 'connection', 'actions',
)
row_attrs = {
'class': get_cabletermination_row_class
}
2020-10-16 10:39:13 -04:00
class BaseInterfaceTable(BaseTable):
enabled = BooleanColumn()
ip_addresses = tables.TemplateColumn(
template_code=INTERFACE_IPADDRESSES,
orderable=False,
verbose_name='IP Addresses'
)
fhrp_groups = tables.TemplateColumn(
accessor=Accessor('fhrp_group_assignments'),
template_code=INTERFACE_FHRPGROUPS,
orderable=False,
verbose_name='FHRP Groups'
)
2020-10-16 10:39:13 -04:00
untagged_vlan = tables.Column(linkify=True)
tagged_vlans = TemplateColumn(
2020-10-16 10:39:13 -04:00
template_code=INTERFACE_TAGGED_VLANS,
orderable=False,
verbose_name='Tagged VLANs'
)
class InterfaceTable(DeviceComponentTable, BaseInterfaceTable, PathEndpointTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_interfaces',
'args': [Accessor('device_id')],
}
)
mgmt_only = BooleanColumn()
2021-10-13 14:04:53 -04:00
wireless_link = tables.Column(
linkify=True
)
wireless_lans = TemplateColumn(
template_code=INTERFACE_WIRELESS_LANS,
orderable=False,
verbose_name='Wireless LANs'
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:interface_list'
)
class Meta(DeviceComponentTable.Meta):
model = Interface
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'device', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'mac_address', 'wwn',
'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'description',
'mark_connected', 'cable', 'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection',
'tags', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated',
2020-10-16 10:39:13 -04:00
)
default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
2020-10-16 10:39:13 -04:00
class DeviceInterfaceTable(InterfaceTable):
name = tables.TemplateColumn(
template_code='<i class="mdi mdi-{% if record.mgmt_only %}wrench{% elif record.is_lag %}reorder-horizontal'
2021-10-15 12:24:07 -04:00
'{% elif record.is_virtual %}circle{% elif record.is_wireless %}wifi{% else %}ethernet'
2020-11-13 13:14:10 -05:00
'{% endif %}"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
2021-03-05 13:49:41 -05:00
parent = tables.Column(
linkify=True
)
bridge = tables.Column(
linkify=True
2021-03-05 13:49:41 -05:00
)
2020-10-16 16:33:08 -04:00
lag = tables.Column(
linkify=True,
verbose_name='LAG'
)
actions = ButtonsColumn(
model=Interface,
buttons=('edit', 'delete'),
prepend_template=INTERFACE_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = Interface
fields = (
2021-11-03 10:29:02 -04:00
'pk', 'id', 'name', 'label', 'enabled', 'type', 'parent', 'bridge', 'lag', 'mgmt_only', 'mtu', 'mode',
'mac_address', 'wwn', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power',
'description', 'mark_connected', 'cable', 'cable_color', 'wireless_link', 'wireless_lans', 'link_peer',
'connection', 'tags', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'actions',
)
order_by = ('name',)
default_columns = (
2021-03-05 13:49:41 -05:00
'pk', 'name', 'label', 'enabled', 'type', 'parent', 'lag', 'mtu', 'mode', 'description', 'ip_addresses',
'cable', 'connection', 'actions',
)
row_attrs = {
'class': get_interface_row_class,
'data-name': lambda record: record.name,
'data-enabled': get_interface_state_attribute,
}
class FrontPortTable(DeviceComponentTable, CableTerminationTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_frontports',
'args': [Accessor('device_id')],
}
)
color = ColorColumn()
2020-10-16 10:39:13 -04:00
rear_port_position = tables.Column(
verbose_name='Position'
)
2020-10-16 16:33:08 -04:00
rear_port = tables.Column(
linkify=True
)
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:frontport_list'
)
class Meta(DeviceComponentTable.Meta):
model = FrontPort
fields = (
'pk', 'id', 'name', 'device', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description',
'mark_connected', 'cable', 'cable_color', 'link_peer', 'tags', 'created', 'last_updated',
)
default_columns = (
'pk', 'name', 'device', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description',
2020-10-16 10:39:13 -04:00
)
class DeviceFrontPortTable(FrontPortTable):
name = tables.TemplateColumn(
2020-11-06 15:06:45 -05:00
template_code='<i class="mdi mdi-square-rounded{% if not record.cable %}-outline{% endif %}"></i> '
2020-11-13 13:14:10 -05:00
'<a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=FrontPort,
buttons=('edit', 'delete'),
prepend_template=FRONTPORT_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = FrontPort
fields = (
'pk', 'id', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'mark_connected', 'cable',
2021-10-13 14:04:53 -04:00
'cable_color', 'link_peer', 'tags', 'actions',
)
default_columns = (
2021-10-13 14:04:53 -04:00
'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'link_peer',
'actions',
)
row_attrs = {
'class': get_cabletermination_row_class
}
class RearPortTable(DeviceComponentTable, CableTerminationTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_rearports',
'args': [Accessor('device_id')],
}
)
color = ColorColumn()
2020-10-16 10:39:13 -04:00
tags = TagColumn(
url_name='dcim:rearport_list'
)
class Meta(DeviceComponentTable.Meta):
model = RearPort
fields = (
'pk', 'id', 'name', 'device', 'label', 'type', 'color', 'positions', 'description', 'mark_connected', 'cable',
'cable_color', 'link_peer', 'tags', 'created', 'last_updated',
)
default_columns = ('pk', 'name', 'device', 'label', 'type', 'color', 'description')
2020-10-16 10:39:13 -04:00
class DeviceRearPortTable(RearPortTable):
name = tables.TemplateColumn(
2020-11-16 13:17:43 -05:00
template_code='<i class="mdi mdi-square-rounded{% if not record.cable %}-outline{% endif %}"></i> '
2020-11-13 13:14:10 -05:00
'<a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=RearPort,
buttons=('edit', 'delete'),
prepend_template=REARPORT_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = RearPort
fields = (
'pk', 'id', 'name', 'label', 'type', 'positions', 'description', 'mark_connected', 'cable', 'cable_color',
2021-10-13 14:04:53 -04:00
'link_peer', 'tags', 'actions',
)
default_columns = (
2021-10-13 14:04:53 -04:00
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'link_peer', 'actions',
)
row_attrs = {
'class': get_cabletermination_row_class
}
2020-10-16 10:39:13 -04:00
class DeviceBayTable(DeviceComponentTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_devicebays',
'args': [Accessor('device_id')],
}
)
2020-10-16 16:33:08 -04:00
status = tables.TemplateColumn(
2021-11-11 14:05:39 +01:00
template_code=DEVICEBAY_STATUS,
order_by=Accessor('installed_device__status')
2020-10-16 16:33:08 -04:00
)
2020-10-16 10:39:13 -04:00
installed_device = tables.Column(
linkify=True
)
tags = TagColumn(
url_name='dcim:devicebay_list'
)
class Meta(DeviceComponentTable.Meta):
model = DeviceBay
fields = (
'pk', 'id', 'name', 'device', 'label', 'status', 'installed_device', 'description', 'tags',
'created', 'last_updated',
)
default_columns = ('pk', 'name', 'device', 'label', 'status', 'installed_device', 'description')
2020-10-16 10:39:13 -04:00
class DeviceDeviceBayTable(DeviceBayTable):
name = tables.TemplateColumn(
2020-11-06 15:06:45 -05:00
template_code='<i class="mdi mdi-circle{% if record.installed_device %}slice-8{% else %}outline{% endif %}'
2020-11-13 13:14:10 -05:00
'"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=DeviceBay,
buttons=('edit', 'delete'),
prepend_template=DEVICEBAY_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = DeviceBay
fields = (
'pk', 'id', 'name', 'label', 'status', 'installed_device', 'description', 'tags', 'actions',
)
default_columns = (
2020-10-16 16:33:08 -04:00
'pk', 'name', 'label', 'status', 'installed_device', 'description', 'actions',
)
2020-10-16 10:39:13 -04:00
class InventoryItemTable(DeviceComponentTable):
device = tables.Column(
linkify={
'viewname': 'dcim:device_inventory',
'args': [Accessor('device_id')],
}
)
2020-10-16 10:39:13 -04:00
manufacturer = tables.Column(
linkify=True
)
discovered = BooleanColumn()
tags = TagColumn(
url_name='dcim:inventoryitem_list'
)
cable = None # Override DeviceComponentTable
class Meta(BaseTable.Meta):
2020-10-16 10:39:13 -04:00
model = InventoryItem
fields = (
'pk', 'id', 'name', 'device', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description',
'discovered', 'tags', 'created', 'last_updated',
2020-10-16 10:39:13 -04:00
)
default_columns = ('pk', 'name', 'device', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag')
2020-10-16 10:39:13 -04:00
class DeviceInventoryItemTable(InventoryItemTable):
name = tables.TemplateColumn(
template_code='<a href="{{ record.get_absolute_url }}" style="padding-left: {{ record.level }}0px">'
2020-11-13 13:14:10 -05:00
'{{ value }}</a>',
order_by=Accessor('_name'),
2020-11-13 13:14:10 -05:00
attrs={'td': {'class': 'text-nowrap'}}
)
actions = ButtonsColumn(
model=InventoryItem,
buttons=('edit', 'delete')
)
class Meta(BaseTable.Meta):
model = InventoryItem
fields = (
'pk', 'id', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', 'discovered',
2020-10-16 16:33:08 -04:00
'tags', 'actions',
)
default_columns = (
'pk', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', 'discovered',
'actions',
)
2020-10-16 10:39:13 -04:00
#
# Virtual chassis
#
class VirtualChassisTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(
linkify=True
)
master = tables.Column(
linkify=True
)
member_count = LinkedCountColumn(
viewname='dcim:device_list',
url_params={'virtual_chassis_id': 'pk'},
verbose_name='Members'
)
tags = TagColumn(
url_name='dcim:virtualchassis_list'
)
class Meta(BaseTable.Meta):
model = VirtualChassis
fields = ('pk', 'id', 'name', 'domain', 'master', 'member_count', 'tags', 'created', 'last_updated',)
2020-10-16 10:39:13 -04:00
default_columns = ('pk', 'name', 'domain', 'master', 'member_count')