search.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. ('facility', 100),
  114. ('slug', 110),
  115. ('description', 500),
  116. )
  117. display_attrs = ('site', 'status', 'tenant', 'facility', 'description')
  118. @register_search
  119. class ManufacturerIndex(SearchIndex):
  120. model = models.Manufacturer
  121. fields = (
  122. ('name', 100),
  123. ('slug', 110),
  124. ('description', 500),
  125. )
  126. display_attrs = ('description',)
  127. @register_search
  128. class ModuleIndex(SearchIndex):
  129. model = models.Module
  130. fields = (
  131. ('asset_tag', 50),
  132. ('serial', 60),
  133. ('description', 500),
  134. ('comments', 5000),
  135. )
  136. display_attrs = ('device', 'module_bay', 'module_type', 'status', 'serial', 'asset_tag', 'description')
  137. @register_search
  138. class ModuleBayIndex(SearchIndex):
  139. model = models.ModuleBay
  140. fields = (
  141. ('name', 100),
  142. ('label', 200),
  143. ('description', 500),
  144. )
  145. display_attrs = ('device', 'label', 'position', 'description')
  146. @register_search
  147. class ModuleTypeIndex(SearchIndex):
  148. model = models.ModuleType
  149. fields = (
  150. ('model', 100),
  151. ('part_number', 200),
  152. ('description', 500),
  153. ('comments', 5000),
  154. )
  155. display_attrs = ('manufacturer', 'model', 'part_number', 'description')
  156. @register_search
  157. class PlatformIndex(SearchIndex):
  158. model = models.Platform
  159. fields = (
  160. ('name', 100),
  161. ('slug', 110),
  162. ('description', 500),
  163. )
  164. display_attrs = ('manufacturer', 'description')
  165. @register_search
  166. class PowerFeedIndex(SearchIndex):
  167. model = models.PowerFeed
  168. fields = (
  169. ('name', 100),
  170. ('description', 500),
  171. ('comments', 5000),
  172. )
  173. display_attrs = ('power_panel', 'rack', 'status', 'description')
  174. @register_search
  175. class PowerOutletIndex(SearchIndex):
  176. model = models.PowerOutlet
  177. fields = (
  178. ('name', 100),
  179. ('label', 200),
  180. ('description', 500),
  181. )
  182. display_attrs = ('device', 'label', 'type', 'description')
  183. @register_search
  184. class PowerPanelIndex(SearchIndex):
  185. model = models.PowerPanel
  186. fields = (
  187. ('name', 100),
  188. ('description', 500),
  189. ('comments', 5000),
  190. )
  191. display_attrs = ('site', 'location', 'description')
  192. @register_search
  193. class PowerPortIndex(SearchIndex):
  194. model = models.PowerPort
  195. fields = (
  196. ('name', 100),
  197. ('label', 200),
  198. ('description', 500),
  199. ('maximum_draw', 2000),
  200. ('allocated_draw', 2000),
  201. )
  202. display_attrs = ('device', 'label', 'type', 'description')
  203. @register_search
  204. class RackIndex(SearchIndex):
  205. model = models.Rack
  206. fields = (
  207. ('asset_tag', 50),
  208. ('serial', 60),
  209. ('name', 100),
  210. ('facility_id', 200),
  211. ('description', 500),
  212. ('comments', 5000),
  213. )
  214. display_attrs = (
  215. 'site', 'location', 'facility_id', 'tenant', 'status', 'role', 'serial', 'asset_tag', 'description',
  216. )
  217. @register_search
  218. class RackReservationIndex(SearchIndex):
  219. model = models.RackReservation
  220. fields = (
  221. ('description', 500),
  222. ('comments', 5000),
  223. )
  224. display_attrs = ('rack', 'tenant', 'user', 'description')
  225. @register_search
  226. class RackRoleIndex(SearchIndex):
  227. model = models.RackRole
  228. fields = (
  229. ('name', 100),
  230. ('slug', 110),
  231. ('description', 500),
  232. )
  233. display_attrs = ('description',)
  234. @register_search
  235. class RearPortIndex(SearchIndex):
  236. model = models.RearPort
  237. fields = (
  238. ('name', 100),
  239. ('label', 200),
  240. ('description', 500),
  241. )
  242. display_attrs = ('device', 'label', 'type', 'description')
  243. @register_search
  244. class RegionIndex(SearchIndex):
  245. model = models.Region
  246. fields = (
  247. ('name', 100),
  248. ('slug', 110),
  249. ('description', 500),
  250. )
  251. display_attrs = ('parent', 'description')
  252. @register_search
  253. class SiteIndex(SearchIndex):
  254. model = models.Site
  255. fields = (
  256. ('name', 100),
  257. ('facility', 100),
  258. ('slug', 110),
  259. ('description', 500),
  260. ('physical_address', 2000),
  261. ('shipping_address', 2000),
  262. ('comments', 5000),
  263. )
  264. display_attrs = ('region', 'group', 'status', 'tenant', 'facility', 'description')
  265. @register_search
  266. class SiteGroupIndex(SearchIndex):
  267. model = models.SiteGroup
  268. fields = (
  269. ('name', 100),
  270. ('slug', 110),
  271. ('description', 500),
  272. )
  273. display_attrs = ('parent', 'description')
  274. @register_search
  275. class VirtualChassisIndex(SearchIndex):
  276. model = models.VirtualChassis
  277. fields = (
  278. ('name', 100),
  279. ('domain', 300),
  280. ('description', 500),
  281. ('comments', 5000),
  282. )
  283. display_attrs = ('master', 'domain', 'description')
  284. @register_search
  285. class VirtualDeviceContextIndex(SearchIndex):
  286. model = models.VirtualDeviceContext
  287. fields = (
  288. ('name', 100),
  289. ('identifier', 300),
  290. ('description', 500),
  291. ('comments', 5000),
  292. )
  293. display_attrs = ('device', 'status', 'identifier', 'tenant', 'description')