search.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. from netbox.search import SearchIndex, register_search
  2. from . import models
  3. @register_search
  4. class CableIndex(SearchIndex):
  5. model = models.Cable
  6. fields = (
  7. ('label', 100),
  8. ('description', 500),
  9. ('comments', 5000),
  10. )
  11. display_attrs = ('type', 'status', 'tenant', 'label', 'description')
  12. @register_search
  13. class ConsolePortIndex(SearchIndex):
  14. model = models.ConsolePort
  15. fields = (
  16. ('name', 100),
  17. ('label', 200),
  18. ('description', 500),
  19. ('speed', 2000),
  20. )
  21. display_attrs = ('device', 'label', 'type', 'description')
  22. @register_search
  23. class ConsoleServerPortIndex(SearchIndex):
  24. model = models.ConsoleServerPort
  25. fields = (
  26. ('name', 100),
  27. ('label', 200),
  28. ('description', 500),
  29. ('speed', 2000),
  30. )
  31. display_attrs = ('device', 'label', 'type', 'description')
  32. @register_search
  33. class DeviceIndex(SearchIndex):
  34. model = models.Device
  35. fields = (
  36. ('asset_tag', 50),
  37. ('serial', 60),
  38. ('name', 100),
  39. ('description', 500),
  40. ('comments', 5000),
  41. )
  42. display_attrs = (
  43. 'site', 'location', 'rack', 'status', 'device_type', 'role', 'tenant', 'platform', 'serial', 'asset_tag',
  44. 'description',
  45. )
  46. @register_search
  47. class DeviceBayIndex(SearchIndex):
  48. model = models.DeviceBay
  49. fields = (
  50. ('name', 100),
  51. ('label', 200),
  52. ('description', 500),
  53. )
  54. display_attrs = ('device', 'label', 'description')
  55. @register_search
  56. class DeviceRoleIndex(SearchIndex):
  57. model = models.DeviceRole
  58. fields = (
  59. ('name', 100),
  60. ('slug', 110),
  61. ('description', 500),
  62. )
  63. display_attrs = ('description',)
  64. @register_search
  65. class DeviceTypeIndex(SearchIndex):
  66. model = models.DeviceType
  67. fields = (
  68. ('model', 100),
  69. ('part_number', 200),
  70. ('description', 500),
  71. ('comments', 5000),
  72. )
  73. display_attrs = ('manufacturer', 'part_number', 'description')
  74. @register_search
  75. class FrontPortIndex(SearchIndex):
  76. model = models.FrontPort
  77. fields = (
  78. ('name', 100),
  79. ('label', 200),
  80. ('description', 500),
  81. )
  82. display_attrs = ('device', 'label', 'type', 'description')
  83. @register_search
  84. class InterfaceIndex(SearchIndex):
  85. model = models.Interface
  86. fields = (
  87. ('name', 100),
  88. ('label', 200),
  89. ('mac_address', 300),
  90. ('wwn', 300),
  91. ('description', 500),
  92. ('mtu', 2000),
  93. ('speed', 2000),
  94. )
  95. display_attrs = ('device', 'label', 'type', 'mac_address', 'wwn', 'description')
  96. @register_search
  97. class InventoryItemIndex(SearchIndex):
  98. model = models.InventoryItem
  99. fields = (
  100. ('asset_tag', 50),
  101. ('serial', 60),
  102. ('name', 100),
  103. ('label', 200),
  104. ('description', 500),
  105. ('part_id', 2000),
  106. )
  107. display_attrs = ('device', 'manufacturer', 'parent', 'part_id', 'serial', 'asset_tag', 'description')
  108. @register_search
  109. class LocationIndex(SearchIndex):
  110. model = models.Location
  111. fields = (
  112. ('name', 100),
  113. ('slug', 110),
  114. ('description', 500),
  115. )
  116. display_attrs = ('site', 'status', 'tenant', 'description')
  117. @register_search
  118. class ManufacturerIndex(SearchIndex):
  119. model = models.Manufacturer
  120. fields = (
  121. ('name', 100),
  122. ('slug', 110),
  123. ('description', 500),
  124. )
  125. display_attrs = ('description',)
  126. @register_search
  127. class ModuleIndex(SearchIndex):
  128. model = models.Module
  129. fields = (
  130. ('asset_tag', 50),
  131. ('serial', 60),
  132. ('description', 500),
  133. ('comments', 5000),
  134. )
  135. display_attrs = ('device', 'module_bay', 'module_type', 'status', 'serial', 'asset_tag', 'description')
  136. @register_search
  137. class ModuleBayIndex(SearchIndex):
  138. model = models.ModuleBay
  139. fields = (
  140. ('name', 100),
  141. ('label', 200),
  142. ('description', 500),
  143. )
  144. display_attrs = ('device', 'label', 'position', 'description')
  145. @register_search
  146. class ModuleTypeIndex(SearchIndex):
  147. model = models.ModuleType
  148. fields = (
  149. ('model', 100),
  150. ('part_number', 200),
  151. ('description', 500),
  152. ('comments', 5000),
  153. )
  154. display_attrs = ('manufacturer', 'model', 'part_number', 'description')
  155. @register_search
  156. class PlatformIndex(SearchIndex):
  157. model = models.Platform
  158. fields = (
  159. ('name', 100),
  160. ('slug', 110),
  161. ('description', 500),
  162. )
  163. display_attrs = ('manufacturer', 'description')
  164. @register_search
  165. class PowerFeedIndex(SearchIndex):
  166. model = models.PowerFeed
  167. fields = (
  168. ('name', 100),
  169. ('description', 500),
  170. ('comments', 5000),
  171. )
  172. display_attrs = ('power_panel', 'rack', 'status', 'description')
  173. @register_search
  174. class PowerOutletIndex(SearchIndex):
  175. model = models.PowerOutlet
  176. fields = (
  177. ('name', 100),
  178. ('label', 200),
  179. ('description', 500),
  180. )
  181. display_attrs = ('device', 'label', 'type', 'description')
  182. @register_search
  183. class PowerPanelIndex(SearchIndex):
  184. model = models.PowerPanel
  185. fields = (
  186. ('name', 100),
  187. ('description', 500),
  188. ('comments', 5000),
  189. )
  190. display_attrs = ('site', 'location', 'description')
  191. @register_search
  192. class PowerPortIndex(SearchIndex):
  193. model = models.PowerPort
  194. fields = (
  195. ('name', 100),
  196. ('label', 200),
  197. ('description', 500),
  198. ('maximum_draw', 2000),
  199. ('allocated_draw', 2000),
  200. )
  201. display_attrs = ('device', 'label', 'type', 'description')
  202. @register_search
  203. class RackIndex(SearchIndex):
  204. model = models.Rack
  205. fields = (
  206. ('asset_tag', 50),
  207. ('serial', 60),
  208. ('name', 100),
  209. ('facility_id', 200),
  210. ('description', 500),
  211. ('comments', 5000),
  212. )
  213. display_attrs = (
  214. 'site', 'location', 'facility_id', 'tenant', 'status', 'role', 'serial', 'asset_tag', 'description',
  215. )
  216. @register_search
  217. class RackReservationIndex(SearchIndex):
  218. model = models.RackReservation
  219. fields = (
  220. ('description', 500),
  221. ('comments', 5000),
  222. )
  223. display_attrs = ('rack', 'tenant', 'user', 'description')
  224. @register_search
  225. class RackRoleIndex(SearchIndex):
  226. model = models.RackRole
  227. fields = (
  228. ('name', 100),
  229. ('slug', 110),
  230. ('description', 500),
  231. )
  232. display_attrs = ('description',)
  233. @register_search
  234. class RearPortIndex(SearchIndex):
  235. model = models.RearPort
  236. fields = (
  237. ('name', 100),
  238. ('label', 200),
  239. ('description', 500),
  240. )
  241. display_attrs = ('device', 'label', 'type', 'description')
  242. @register_search
  243. class RegionIndex(SearchIndex):
  244. model = models.Region
  245. fields = (
  246. ('name', 100),
  247. ('slug', 110),
  248. ('description', 500),
  249. )
  250. display_attrs = ('parent', 'description')
  251. @register_search
  252. class SiteIndex(SearchIndex):
  253. model = models.Site
  254. fields = (
  255. ('name', 100),
  256. ('facility', 100),
  257. ('slug', 110),
  258. ('description', 500),
  259. ('physical_address', 2000),
  260. ('shipping_address', 2000),
  261. ('comments', 5000),
  262. )
  263. display_attrs = ('region', 'group', 'status', 'tenant', 'facility', 'description')
  264. @register_search
  265. class SiteGroupIndex(SearchIndex):
  266. model = models.SiteGroup
  267. fields = (
  268. ('name', 100),
  269. ('slug', 110),
  270. ('description', 500),
  271. )
  272. display_attrs = ('parent', 'description')
  273. @register_search
  274. class VirtualChassisIndex(SearchIndex):
  275. model = models.VirtualChassis
  276. fields = (
  277. ('name', 100),
  278. ('domain', 300),
  279. ('description', 500),
  280. ('comments', 5000),
  281. )
  282. display_attrs = ('master', 'domain', 'description')
  283. @register_search
  284. class VirtualDeviceContextIndex(SearchIndex):
  285. model = models.VirtualDeviceContext
  286. fields = (
  287. ('name', 100),
  288. ('identifier', 300),
  289. ('description', 500),
  290. ('comments', 5000),
  291. )
  292. display_attrs = ('device', 'status', 'identifier', 'tenant', 'description')