tables.py 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. import django_tables2 as tables
  2. from django_tables2.utils import Accessor
  3. from tenancy.tables import COL_TENANT
  4. from utilities.tables import (
  5. BaseTable, BooleanColumn, ButtonsColumn, ColorColumn, ColoredLabelColumn, TagColumn, ToggleColumn,
  6. )
  7. from .models import (
  8. Cable, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
  9. DeviceBayTemplate, DeviceRole, DeviceType, FrontPort, FrontPortTemplate, Interface, InterfaceTemplate,
  10. InventoryItem, Manufacturer, Platform, PowerFeed, PowerOutlet, PowerOutletTemplate, PowerPanel, PowerPort,
  11. PowerPortTemplate, Rack, RackGroup, RackReservation, RackRole, RearPort, RearPortTemplate, Region, Site,
  12. VirtualChassis,
  13. )
  14. MPTT_LINK = """
  15. {% if record.get_children %}
  16. <span style="padding-left: {{ record.get_ancestors|length }}0px "><i class="fa fa-caret-right"></i>
  17. {% else %}
  18. <span style="padding-left: {{ record.get_ancestors|length }}9px">
  19. {% endif %}
  20. <a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
  21. </span>
  22. """
  23. SITE_REGION_LINK = """
  24. {% if record.region %}
  25. <a href="{% url 'dcim:site_list' %}?region={{ record.region.slug }}">{{ record.region }}</a>
  26. {% else %}
  27. &mdash;
  28. {% endif %}
  29. """
  30. COLOR_LABEL = """
  31. {% load helpers %}
  32. <label class="label" style="color: {{ record.color|fgcolor }}; background-color: #{{ record.color }}">{{ record }}</label>
  33. """
  34. DEVICE_LINK = """
  35. <a href="{% url 'dcim:device' pk=record.pk %}">
  36. {{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
  37. </a>
  38. """
  39. RACKGROUP_ELEVATIONS = """
  40. <a href="{% url 'dcim:rack_elevation_list' %}?site={{ record.site.slug }}&group_id={{ record.pk }}" class="btn btn-xs btn-primary" title="View elevations">
  41. <i class="fa fa-eye"></i>
  42. </a>
  43. """
  44. RACK_DEVICE_COUNT = """
  45. <a href="{% url 'dcim:device_list' %}?rack_id={{ record.pk }}">{{ value }}</a>
  46. """
  47. DEVICEROLE_DEVICE_COUNT = """
  48. <a href="{% url 'dcim:device_list' %}?role={{ record.slug }}">{{ value }}</a>
  49. """
  50. DEVICEROLE_VM_COUNT = """
  51. <a href="{% url 'virtualization:virtualmachine_list' %}?role={{ record.slug }}">{{ value }}</a>
  52. """
  53. PLATFORM_DEVICE_COUNT = """
  54. <a href="{% url 'dcim:device_list' %}?platform={{ record.slug }}">{{ value }}</a>
  55. """
  56. PLATFORM_VM_COUNT = """
  57. <a href="{% url 'virtualization:virtualmachine_list' %}?platform={{ record.slug }}">{{ value }}</a>
  58. """
  59. STATUS_LABEL = """
  60. <span class="label label-{{ record.get_status_class }}">{{ record.get_status_display }}</span>
  61. """
  62. TYPE_LABEL = """
  63. <span class="label label-{{ record.get_type_class }}">{{ record.get_type_display }}</span>
  64. """
  65. DEVICE_PRIMARY_IP = """
  66. {{ record.primary_ip6.address.ip|default:"" }}
  67. {% if record.primary_ip6 and record.primary_ip4 %}<br />{% endif %}
  68. {{ record.primary_ip4.address.ip|default:"" }}
  69. """
  70. DEVICETYPE_INSTANCES_TEMPLATE = """
  71. <a href="{% url 'dcim:device_list' %}?manufacturer_id={{ record.manufacturer_id }}&device_type_id={{ record.pk }}">{{ record.instance_count }}</a>
  72. """
  73. UTILIZATION_GRAPH = """
  74. {% load helpers %}
  75. {% utilization_graph value %}
  76. """
  77. CABLE_TERMINATION_PARENT = """
  78. {% if value.device %}
  79. <a href="{{ value.device.get_absolute_url }}">{{ value.device }}</a>
  80. {% elif value.circuit %}
  81. <a href="{{ value.circuit.get_absolute_url }}">{{ value.circuit }}</a>
  82. {% elif value.power_panel %}
  83. <a href="{{ value.power_panel.get_absolute_url }}">{{ value.power_panel }}</a>
  84. {% endif %}
  85. """
  86. CABLE_LENGTH = """
  87. {% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% else %}&mdash;{% endif %}
  88. """
  89. POWERPANEL_POWERFEED_COUNT = """
  90. <a href="{% url 'dcim:powerfeed_list' %}?power_panel_id={{ record.pk }}">{{ value }}</a>
  91. """
  92. #
  93. # Regions
  94. #
  95. class RegionTable(BaseTable):
  96. pk = ToggleColumn()
  97. name = tables.TemplateColumn(
  98. template_code=MPTT_LINK,
  99. orderable=False
  100. )
  101. site_count = tables.Column(
  102. verbose_name='Sites'
  103. )
  104. actions = ButtonsColumn(Region)
  105. class Meta(BaseTable.Meta):
  106. model = Region
  107. fields = ('pk', 'name', 'slug', 'site_count', 'description', 'actions')
  108. default_columns = ('pk', 'name', 'site_count', 'description', 'actions')
  109. #
  110. # Sites
  111. #
  112. class SiteTable(BaseTable):
  113. pk = ToggleColumn()
  114. name = tables.LinkColumn(
  115. order_by=('_name',)
  116. )
  117. status = tables.TemplateColumn(
  118. template_code=STATUS_LABEL
  119. )
  120. region = tables.TemplateColumn(
  121. template_code=SITE_REGION_LINK
  122. )
  123. tenant = tables.TemplateColumn(
  124. template_code=COL_TENANT
  125. )
  126. tags = TagColumn(
  127. url_name='dcim:site_list'
  128. )
  129. class Meta(BaseTable.Meta):
  130. model = Site
  131. fields = (
  132. 'pk', 'name', 'slug', 'status', 'facility', 'region', 'tenant', 'asn', 'time_zone', 'description',
  133. 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone',
  134. 'contact_email', 'tags',
  135. )
  136. default_columns = ('pk', 'name', 'status', 'facility', 'region', 'tenant', 'asn', 'description')
  137. #
  138. # Rack groups
  139. #
  140. class RackGroupTable(BaseTable):
  141. pk = ToggleColumn()
  142. name = tables.TemplateColumn(
  143. template_code=MPTT_LINK,
  144. orderable=False
  145. )
  146. site = tables.LinkColumn(
  147. viewname='dcim:site',
  148. args=[Accessor('site.slug')],
  149. verbose_name='Site'
  150. )
  151. rack_count = tables.Column(
  152. verbose_name='Racks'
  153. )
  154. actions = ButtonsColumn(
  155. model=RackGroup,
  156. prepend_template=RACKGROUP_ELEVATIONS
  157. )
  158. class Meta(BaseTable.Meta):
  159. model = RackGroup
  160. fields = ('pk', 'name', 'site', 'rack_count', 'description', 'slug', 'actions')
  161. default_columns = ('pk', 'name', 'site', 'rack_count', 'description', 'actions')
  162. #
  163. # Rack roles
  164. #
  165. class RackRoleTable(BaseTable):
  166. pk = ToggleColumn()
  167. rack_count = tables.Column(verbose_name='Racks')
  168. color = tables.TemplateColumn(COLOR_LABEL)
  169. actions = ButtonsColumn(RackRole)
  170. class Meta(BaseTable.Meta):
  171. model = RackRole
  172. fields = ('pk', 'name', 'rack_count', 'color', 'description', 'slug', 'actions')
  173. default_columns = ('pk', 'name', 'rack_count', 'color', 'description', 'actions')
  174. #
  175. # Racks
  176. #
  177. class RackTable(BaseTable):
  178. pk = ToggleColumn()
  179. name = tables.LinkColumn(
  180. order_by=('_name',)
  181. )
  182. site = tables.LinkColumn(
  183. viewname='dcim:site',
  184. args=[Accessor('site.slug')]
  185. )
  186. tenant = tables.TemplateColumn(
  187. template_code=COL_TENANT
  188. )
  189. status = tables.TemplateColumn(
  190. template_code=STATUS_LABEL
  191. )
  192. role = ColoredLabelColumn()
  193. u_height = tables.TemplateColumn(
  194. template_code="{{ record.u_height }}U",
  195. verbose_name='Height'
  196. )
  197. class Meta(BaseTable.Meta):
  198. model = Rack
  199. fields = (
  200. 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', 'type',
  201. 'width', 'u_height',
  202. )
  203. default_columns = ('pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'u_height')
  204. class RackDetailTable(RackTable):
  205. device_count = tables.TemplateColumn(
  206. template_code=RACK_DEVICE_COUNT,
  207. verbose_name='Devices'
  208. )
  209. get_utilization = tables.TemplateColumn(
  210. template_code=UTILIZATION_GRAPH,
  211. orderable=False,
  212. verbose_name='Space'
  213. )
  214. get_power_utilization = tables.TemplateColumn(
  215. template_code=UTILIZATION_GRAPH,
  216. orderable=False,
  217. verbose_name='Power'
  218. )
  219. tags = TagColumn(
  220. url_name='dcim:rack_list'
  221. )
  222. class Meta(RackTable.Meta):
  223. fields = (
  224. 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', 'type',
  225. 'width', 'u_height', 'device_count', 'get_utilization', 'get_power_utilization', 'tags',
  226. )
  227. default_columns = (
  228. 'pk', 'name', 'site', 'group', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count',
  229. 'get_utilization', 'get_power_utilization',
  230. )
  231. #
  232. # Rack reservations
  233. #
  234. class RackReservationTable(BaseTable):
  235. pk = ToggleColumn()
  236. reservation = tables.LinkColumn(
  237. viewname='dcim:rackreservation',
  238. args=[Accessor('pk')],
  239. accessor='pk'
  240. )
  241. site = tables.LinkColumn(
  242. viewname='dcim:site',
  243. accessor=Accessor('rack.site'),
  244. args=[Accessor('rack.site.slug')],
  245. )
  246. tenant = tables.TemplateColumn(
  247. template_code=COL_TENANT
  248. )
  249. rack = tables.LinkColumn(
  250. viewname='dcim:rack',
  251. args=[Accessor('rack.pk')]
  252. )
  253. unit_list = tables.Column(
  254. orderable=False,
  255. verbose_name='Units'
  256. )
  257. tags = TagColumn(
  258. url_name='dcim:rackreservation_list'
  259. )
  260. actions = ButtonsColumn(RackReservation)
  261. class Meta(BaseTable.Meta):
  262. model = RackReservation
  263. fields = (
  264. 'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'tags',
  265. 'actions',
  266. )
  267. default_columns = (
  268. 'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'description', 'actions',
  269. )
  270. #
  271. # Manufacturers
  272. #
  273. class ManufacturerTable(BaseTable):
  274. pk = ToggleColumn()
  275. name = tables.LinkColumn()
  276. devicetype_count = tables.Column(
  277. verbose_name='Device Types'
  278. )
  279. inventoryitem_count = tables.Column(
  280. verbose_name='Inventory Items'
  281. )
  282. platform_count = tables.Column(
  283. verbose_name='Platforms'
  284. )
  285. slug = tables.Column()
  286. actions = ButtonsColumn(Manufacturer, pk_field='slug')
  287. class Meta(BaseTable.Meta):
  288. model = Manufacturer
  289. fields = (
  290. 'pk', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'description', 'slug', 'actions',
  291. )
  292. #
  293. # Device types
  294. #
  295. class DeviceTypeTable(BaseTable):
  296. pk = ToggleColumn()
  297. model = tables.LinkColumn(
  298. viewname='dcim:devicetype',
  299. args=[Accessor('pk')],
  300. verbose_name='Device Type'
  301. )
  302. is_full_depth = BooleanColumn(
  303. verbose_name='Full Depth'
  304. )
  305. instance_count = tables.TemplateColumn(
  306. template_code=DEVICETYPE_INSTANCES_TEMPLATE,
  307. verbose_name='Instances'
  308. )
  309. tags = TagColumn(
  310. url_name='dcim:devicetype_list'
  311. )
  312. class Meta(BaseTable.Meta):
  313. model = DeviceType
  314. fields = (
  315. 'pk', 'model', 'manufacturer', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
  316. 'instance_count', 'tags',
  317. )
  318. default_columns = (
  319. 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count',
  320. )
  321. #
  322. # Device type components
  323. #
  324. class ComponentTemplateTable(BaseTable):
  325. pk = ToggleColumn()
  326. name = tables.Column(
  327. order_by=('_name',)
  328. )
  329. class ConsolePortTemplateTable(ComponentTemplateTable):
  330. actions = ButtonsColumn(
  331. model=ConsolePortTemplate,
  332. buttons=('edit', 'delete')
  333. )
  334. class Meta(BaseTable.Meta):
  335. model = ConsolePortTemplate
  336. fields = ('pk', 'name', 'label', 'type', 'description', 'actions')
  337. empty_text = "None"
  338. class ConsoleServerPortTemplateTable(ComponentTemplateTable):
  339. actions = ButtonsColumn(
  340. model=ConsoleServerPortTemplate,
  341. buttons=('edit', 'delete')
  342. )
  343. class Meta(BaseTable.Meta):
  344. model = ConsoleServerPortTemplate
  345. fields = ('pk', 'name', 'label', 'type', 'description', 'actions')
  346. empty_text = "None"
  347. class PowerPortTemplateTable(ComponentTemplateTable):
  348. actions = ButtonsColumn(
  349. model=PowerPortTemplate,
  350. buttons=('edit', 'delete')
  351. )
  352. class Meta(BaseTable.Meta):
  353. model = PowerPortTemplate
  354. fields = ('pk', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description', 'actions')
  355. empty_text = "None"
  356. class PowerOutletTemplateTable(ComponentTemplateTable):
  357. actions = ButtonsColumn(
  358. model=PowerOutletTemplate,
  359. buttons=('edit', 'delete')
  360. )
  361. class Meta(BaseTable.Meta):
  362. model = PowerOutletTemplate
  363. fields = ('pk', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description', 'actions')
  364. empty_text = "None"
  365. class InterfaceTemplateTable(ComponentTemplateTable):
  366. mgmt_only = BooleanColumn(
  367. verbose_name='Management Only'
  368. )
  369. actions = ButtonsColumn(
  370. model=InterfaceTemplate,
  371. buttons=('edit', 'delete')
  372. )
  373. class Meta(BaseTable.Meta):
  374. model = InterfaceTemplate
  375. fields = ('pk', 'name', 'label', 'mgmt_only', 'type', 'description', 'actions')
  376. empty_text = "None"
  377. class FrontPortTemplateTable(ComponentTemplateTable):
  378. rear_port_position = tables.Column(
  379. verbose_name='Position'
  380. )
  381. actions = ButtonsColumn(
  382. model=FrontPortTemplate,
  383. buttons=('edit', 'delete')
  384. )
  385. class Meta(BaseTable.Meta):
  386. model = FrontPortTemplate
  387. fields = ('pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'actions')
  388. empty_text = "None"
  389. class RearPortTemplateTable(ComponentTemplateTable):
  390. actions = ButtonsColumn(
  391. model=RearPortTemplate,
  392. buttons=('edit', 'delete')
  393. )
  394. class Meta(BaseTable.Meta):
  395. model = RearPortTemplate
  396. fields = ('pk', 'name', 'label', 'type', 'positions', 'description', 'actions')
  397. empty_text = "None"
  398. class DeviceBayTemplateTable(ComponentTemplateTable):
  399. actions = ButtonsColumn(
  400. model=DeviceBayTemplate,
  401. buttons=('edit', 'delete')
  402. )
  403. class Meta(BaseTable.Meta):
  404. model = DeviceBayTemplate
  405. fields = ('pk', 'name', 'label', 'description', 'actions')
  406. empty_text = "None"
  407. #
  408. # Device roles
  409. #
  410. class DeviceRoleTable(BaseTable):
  411. pk = ToggleColumn()
  412. device_count = tables.TemplateColumn(
  413. template_code=DEVICEROLE_DEVICE_COUNT,
  414. accessor=Accessor('devices.count'),
  415. orderable=False,
  416. verbose_name='Devices'
  417. )
  418. vm_count = tables.TemplateColumn(
  419. template_code=DEVICEROLE_VM_COUNT,
  420. accessor=Accessor('virtual_machines.count'),
  421. orderable=False,
  422. verbose_name='VMs'
  423. )
  424. color = tables.TemplateColumn(
  425. template_code=COLOR_LABEL,
  426. verbose_name='Label'
  427. )
  428. vm_role = BooleanColumn()
  429. actions = ButtonsColumn(DeviceRole, pk_field='slug')
  430. class Meta(BaseTable.Meta):
  431. model = DeviceRole
  432. fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'actions')
  433. default_columns = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'actions')
  434. #
  435. # Platforms
  436. #
  437. class PlatformTable(BaseTable):
  438. pk = ToggleColumn()
  439. device_count = tables.TemplateColumn(
  440. template_code=PLATFORM_DEVICE_COUNT,
  441. accessor=Accessor('devices.count'),
  442. orderable=False,
  443. verbose_name='Devices'
  444. )
  445. vm_count = tables.TemplateColumn(
  446. template_code=PLATFORM_VM_COUNT,
  447. accessor=Accessor('virtual_machines.count'),
  448. orderable=False,
  449. verbose_name='VMs'
  450. )
  451. actions = ButtonsColumn(Platform, pk_field='slug')
  452. class Meta(BaseTable.Meta):
  453. model = Platform
  454. fields = (
  455. 'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'napalm_args',
  456. 'description', 'actions',
  457. )
  458. default_columns = (
  459. 'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'napalm_driver', 'description', 'actions',
  460. )
  461. #
  462. # Devices
  463. #
  464. class DeviceTable(BaseTable):
  465. pk = ToggleColumn()
  466. name = tables.TemplateColumn(
  467. order_by=('_name',),
  468. template_code=DEVICE_LINK
  469. )
  470. status = tables.TemplateColumn(
  471. template_code=STATUS_LABEL
  472. )
  473. tenant = tables.TemplateColumn(
  474. template_code=COL_TENANT
  475. )
  476. site = tables.LinkColumn(
  477. viewname='dcim:site',
  478. args=[Accessor('site.slug')]
  479. )
  480. rack = tables.LinkColumn(
  481. viewname='dcim:rack',
  482. args=[Accessor('rack.pk')]
  483. )
  484. device_role = ColoredLabelColumn(
  485. verbose_name='Role'
  486. )
  487. device_type = tables.LinkColumn(
  488. viewname='dcim:devicetype',
  489. args=[Accessor('device_type.pk')],
  490. verbose_name='Type',
  491. text=lambda record: record.device_type.display_name
  492. )
  493. primary_ip = tables.TemplateColumn(
  494. template_code=DEVICE_PRIMARY_IP,
  495. orderable=False,
  496. verbose_name='IP Address'
  497. )
  498. primary_ip4 = tables.LinkColumn(
  499. viewname='ipam:ipaddress',
  500. args=[Accessor('primary_ip4.pk')],
  501. verbose_name='IPv4 Address'
  502. )
  503. primary_ip6 = tables.LinkColumn(
  504. viewname='ipam:ipaddress',
  505. args=[Accessor('primary_ip6.pk')],
  506. verbose_name='IPv6 Address'
  507. )
  508. cluster = tables.LinkColumn(
  509. viewname='virtualization:cluster',
  510. args=[Accessor('cluster.pk')]
  511. )
  512. virtual_chassis = tables.LinkColumn(
  513. viewname='dcim:virtualchassis',
  514. args=[Accessor('virtual_chassis.pk')]
  515. )
  516. vc_position = tables.Column(
  517. verbose_name='VC Position'
  518. )
  519. vc_priority = tables.Column(
  520. verbose_name='VC Priority'
  521. )
  522. tags = TagColumn(
  523. url_name='dcim:device_list'
  524. )
  525. class Meta(BaseTable.Meta):
  526. model = Device
  527. fields = (
  528. 'pk', 'name', 'status', 'tenant', 'device_role', 'device_type', 'platform', 'serial', 'asset_tag', 'site',
  529. 'rack', 'position', 'face', 'primary_ip', 'primary_ip4', 'primary_ip6', 'cluster', 'virtual_chassis',
  530. 'vc_position', 'vc_priority', 'tags',
  531. )
  532. default_columns = (
  533. 'pk', 'name', 'status', 'tenant', 'site', 'rack', 'device_role', 'device_type', 'primary_ip',
  534. )
  535. class DeviceImportTable(BaseTable):
  536. name = tables.TemplateColumn(
  537. template_code=DEVICE_LINK
  538. )
  539. status = tables.TemplateColumn(
  540. template_code=STATUS_LABEL
  541. )
  542. tenant = tables.TemplateColumn(
  543. template_code=COL_TENANT
  544. )
  545. site = tables.LinkColumn(
  546. viewname='dcim:site',
  547. args=[Accessor('site.slug')]
  548. )
  549. rack = tables.LinkColumn(
  550. viewname='dcim:rack',
  551. args=[Accessor('rack.pk')]
  552. )
  553. device_role = tables.Column(
  554. verbose_name='Role'
  555. )
  556. device_type = tables.Column(
  557. verbose_name='Type'
  558. )
  559. class Meta(BaseTable.Meta):
  560. model = Device
  561. fields = ('name', 'status', 'tenant', 'site', 'rack', 'position', 'device_role', 'device_type')
  562. empty_text = False
  563. #
  564. # Device components
  565. #
  566. class DeviceComponentTable(BaseTable):
  567. pk = ToggleColumn()
  568. device = tables.Column(
  569. linkify=True
  570. )
  571. name = tables.Column(
  572. linkify=True,
  573. order_by=('_name',)
  574. )
  575. cable = tables.Column(
  576. linkify=True
  577. )
  578. class Meta(BaseTable.Meta):
  579. order_by = ('device', 'name')
  580. class ConsolePortTable(DeviceComponentTable):
  581. class Meta(DeviceComponentTable.Meta):
  582. model = ConsolePort
  583. fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable')
  584. default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
  585. class ConsoleServerPortTable(DeviceComponentTable):
  586. class Meta(DeviceComponentTable.Meta):
  587. model = ConsoleServerPort
  588. fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'cable')
  589. default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
  590. class PowerPortTable(DeviceComponentTable):
  591. class Meta(DeviceComponentTable.Meta):
  592. model = PowerPort
  593. fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'maximum_draw', 'allocated_draw', 'cable')
  594. default_columns = ('pk', 'device', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description')
  595. class PowerOutletTable(DeviceComponentTable):
  596. class Meta(DeviceComponentTable.Meta):
  597. model = PowerOutlet
  598. fields = ('pk', 'device', 'name', 'label', 'type', 'description', 'power_port', 'feed_leg', 'cable')
  599. default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
  600. class InterfaceTable(DeviceComponentTable):
  601. enabled = BooleanColumn()
  602. class Meta(DeviceComponentTable.Meta):
  603. model = Interface
  604. fields = (
  605. 'pk', 'device', 'name', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'description', 'cable',
  606. )
  607. default_columns = ('pk', 'device', 'name', 'label', 'enabled', 'type', 'description')
  608. class FrontPortTable(DeviceComponentTable):
  609. rear_port_position = tables.Column(
  610. verbose_name='Position'
  611. )
  612. class Meta(DeviceComponentTable.Meta):
  613. model = FrontPort
  614. fields = ('pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable')
  615. default_columns = ('pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description')
  616. class RearPortTable(DeviceComponentTable):
  617. class Meta(DeviceComponentTable.Meta):
  618. model = RearPort
  619. fields = ('pk', 'device', 'name', 'label', 'type', 'positions', 'description', 'cable')
  620. default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
  621. class DeviceBayTable(DeviceComponentTable):
  622. installed_device = tables.Column(
  623. linkify=True
  624. )
  625. class Meta(DeviceComponentTable.Meta):
  626. model = DeviceBay
  627. fields = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
  628. default_columns = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
  629. class InventoryItemTable(DeviceComponentTable):
  630. manufacturer = tables.Column(
  631. linkify=True
  632. )
  633. discovered = BooleanColumn()
  634. class Meta(DeviceComponentTable.Meta):
  635. model = InventoryItem
  636. fields = (
  637. 'pk', 'device', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description',
  638. 'discovered',
  639. )
  640. default_columns = ('pk', 'device', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag')
  641. #
  642. # Cables
  643. #
  644. class CableTable(BaseTable):
  645. pk = ToggleColumn()
  646. id = tables.LinkColumn(
  647. viewname='dcim:cable',
  648. args=[Accessor('pk')],
  649. verbose_name='ID'
  650. )
  651. termination_a_parent = tables.TemplateColumn(
  652. template_code=CABLE_TERMINATION_PARENT,
  653. accessor=Accessor('termination_a'),
  654. orderable=False,
  655. verbose_name='Side A'
  656. )
  657. termination_a = tables.LinkColumn(
  658. accessor=Accessor('termination_a'),
  659. orderable=False,
  660. verbose_name='Termination A'
  661. )
  662. termination_b_parent = tables.TemplateColumn(
  663. template_code=CABLE_TERMINATION_PARENT,
  664. accessor=Accessor('termination_b'),
  665. orderable=False,
  666. verbose_name='Side B'
  667. )
  668. termination_b = tables.LinkColumn(
  669. accessor=Accessor('termination_b'),
  670. orderable=False,
  671. verbose_name='Termination B'
  672. )
  673. status = tables.TemplateColumn(
  674. template_code=STATUS_LABEL
  675. )
  676. length = tables.TemplateColumn(
  677. template_code=CABLE_LENGTH,
  678. order_by='_abs_length'
  679. )
  680. color = ColorColumn()
  681. tags = TagColumn(
  682. url_name='dcim:cable_list'
  683. )
  684. class Meta(BaseTable.Meta):
  685. model = Cable
  686. fields = (
  687. 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
  688. 'status', 'type', 'color', 'length', 'tags',
  689. )
  690. default_columns = (
  691. 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b',
  692. 'status', 'type',
  693. )
  694. #
  695. # Device connections
  696. #
  697. class ConsoleConnectionTable(BaseTable):
  698. console_server = tables.LinkColumn(
  699. viewname='dcim:device',
  700. accessor=Accessor('connected_endpoint.device'),
  701. args=[Accessor('connected_endpoint.device.pk')],
  702. verbose_name='Console Server'
  703. )
  704. connected_endpoint = tables.Column(
  705. verbose_name='Port'
  706. )
  707. device = tables.LinkColumn(
  708. viewname='dcim:device',
  709. args=[Accessor('device.pk')]
  710. )
  711. name = tables.Column(
  712. verbose_name='Console Port'
  713. )
  714. class Meta(BaseTable.Meta):
  715. model = ConsolePort
  716. fields = ('console_server', 'connected_endpoint', 'device', 'name', 'connection_status')
  717. class PowerConnectionTable(BaseTable):
  718. pdu = tables.LinkColumn(
  719. viewname='dcim:device',
  720. accessor=Accessor('connected_endpoint.device'),
  721. args=[Accessor('connected_endpoint.device.pk')],
  722. order_by='_connected_poweroutlet__device',
  723. verbose_name='PDU'
  724. )
  725. outlet = tables.Column(
  726. accessor=Accessor('_connected_poweroutlet'),
  727. verbose_name='Outlet'
  728. )
  729. device = tables.LinkColumn(
  730. viewname='dcim:device',
  731. args=[Accessor('device.pk')]
  732. )
  733. name = tables.Column(
  734. verbose_name='Power Port'
  735. )
  736. class Meta(BaseTable.Meta):
  737. model = PowerPort
  738. fields = ('pdu', 'outlet', 'device', 'name', 'connection_status')
  739. class InterfaceConnectionTable(BaseTable):
  740. device_a = tables.LinkColumn(
  741. viewname='dcim:device',
  742. accessor=Accessor('device'),
  743. args=[Accessor('device.pk')],
  744. verbose_name='Device A'
  745. )
  746. interface_a = tables.LinkColumn(
  747. viewname='dcim:interface',
  748. accessor=Accessor('name'),
  749. args=[Accessor('pk')],
  750. verbose_name='Interface A'
  751. )
  752. device_b = tables.LinkColumn(
  753. viewname='dcim:device',
  754. accessor=Accessor('_connected_interface.device'),
  755. args=[Accessor('_connected_interface.device.pk')],
  756. verbose_name='Device B'
  757. )
  758. interface_b = tables.LinkColumn(
  759. viewname='dcim:interface',
  760. accessor=Accessor('_connected_interface'),
  761. args=[Accessor('_connected_interface.pk')],
  762. verbose_name='Interface B'
  763. )
  764. class Meta(BaseTable.Meta):
  765. model = Interface
  766. fields = (
  767. 'device_a', 'interface_a', 'device_b', 'interface_b', 'connection_status',
  768. )
  769. #
  770. # Virtual chassis
  771. #
  772. class VirtualChassisTable(BaseTable):
  773. pk = ToggleColumn()
  774. name = tables.Column(
  775. linkify=True
  776. )
  777. master = tables.Column(
  778. linkify=True
  779. )
  780. member_count = tables.Column(
  781. verbose_name='Members'
  782. )
  783. tags = TagColumn(
  784. url_name='dcim:virtualchassis_list'
  785. )
  786. class Meta(BaseTable.Meta):
  787. model = VirtualChassis
  788. fields = ('pk', 'name', 'domain', 'master', 'member_count', 'tags')
  789. default_columns = ('pk', 'name', 'domain', 'master', 'member_count')
  790. #
  791. # Power panels
  792. #
  793. class PowerPanelTable(BaseTable):
  794. pk = ToggleColumn()
  795. name = tables.LinkColumn()
  796. site = tables.LinkColumn(
  797. viewname='dcim:site',
  798. args=[Accessor('site.slug')]
  799. )
  800. powerfeed_count = tables.TemplateColumn(
  801. template_code=POWERPANEL_POWERFEED_COUNT,
  802. verbose_name='Feeds'
  803. )
  804. tags = TagColumn(
  805. url_name='dcim:powerpanel_list'
  806. )
  807. class Meta(BaseTable.Meta):
  808. model = PowerPanel
  809. fields = ('pk', 'name', 'site', 'rack_group', 'powerfeed_count', 'tags')
  810. default_columns = ('pk', 'name', 'site', 'rack_group', 'powerfeed_count')
  811. #
  812. # Power feeds
  813. #
  814. class PowerFeedTable(BaseTable):
  815. pk = ToggleColumn()
  816. name = tables.LinkColumn()
  817. power_panel = tables.LinkColumn(
  818. viewname='dcim:powerpanel',
  819. args=[Accessor('power_panel.pk')],
  820. )
  821. rack = tables.LinkColumn(
  822. viewname='dcim:rack',
  823. args=[Accessor('rack.pk')]
  824. )
  825. status = tables.TemplateColumn(
  826. template_code=STATUS_LABEL
  827. )
  828. type = tables.TemplateColumn(
  829. template_code=TYPE_LABEL
  830. )
  831. max_utilization = tables.TemplateColumn(
  832. template_code="{{ value }}%"
  833. )
  834. available_power = tables.Column(
  835. verbose_name='Available power (VA)'
  836. )
  837. tags = TagColumn(
  838. url_name='dcim:powerfeed_list'
  839. )
  840. class Meta(BaseTable.Meta):
  841. model = PowerFeed
  842. fields = (
  843. 'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
  844. 'max_utilization', 'available_power', 'tags',
  845. )
  846. default_columns = (
  847. 'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
  848. )