Coverage for dcim/tables/cooling.py: 100%
87 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1import django_tables2 as tables
2from django.utils.translation import gettext_lazy as _
3from django_tables2.utils import Accessor
5from dcim import models
6from dcim.models import CoolingFeed, CoolingSource
7from netbox.tables import PrimaryModelTable, columns
8from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
10from .devices import DeviceComponentTable, ModularDeviceComponentTable
11from .devicetypes import ComponentTemplateTable
12from .template_code import DIAMETER, MAX_FLOW, MODULAR_COMPONENT_TEMPLATE_BUTTONS
14__all__ = (
15 'CoolingFeedTable',
16 'CoolingIntakeTable',
17 'CoolingIntakeTemplateTable',
18 'CoolingOutflowTable',
19 'CoolingOutflowTemplateTable',
20 'CoolingSourceTable',
21 'DeviceCoolingIntakeTable',
22 'DeviceCoolingOutflowTable',
23)
26#
27# Cooling sources
28#
30class CoolingSourceTable(ContactsColumnMixin, PrimaryModelTable):
31 name = tables.Column(
32 verbose_name=_('Name'),
33 linkify=True
34 )
35 site = tables.Column(
36 verbose_name=_('Site'),
37 linkify=True
38 )
39 location = tables.Column(
40 verbose_name=_('Location'),
41 linkify=True
42 )
43 status = columns.ChoiceFieldColumn(
44 verbose_name=_('Status'),
45 )
46 type = columns.ChoiceFieldColumn(
47 verbose_name=_('Type'),
48 )
49 fluid_type = columns.ChoiceFieldColumn(
50 verbose_name=_('Fluid Type'),
51 )
52 cooling_capacity = tables.Column(
53 verbose_name=_('Cooling Capacity (kW)')
54 )
55 coolingfeed_count = columns.LinkedCountColumn(
56 viewname='dcim:coolingfeed_list',
57 url_params={'cooling_source_id': 'pk'},
58 verbose_name=_('Cooling Feeds')
59 )
60 tags = columns.TagColumn(
61 url_name='dcim:coolingsource_list'
62 )
64 class Meta(PrimaryModelTable.Meta):
65 model = CoolingSource
66 fields = (
67 'pk', 'id', 'name', 'site', 'location', 'type', 'status', 'fluid_type', 'cooling_capacity',
68 'coolingfeed_count', 'contacts', 'description', 'comments', 'tags', 'created', 'last_updated',
69 )
70 default_columns = (
71 'pk', 'name', 'site', 'location', 'type', 'status', 'cooling_capacity', 'coolingfeed_count',
72 )
75#
76# Cooling feeds
77#
79class CoolingFeedTable(TenancyColumnsMixin, PrimaryModelTable):
80 name = tables.Column(
81 verbose_name=_('Name'),
82 linkify=True
83 )
84 cooling_source = tables.Column(
85 verbose_name=_('Cooling Source'),
86 linkify=True
87 )
88 rack = tables.Column(
89 verbose_name=_('Rack'),
90 linkify=True
91 )
92 status = columns.ChoiceFieldColumn(
93 verbose_name=_('Status'),
94 )
95 cooling_capacity = tables.Column(
96 verbose_name=_('Cooling Capacity (kW)')
97 )
98 max_flow = columns.TemplateColumn(
99 verbose_name=_('Max Flow'),
100 template_code=MAX_FLOW,
101 order_by=('_abs_max_flow',),
102 )
103 tenant = tables.Column(
104 linkify=True,
105 verbose_name=_('Tenant')
106 )
107 site = tables.Column(
108 accessor='rack__site',
109 linkify=True,
110 verbose_name=_('Site'),
111 )
112 tags = columns.TagColumn(
113 url_name='dcim:coolingfeed_list'
114 )
116 class Meta(PrimaryModelTable.Meta):
117 model = CoolingFeed
118 fields = (
119 'pk', 'id', 'name', 'cooling_source', 'site', 'rack', 'status', 'cooling_capacity', 'max_flow', 'tenant',
120 'tenant_group', 'description', 'comments', 'tags', 'created', 'last_updated',
121 )
122 default_columns = (
123 'pk', 'name', 'cooling_source', 'rack', 'status', 'cooling_capacity',
124 'max_flow',
125 )
128#
129# Cooling ports
130#
132class CoolingIntakeTable(ModularDeviceComponentTable):
133 device = tables.Column(
134 verbose_name=_('Device'),
135 linkify={
136 'viewname': 'dcim:device_coolingintakes',
137 'args': [Accessor('device_id')],
138 }
139 )
140 type = columns.ChoiceFieldColumn(
141 verbose_name=_('Type'),
142 )
143 diameter = columns.TemplateColumn(
144 verbose_name=_('Diameter'),
145 template_code=DIAMETER,
146 order_by=('_abs_diameter', 'diameter_unit')
147 )
148 max_flow = columns.TemplateColumn(
149 verbose_name=_('Max Flow'),
150 template_code=MAX_FLOW,
151 order_by=('_abs_max_flow',),
152 )
153 cooling_outflow = tables.Column(
154 verbose_name=_('Cooling Outflow'),
155 linkify=True
156 )
157 tags = columns.TagColumn(
158 url_name='dcim:coolingintake_list'
159 )
161 class Meta(DeviceComponentTable.Meta):
162 model = models.CoolingIntake
163 fields = (
164 'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'type', 'diameter', 'description',
165 'max_flow', 'cooling_outflow', 'inventory_items', 'tags', 'created', 'last_updated',
166 )
167 default_columns = (
168 'pk', 'name', 'device', 'label', 'type', 'diameter', 'max_flow',
169 'cooling_outflow', 'description',
170 )
173#
174# Cooling outlets
175#
177class CoolingOutflowTable(ModularDeviceComponentTable):
178 device = tables.Column(
179 verbose_name=_('Device'),
180 linkify={
181 'viewname': 'dcim:device_coolingoutflows',
182 'args': [Accessor('device_id')],
183 }
184 )
185 type = columns.ChoiceFieldColumn(
186 verbose_name=_('Type'),
187 )
188 diameter = columns.TemplateColumn(
189 verbose_name=_('Diameter'),
190 template_code=DIAMETER,
191 order_by=('_abs_diameter', 'diameter_unit')
192 )
193 cooling_intake = tables.Column(
194 verbose_name=_('Cooling Intake'),
195 linkify=True
196 )
197 tags = columns.TagColumn(
198 url_name='dcim:coolingoutflow_list'
199 )
201 class Meta(DeviceComponentTable.Meta):
202 model = models.CoolingOutflow
203 fields = (
204 'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'type', 'diameter',
205 'description', 'cooling_intake', 'inventory_items', 'tags', 'created', 'last_updated',
206 )
207 default_columns = (
208 'pk', 'name', 'device', 'label', 'type', 'diameter', 'cooling_intake',
209 'description',
210 )
213#
214# Cooling port templates
215#
217class CoolingIntakeTemplateTable(ComponentTemplateTable):
218 diameter = columns.TemplateColumn(
219 verbose_name=_('Diameter'),
220 template_code=DIAMETER,
221 order_by=('_abs_diameter', 'diameter_unit')
222 )
223 max_flow = columns.TemplateColumn(
224 verbose_name=_('Max Flow'),
225 template_code=MAX_FLOW,
226 order_by=('_abs_max_flow',),
227 )
228 actions = columns.ActionsColumn(
229 actions=('edit', 'delete'),
230 extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
231 )
233 class Meta(ComponentTemplateTable.Meta):
234 model = models.CoolingIntakeTemplate
235 fields = (
236 'pk', 'name', 'label', 'type', 'diameter', 'max_flow', 'description', 'actions',
237 )
238 empty_text = "None"
241#
242# Cooling outlet templates
243#
245class CoolingOutflowTemplateTable(ComponentTemplateTable):
246 diameter = columns.TemplateColumn(
247 verbose_name=_('Diameter'),
248 template_code=DIAMETER,
249 order_by=('_abs_diameter', 'diameter_unit')
250 )
251 actions = columns.ActionsColumn(
252 actions=('edit', 'delete'),
253 extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
254 )
256 class Meta(ComponentTemplateTable.Meta):
257 model = models.CoolingOutflowTemplate
258 fields = (
259 'pk', 'name', 'label', 'type', 'diameter', 'cooling_intake', 'description',
260 'actions',
261 )
262 empty_text = "None"
265#
266# Device cooling components
267#
269class DeviceCoolingIntakeTable(CoolingIntakeTable):
270 name = tables.TemplateColumn(
271 verbose_name=_('Name'),
272 template_code='<i class="mdi mdi-snowflake"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
273 attrs={'td': {'class': 'text-nowrap'}}
274 )
276 class Meta(DeviceComponentTable.Meta):
277 model = models.CoolingIntake
278 fields = (
279 'pk', 'id', 'name', 'module_bay', 'module', 'label', 'type', 'diameter', 'max_flow',
280 'description', 'cooling_outflow', 'tags', 'actions',
281 )
282 default_columns = (
283 'pk', 'name', 'label', 'type', 'diameter', 'max_flow',
284 'cooling_outflow', 'description',
285 )
288class DeviceCoolingOutflowTable(CoolingOutflowTable):
289 name = tables.TemplateColumn(
290 verbose_name=_('Name'),
291 template_code='<i class="mdi mdi-snowflake"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
292 attrs={'td': {'class': 'text-nowrap'}}
293 )
295 class Meta(DeviceComponentTable.Meta):
296 model = models.CoolingOutflow
297 fields = (
298 'pk', 'id', 'name', 'module_bay', 'module', 'label', 'type', 'diameter',
299 'cooling_intake', 'description', 'tags', 'actions',
300 )
301 default_columns = (
302 'pk', 'name', 'label', 'type', 'diameter', 'cooling_intake', 'description',
303 )