search.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. ('virtual_chassis', 200),
  40. ('description', 500),
  41. ('comments', 5000),
  42. )
  43. display_attrs = (
  44. 'site', 'location', 'rack', 'status', 'device_type', 'role', 'tenant', 'platform', 'serial', 'asset_tag',
  45. 'description',
  46. )
  47. @register_search
  48. class DeviceBayIndex(SearchIndex):
  49. model = models.DeviceBay
  50. fields = (
  51. ('name', 100),
  52. ('label', 200),
  53. ('description', 500),
  54. )
  55. display_attrs = ('device', 'label', 'description')
  56. @register_search
  57. class DeviceRoleIndex(SearchIndex):
  58. model = models.DeviceRole
  59. fields = (
  60. ('name', 100),
  61. ('slug', 110),
  62. ('description', 500),
  63. )
  64. display_attrs = ('description',)
  65. @register_search
  66. class DeviceTypeIndex(SearchIndex):
  67. model = models.DeviceType
  68. fields = (
  69. ('model', 100),
  70. ('part_number', 200),
  71. ('description', 500),
  72. ('comments', 5000),
  73. )
  74. display_attrs = ('manufacturer', 'part_number', 'description')
  75. @register_search
  76. class FrontPortIndex(SearchIndex):
  77. model = models.FrontPort
  78. fields = (
  79. ('name', 100),
  80. ('label', 200),
  81. ('description', 500),
  82. )
  83. display_attrs = ('device', 'label', 'type', 'description')
  84. @register_search
  85. class MACAddressIndex(SearchIndex):
  86. model = models.MACAddress
  87. fields = (
  88. ('mac_address', 100),
  89. ('description', 500),
  90. )
  91. display_attrs = ('assigned_object', 'description')
  92. @register_search
  93. class InterfaceIndex(SearchIndex):
  94. model = models.Interface
  95. fields = (
  96. ('name', 100),
  97. ('label', 200),
  98. ('wwn', 300),
  99. ('description', 500),
  100. ('mtu', 2000),
  101. ('speed', 2000),
  102. )
  103. display_attrs = ('device', 'label', 'type', 'wwn', 'description')
  104. @register_search
  105. class InventoryItemIndex(SearchIndex):
  106. model = models.InventoryItem
  107. fields = (
  108. ('asset_tag', 50),
  109. ('serial', 60),
  110. ('name', 100),
  111. ('label', 200),
  112. ('description', 500),
  113. ('part_id', 2000),
  114. )
  115. display_attrs = ('device', 'manufacturer', 'parent', 'part_id', 'serial', 'asset_tag', 'description')
  116. @register_search
  117. class LocationIndex(SearchIndex):
  118. model = models.Location
  119. fields = (
  120. ('name', 100),
  121. ('facility', 100),
  122. ('slug', 110),
  123. ('description', 500),
  124. ('comments', 5000),
  125. )
  126. display_attrs = ('site', 'status', 'tenant', 'facility', 'description')
  127. @register_search
  128. class ManufacturerIndex(SearchIndex):
  129. model = models.Manufacturer
  130. fields = (
  131. ('name', 100),
  132. ('slug', 110),
  133. ('description', 500),
  134. )
  135. display_attrs = ('description',)
  136. @register_search
  137. class ModuleIndex(SearchIndex):
  138. model = models.Module
  139. fields = (
  140. ('asset_tag', 50),
  141. ('serial', 60),
  142. ('description', 500),
  143. ('comments', 5000),
  144. )
  145. display_attrs = ('device', 'module_bay', 'module_type', 'status', 'serial', 'asset_tag', 'description')
  146. @register_search
  147. class ModuleBayIndex(SearchIndex):
  148. model = models.ModuleBay
  149. fields = (
  150. ('name', 100),
  151. ('label', 200),
  152. ('description', 500),
  153. )
  154. display_attrs = ('device', 'label', 'position', 'description')
  155. @register_search
  156. class ModuleTypeProfileIndex(SearchIndex):
  157. model = models.ModuleTypeProfile
  158. fields = (
  159. ('name', 100),
  160. ('description', 500),
  161. ('comments', 5000),
  162. )
  163. display_attrs = ('name', 'description')
  164. @register_search
  165. class ModuleTypeIndex(SearchIndex):
  166. model = models.ModuleType
  167. fields = (
  168. ('model', 100),
  169. ('part_number', 200),
  170. ('description', 500),
  171. ('comments', 5000),
  172. )
  173. display_attrs = ('manufacturer', 'model', 'part_number', 'description')
  174. @register_search
  175. class PlatformIndex(SearchIndex):
  176. model = models.Platform
  177. fields = (
  178. ('name', 100),
  179. ('slug', 110),
  180. ('description', 500),
  181. )
  182. display_attrs = ('manufacturer', 'description')
  183. @register_search
  184. class PowerFeedIndex(SearchIndex):
  185. model = models.PowerFeed
  186. fields = (
  187. ('name', 100),
  188. ('description', 500),
  189. ('comments', 5000),
  190. )
  191. display_attrs = ('power_panel', 'rack', 'status', 'description')
  192. @register_search
  193. class PowerOutletIndex(SearchIndex):
  194. model = models.PowerOutlet
  195. fields = (
  196. ('name', 100),
  197. ('label', 200),
  198. ('description', 500),
  199. )
  200. display_attrs = ('device', 'label', 'type', 'status', 'description')
  201. @register_search
  202. class PowerPanelIndex(SearchIndex):
  203. model = models.PowerPanel
  204. fields = (
  205. ('name', 100),
  206. ('description', 500),
  207. ('comments', 5000),
  208. )
  209. display_attrs = ('site', 'location', 'description')
  210. @register_search
  211. class PowerPortIndex(SearchIndex):
  212. model = models.PowerPort
  213. fields = (
  214. ('name', 100),
  215. ('label', 200),
  216. ('description', 500),
  217. ('maximum_draw', 2000),
  218. ('allocated_draw', 2000),
  219. )
  220. display_attrs = ('device', 'label', 'type', 'description')
  221. @register_search
  222. class RackTypeIndex(SearchIndex):
  223. model = models.RackType
  224. fields = (
  225. ('model', 100),
  226. ('description', 500),
  227. ('comments', 5000),
  228. )
  229. display_attrs = ('model', 'description')
  230. @register_search
  231. class RackIndex(SearchIndex):
  232. model = models.Rack
  233. fields = (
  234. ('asset_tag', 50),
  235. ('serial', 60),
  236. ('name', 100),
  237. ('facility_id', 200),
  238. ('description', 500),
  239. ('comments', 5000),
  240. )
  241. display_attrs = (
  242. 'site', 'location', 'facility_id', 'tenant', 'status', 'role', 'serial', 'asset_tag', 'description',
  243. )
  244. @register_search
  245. class RackReservationIndex(SearchIndex):
  246. model = models.RackReservation
  247. fields = (
  248. ('description', 500),
  249. ('comments', 5000),
  250. )
  251. display_attrs = ('rack', 'tenant', 'user', 'description')
  252. @register_search
  253. class RackRoleIndex(SearchIndex):
  254. model = models.RackRole
  255. fields = (
  256. ('name', 100),
  257. ('slug', 110),
  258. ('description', 500),
  259. )
  260. display_attrs = ('description',)
  261. @register_search
  262. class RearPortIndex(SearchIndex):
  263. model = models.RearPort
  264. fields = (
  265. ('name', 100),
  266. ('label', 200),
  267. ('description', 500),
  268. )
  269. display_attrs = ('device', 'label', 'type', 'description')
  270. @register_search
  271. class RegionIndex(SearchIndex):
  272. model = models.Region
  273. fields = (
  274. ('name', 100),
  275. ('slug', 110),
  276. ('description', 500),
  277. ('comments', 5000),
  278. )
  279. display_attrs = ('parent', 'description')
  280. @register_search
  281. class SiteIndex(SearchIndex):
  282. model = models.Site
  283. fields = (
  284. ('name', 100),
  285. ('facility', 100),
  286. ('slug', 110),
  287. ('description', 500),
  288. ('physical_address', 2000),
  289. ('shipping_address', 2000),
  290. ('comments', 5000),
  291. )
  292. display_attrs = ('region', 'group', 'status', 'tenant', 'facility', 'description')
  293. @register_search
  294. class SiteGroupIndex(SearchIndex):
  295. model = models.SiteGroup
  296. fields = (
  297. ('name', 100),
  298. ('slug', 110),
  299. ('description', 500),
  300. ('comments', 5000),
  301. )
  302. display_attrs = ('parent', 'description')
  303. @register_search
  304. class VirtualChassisIndex(SearchIndex):
  305. model = models.VirtualChassis
  306. fields = (
  307. ('name', 100),
  308. ('domain', 300),
  309. ('description', 500),
  310. ('comments', 5000),
  311. )
  312. display_attrs = ('master', 'domain', 'description')
  313. @register_search
  314. class VirtualDeviceContextIndex(SearchIndex):
  315. model = models.VirtualDeviceContext
  316. fields = (
  317. ('name', 100),
  318. ('identifier', 300),
  319. ('description', 500),
  320. ('comments', 5000),
  321. )
  322. display_attrs = ('device', 'status', 'identifier', 'tenant', 'description')