2023-08-01 01:35:28 +07:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-10-16 10:39:13 -04:00
|
|
|
import django_tables2 as tables
|
|
|
|
from django_tables2.utils import Accessor
|
|
|
|
|
2021-04-08 10:08:50 -04:00
|
|
|
from dcim.models import Rack, RackReservation, RackRole
|
2022-01-27 15:48:05 -05:00
|
|
|
from netbox.tables import NetBoxTable, columns
|
2022-10-20 16:07:03 -04:00
|
|
|
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
2022-12-09 12:45:02 -05:00
|
|
|
from .template_code import WEIGHT
|
2020-10-16 10:39:13 -04:00
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'RackTable',
|
|
|
|
'RackReservationTable',
|
|
|
|
'RackRoleTable',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Rack roles
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class RackRoleTable(NetBoxTable):
|
2023-08-01 01:35:28 +07:00
|
|
|
name = tables.Column(
|
|
|
|
verbose_name=_('Name'),
|
|
|
|
linkify=True
|
|
|
|
)
|
2023-01-25 16:20:52 -05:00
|
|
|
rack_count = columns.LinkedCountColumn(
|
|
|
|
viewname='dcim:rack_list',
|
|
|
|
url_params={'role_id': 'pk'},
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Racks')
|
|
|
|
)
|
|
|
|
color = columns.ColorColumn(
|
|
|
|
verbose_name=_('Color'),
|
2023-01-25 16:20:52 -05:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='dcim:rackrole_list'
|
|
|
|
)
|
2020-10-16 10:39:13 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-10-16 10:39:13 -04:00
|
|
|
model = RackRole
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'id', 'name', 'rack_count', 'color', 'description', 'slug', 'tags', 'actions', 'created',
|
|
|
|
'last_updated',
|
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'rack_count', 'color', 'description')
|
2020-10-16 10:39:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Racks
|
|
|
|
#
|
|
|
|
|
2022-10-18 13:47:14 -07:00
|
|
|
class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
2020-11-05 15:33:07 -05:00
|
|
|
name = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Name'),
|
2020-11-05 15:33:07 -05:00
|
|
|
order_by=('_name',),
|
|
|
|
linkify=True
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2021-04-07 15:40:03 -04:00
|
|
|
location = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Location'),
|
2020-11-05 15:33:07 -05:00
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
site = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Site'),
|
2020-11-05 15:33:07 -05:00
|
|
|
linkify=True
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2023-08-01 01:35:28 +07:00
|
|
|
status = columns.ChoiceFieldColumn(
|
|
|
|
verbose_name=_('Status'),
|
|
|
|
)
|
|
|
|
role = columns.ColoredLabelColumn(
|
|
|
|
verbose_name=_('Role'),
|
|
|
|
)
|
2020-10-16 10:39:13 -04:00
|
|
|
u_height = tables.TemplateColumn(
|
2022-08-30 09:53:38 -04:00
|
|
|
template_code="{{ value }}U",
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Height')
|
|
|
|
)
|
|
|
|
comments = columns.MarkdownColumn(
|
|
|
|
verbose_name=_('Comments'),
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
device_count = columns.LinkedCountColumn(
|
2020-10-16 10:39:13 -04:00
|
|
|
viewname='dcim:device_list',
|
|
|
|
url_params={'rack_id': 'pk'},
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Devices')
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
get_utilization = columns.UtilizationColumn(
|
2021-04-23 09:44:29 -04:00
|
|
|
orderable=False,
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Space')
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
get_power_utilization = columns.UtilizationColumn(
|
2020-10-16 10:39:13 -04:00
|
|
|
orderable=False,
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Power')
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2020-10-16 10:39:13 -04:00
|
|
|
url_name='dcim:rack_list'
|
|
|
|
)
|
2021-11-08 14:15:26 +01:00
|
|
|
outer_width = tables.TemplateColumn(
|
|
|
|
template_code="{{ record.outer_width }} {{ record.outer_unit }}",
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Outer Width')
|
2021-11-08 14:15:26 +01:00
|
|
|
)
|
|
|
|
outer_depth = tables.TemplateColumn(
|
|
|
|
template_code="{{ record.outer_depth }} {{ record.outer_unit }}",
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Outer Depth')
|
2021-11-08 14:15:26 +01:00
|
|
|
)
|
2022-09-30 13:31:04 -07:00
|
|
|
weight = columns.TemplateColumn(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Weight'),
|
2022-12-09 12:45:02 -05:00
|
|
|
template_code=WEIGHT,
|
2022-09-30 13:31:04 -07:00
|
|
|
order_by=('_abs_weight', 'weight_unit')
|
|
|
|
)
|
2022-12-09 12:45:02 -05:00
|
|
|
max_weight = columns.TemplateColumn(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Max Weight'),
|
2022-12-09 12:45:02 -05:00
|
|
|
template_code=WEIGHT,
|
|
|
|
order_by=('_abs_max_weight', 'weight_unit')
|
|
|
|
)
|
2020-10-16 10:39:13 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2021-09-17 13:55:32 -04:00
|
|
|
model = Rack
|
2020-10-16 10:39:13 -04:00
|
|
|
fields = (
|
2022-09-30 13:31:04 -07:00
|
|
|
'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'tenant_group', 'role', 'serial',
|
2023-08-02 10:47:16 -04:00
|
|
|
'asset_tag', 'type', 'u_height', 'starting_unit', 'width', 'outer_width', 'outer_depth', 'mounting_depth',
|
|
|
|
'weight', 'max_weight', 'comments', 'device_count', 'get_utilization', 'get_power_utilization',
|
|
|
|
'description', 'contacts', 'tags', 'created', 'last_updated',
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
|
|
|
default_columns = (
|
2021-04-07 15:40:03 -04:00
|
|
|
'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count',
|
2021-12-30 12:02:20 -05:00
|
|
|
'get_utilization',
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Rack reservations
|
|
|
|
#
|
|
|
|
|
2022-07-10 15:13:48 +02:00
|
|
|
class RackReservationTable(TenancyColumnsMixin, NetBoxTable):
|
2020-10-16 10:39:13 -04:00
|
|
|
reservation = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Reservation'),
|
2020-10-16 10:39:13 -04:00
|
|
|
accessor='pk',
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
site = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Site'),
|
2020-10-16 10:39:13 -04:00
|
|
|
accessor=Accessor('rack__site'),
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-08-01 08:01:18 -05:00
|
|
|
location = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Location'),
|
2022-08-01 08:01:18 -05:00
|
|
|
accessor=Accessor('rack__location'),
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-10-16 10:39:13 -04:00
|
|
|
rack = tables.Column(
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Rack'),
|
2020-10-16 10:39:13 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
unit_list = tables.Column(
|
|
|
|
orderable=False,
|
2023-08-01 01:35:28 +07:00
|
|
|
verbose_name=_('Units')
|
|
|
|
)
|
|
|
|
comments = columns.MarkdownColumn(
|
|
|
|
verbose_name=_('Comments'),
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2020-10-16 10:39:13 -04:00
|
|
|
url_name='dcim:rackreservation_list'
|
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-10-16 10:39:13 -04:00
|
|
|
model = RackReservation
|
|
|
|
fields = (
|
2022-11-04 08:28:09 -04:00
|
|
|
'pk', 'id', 'reservation', 'site', 'location', 'rack', 'unit_list', 'user', 'created', 'tenant',
|
|
|
|
'tenant_group', 'description', 'comments', 'tags', 'actions', 'created', 'last_updated',
|
2020-10-16 10:39:13 -04:00
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'description')
|