devicetypes.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import django_tables2 as tables
  2. from dcim import models
  3. from netbox.tables import NetBoxTable, columns
  4. from tenancy.tables import ContactsColumnMixin
  5. from .template_code import MODULAR_COMPONENT_TEMPLATE_BUTTONS, WEIGHT
  6. __all__ = (
  7. 'ConsolePortTemplateTable',
  8. 'ConsoleServerPortTemplateTable',
  9. 'DeviceBayTemplateTable',
  10. 'DeviceTypeTable',
  11. 'FrontPortTemplateTable',
  12. 'InterfaceTemplateTable',
  13. 'InventoryItemTemplateTable',
  14. 'ManufacturerTable',
  15. 'ModuleBayTemplateTable',
  16. 'PowerOutletTemplateTable',
  17. 'PowerPortTemplateTable',
  18. 'RearPortTemplateTable',
  19. )
  20. #
  21. # Manufacturers
  22. #
  23. class ManufacturerTable(ContactsColumnMixin, NetBoxTable):
  24. name = tables.Column(
  25. linkify=True
  26. )
  27. devicetype_count = columns.LinkedCountColumn(
  28. viewname='dcim:devicetype_list',
  29. url_params={'manufacturer_id': 'pk'},
  30. verbose_name='Device Types'
  31. )
  32. moduletype_count = columns.LinkedCountColumn(
  33. viewname='dcim:moduletype_list',
  34. url_params={'manufacturer_id': 'pk'},
  35. verbose_name='Module Types'
  36. )
  37. inventoryitem_count = columns.LinkedCountColumn(
  38. viewname='dcim:inventoryitem_list',
  39. url_params={'manufacturer_id': 'pk'},
  40. verbose_name='Inventory Items'
  41. )
  42. platform_count = columns.LinkedCountColumn(
  43. viewname='dcim:platform_list',
  44. url_params={'manufacturer_id': 'pk'},
  45. verbose_name='Platforms'
  46. )
  47. tags = columns.TagColumn(
  48. url_name='dcim:manufacturer_list'
  49. )
  50. class Meta(NetBoxTable.Meta):
  51. model = models.Manufacturer
  52. fields = (
  53. 'pk', 'id', 'name', 'devicetype_count', 'moduletype_count', 'inventoryitem_count', 'platform_count',
  54. 'description', 'slug', 'tags', 'contacts', 'actions', 'created', 'last_updated',
  55. )
  56. default_columns = (
  57. 'pk', 'name', 'devicetype_count', 'moduletype_count', 'inventoryitem_count', 'platform_count',
  58. 'description', 'slug',
  59. )
  60. #
  61. # Device types
  62. #
  63. class DeviceTypeTable(NetBoxTable):
  64. model = tables.Column(
  65. linkify=True,
  66. verbose_name='Device Type'
  67. )
  68. manufacturer = tables.Column(
  69. linkify=True
  70. )
  71. default_platform = tables.Column(
  72. linkify=True
  73. )
  74. is_full_depth = columns.BooleanColumn(
  75. verbose_name='Full Depth'
  76. )
  77. instance_count = columns.LinkedCountColumn(
  78. viewname='dcim:device_list',
  79. url_params={'device_type_id': 'pk'},
  80. verbose_name='Instances'
  81. )
  82. comments = columns.MarkdownColumn()
  83. tags = columns.TagColumn(
  84. url_name='dcim:devicetype_list'
  85. )
  86. u_height = columns.TemplateColumn(
  87. template_code='{{ value|floatformat }}'
  88. )
  89. weight = columns.TemplateColumn(
  90. template_code=WEIGHT,
  91. order_by=('_abs_weight', 'weight_unit')
  92. )
  93. class Meta(NetBoxTable.Meta):
  94. model = models.DeviceType
  95. fields = (
  96. 'pk', 'id', 'model', 'manufacturer', 'default_platform', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role',
  97. 'airflow', 'weight', 'description', 'comments', 'instance_count', 'tags', 'created', 'last_updated',
  98. )
  99. default_columns = (
  100. 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count',
  101. )
  102. #
  103. # Device type components
  104. #
  105. class ComponentTemplateTable(NetBoxTable):
  106. id = tables.Column(
  107. verbose_name='ID'
  108. )
  109. name = tables.Column(
  110. order_by=('_name',)
  111. )
  112. class Meta(NetBoxTable.Meta):
  113. exclude = ('id', )
  114. class ConsolePortTemplateTable(ComponentTemplateTable):
  115. actions = columns.ActionsColumn(
  116. actions=('edit', 'delete'),
  117. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  118. )
  119. class Meta(ComponentTemplateTable.Meta):
  120. model = models.ConsolePortTemplate
  121. fields = ('pk', 'name', 'label', 'type', 'description', 'actions')
  122. empty_text = "None"
  123. class ConsoleServerPortTemplateTable(ComponentTemplateTable):
  124. actions = columns.ActionsColumn(
  125. actions=('edit', 'delete'),
  126. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  127. )
  128. class Meta(ComponentTemplateTable.Meta):
  129. model = models.ConsoleServerPortTemplate
  130. fields = ('pk', 'name', 'label', 'type', 'description', 'actions')
  131. empty_text = "None"
  132. class PowerPortTemplateTable(ComponentTemplateTable):
  133. actions = columns.ActionsColumn(
  134. actions=('edit', 'delete'),
  135. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  136. )
  137. class Meta(ComponentTemplateTable.Meta):
  138. model = models.PowerPortTemplate
  139. fields = ('pk', 'name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description', 'actions')
  140. empty_text = "None"
  141. class PowerOutletTemplateTable(ComponentTemplateTable):
  142. actions = columns.ActionsColumn(
  143. actions=('edit', 'delete'),
  144. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  145. )
  146. class Meta(ComponentTemplateTable.Meta):
  147. model = models.PowerOutletTemplate
  148. fields = ('pk', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description', 'actions')
  149. empty_text = "None"
  150. class InterfaceTemplateTable(ComponentTemplateTable):
  151. enabled = columns.BooleanColumn()
  152. mgmt_only = columns.BooleanColumn(
  153. verbose_name='Management Only'
  154. )
  155. actions = columns.ActionsColumn(
  156. actions=('edit', 'delete'),
  157. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  158. )
  159. class Meta(ComponentTemplateTable.Meta):
  160. model = models.InterfaceTemplate
  161. fields = ('pk', 'name', 'label', 'enabled', 'mgmt_only', 'type', 'description', 'bridge', 'poe_mode', 'poe_type', 'actions')
  162. empty_text = "None"
  163. class FrontPortTemplateTable(ComponentTemplateTable):
  164. rear_port_position = tables.Column(
  165. verbose_name='Position'
  166. )
  167. color = columns.ColorColumn()
  168. actions = columns.ActionsColumn(
  169. actions=('edit', 'delete'),
  170. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  171. )
  172. class Meta(ComponentTemplateTable.Meta):
  173. model = models.FrontPortTemplate
  174. fields = ('pk', 'name', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description', 'actions')
  175. empty_text = "None"
  176. class RearPortTemplateTable(ComponentTemplateTable):
  177. color = columns.ColorColumn()
  178. actions = columns.ActionsColumn(
  179. actions=('edit', 'delete'),
  180. extra_buttons=MODULAR_COMPONENT_TEMPLATE_BUTTONS
  181. )
  182. class Meta(ComponentTemplateTable.Meta):
  183. model = models.RearPortTemplate
  184. fields = ('pk', 'name', 'label', 'type', 'color', 'positions', 'description', 'actions')
  185. empty_text = "None"
  186. class ModuleBayTemplateTable(ComponentTemplateTable):
  187. actions = columns.ActionsColumn(
  188. actions=('edit', 'delete')
  189. )
  190. class Meta(ComponentTemplateTable.Meta):
  191. model = models.ModuleBayTemplate
  192. fields = ('pk', 'name', 'label', 'position', 'description', 'actions')
  193. empty_text = "None"
  194. class DeviceBayTemplateTable(ComponentTemplateTable):
  195. actions = columns.ActionsColumn(
  196. actions=('edit', 'delete')
  197. )
  198. class Meta(ComponentTemplateTable.Meta):
  199. model = models.DeviceBayTemplate
  200. fields = ('pk', 'name', 'label', 'description', 'actions')
  201. empty_text = "None"
  202. class InventoryItemTemplateTable(ComponentTemplateTable):
  203. actions = columns.ActionsColumn(
  204. actions=('edit', 'delete')
  205. )
  206. role = tables.Column(
  207. linkify=True
  208. )
  209. manufacturer = tables.Column(
  210. linkify=True
  211. )
  212. component = tables.Column(
  213. orderable=False
  214. )
  215. class Meta(ComponentTemplateTable.Meta):
  216. model = models.InventoryItemTemplate
  217. fields = (
  218. 'pk', 'name', 'label', 'parent', 'role', 'manufacturer', 'part_id', 'component', 'description', 'actions',
  219. )
  220. empty_text = "None"