search.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. from netbox.search import SearchIndex, register_search
  2. from . import models
  3. @register_search
  4. class CableBundleIndex(SearchIndex):
  5. model = models.CableBundle
  6. fields = (
  7. ('name', 100),
  8. ('description', 500),
  9. ('comments', 5000),
  10. )
  11. display_attrs = ('description',)
  12. @register_search
  13. class CableIndex(SearchIndex):
  14. model = models.Cable
  15. fields = (
  16. ('label', 100),
  17. ('description', 500),
  18. ('comments', 5000),
  19. )
  20. display_attrs = ('type', 'status', 'tenant', 'label', 'description')
  21. @register_search
  22. class ConsolePortIndex(SearchIndex):
  23. model = models.ConsolePort
  24. fields = (
  25. ('name', 100),
  26. ('label', 200),
  27. ('description', 500),
  28. ('speed', 2000),
  29. )
  30. display_attrs = ('device', 'label', 'type', 'description')
  31. @register_search
  32. class ConsoleServerPortIndex(SearchIndex):
  33. model = models.ConsoleServerPort
  34. fields = (
  35. ('name', 100),
  36. ('label', 200),
  37. ('description', 500),
  38. ('speed', 2000),
  39. )
  40. display_attrs = ('device', 'label', 'type', 'description')
  41. @register_search
  42. class CoolingFeedIndex(SearchIndex):
  43. model = models.CoolingFeed
  44. fields = (
  45. ('name', 100),
  46. ('description', 500),
  47. ('comments', 5000),
  48. )
  49. display_attrs = ('cooling_source', 'rack', 'status', 'description')
  50. @register_search
  51. class CoolingOutflowIndex(SearchIndex):
  52. model = models.CoolingOutflow
  53. fields = (
  54. ('name', 100),
  55. ('label', 200),
  56. ('description', 500),
  57. )
  58. display_attrs = ('device', 'label', 'type', 'description')
  59. @register_search
  60. class CoolingIntakeIndex(SearchIndex):
  61. model = models.CoolingIntake
  62. fields = (
  63. ('name', 100),
  64. ('label', 200),
  65. ('description', 500),
  66. )
  67. display_attrs = ('device', 'label', 'type', 'description')
  68. @register_search
  69. class CoolingSourceIndex(SearchIndex):
  70. model = models.CoolingSource
  71. fields = (
  72. ('name', 100),
  73. ('description', 500),
  74. ('comments', 5000),
  75. )
  76. display_attrs = ('site', 'location', 'type', 'status', 'description')
  77. @register_search
  78. class DeviceIndex(SearchIndex):
  79. model = models.Device
  80. fields = (
  81. ('asset_tag', 50),
  82. ('serial', 60),
  83. ('name', 100),
  84. ('virtual_chassis', 200),
  85. ('description', 500),
  86. ('comments', 5000),
  87. )
  88. display_attrs = (
  89. 'site', 'location', 'rack', 'status', 'device_type', 'role', 'tenant', 'platform', 'serial', 'asset_tag',
  90. 'description',
  91. )
  92. @register_search
  93. class DeviceBayIndex(SearchIndex):
  94. model = models.DeviceBay
  95. fields = (
  96. ('name', 100),
  97. ('label', 200),
  98. ('description', 500),
  99. )
  100. display_attrs = ('device', 'label', 'description')
  101. @register_search
  102. class DeviceRoleIndex(SearchIndex):
  103. model = models.DeviceRole
  104. fields = (
  105. ('name', 100),
  106. ('slug', 110),
  107. ('description', 500),
  108. ('comments', 5000),
  109. )
  110. display_attrs = ('description',)
  111. @register_search
  112. class DeviceTypeIndex(SearchIndex):
  113. model = models.DeviceType
  114. fields = (
  115. ('model', 100),
  116. ('part_number', 200),
  117. ('description', 500),
  118. ('comments', 5000),
  119. )
  120. display_attrs = ('manufacturer', 'part_number', 'description')
  121. @register_search
  122. class FrontPortIndex(SearchIndex):
  123. model = models.FrontPort
  124. fields = (
  125. ('name', 100),
  126. ('label', 200),
  127. ('description', 500),
  128. )
  129. display_attrs = ('device', 'label', 'type', 'description')
  130. @register_search
  131. class MACAddressIndex(SearchIndex):
  132. model = models.MACAddress
  133. fields = (
  134. ('mac_address', 100),
  135. ('description', 500),
  136. ('comments', 5000),
  137. )
  138. display_attrs = ('assigned_object', 'description')
  139. @register_search
  140. class InterfaceIndex(SearchIndex):
  141. model = models.Interface
  142. fields = (
  143. ('name', 100),
  144. ('label', 200),
  145. ('wwn', 300),
  146. ('description', 500),
  147. ('mtu', 2000),
  148. ('speed', 2000),
  149. )
  150. display_attrs = ('device', 'label', 'type', 'wwn', 'description')
  151. @register_search
  152. class InventoryItemIndex(SearchIndex):
  153. model = models.InventoryItem
  154. fields = (
  155. ('asset_tag', 50),
  156. ('serial', 60),
  157. ('name', 100),
  158. ('label', 200),
  159. ('description', 500),
  160. ('part_id', 2000),
  161. )
  162. display_attrs = ('device', 'manufacturer', 'parent', 'part_id', 'serial', 'asset_tag', 'description')
  163. @register_search
  164. class InventoryItemRoleIndex(SearchIndex):
  165. model = models.InventoryItemRole
  166. fields = (
  167. ('name', 100),
  168. ('slug', 110),
  169. ('description', 500),
  170. ('comments', 5000),
  171. )
  172. display_attrs = ('description',)
  173. @register_search
  174. class LocationIndex(SearchIndex):
  175. model = models.Location
  176. fields = (
  177. ('name', 100),
  178. ('facility', 100),
  179. ('slug', 110),
  180. ('description', 500),
  181. ('comments', 5000),
  182. )
  183. display_attrs = ('site', 'status', 'tenant', 'facility', 'description')
  184. @register_search
  185. class ManufacturerIndex(SearchIndex):
  186. model = models.Manufacturer
  187. fields = (
  188. ('name', 100),
  189. ('slug', 110),
  190. ('description', 500),
  191. ('comments', 5000),
  192. )
  193. display_attrs = ('description',)
  194. @register_search
  195. class ModuleIndex(SearchIndex):
  196. model = models.Module
  197. fields = (
  198. ('asset_tag', 50),
  199. ('serial', 60),
  200. ('description', 500),
  201. ('comments', 5000),
  202. )
  203. display_attrs = ('device', 'module_bay', 'module_type', 'status', 'serial', 'asset_tag', 'description')
  204. @register_search
  205. class ModuleBayIndex(SearchIndex):
  206. model = models.ModuleBay
  207. fields = (
  208. ('name', 100),
  209. ('label', 200),
  210. ('description', 500),
  211. )
  212. display_attrs = ('device', 'label', 'position', 'description')
  213. @register_search
  214. class ModuleBayTypeIndex(SearchIndex):
  215. model = models.ModuleBayType
  216. fields = (
  217. ('name', 100),
  218. ('slug', 110),
  219. ('description', 500),
  220. ('comments', 5000),
  221. )
  222. display_attrs = ('name', 'manufacturer', 'description')
  223. @register_search
  224. class ModuleTypeProfileIndex(SearchIndex):
  225. model = models.ModuleTypeProfile
  226. fields = (
  227. ('name', 100),
  228. ('description', 500),
  229. ('comments', 5000),
  230. )
  231. display_attrs = ('name', 'description')
  232. @register_search
  233. class ModuleTypeIndex(SearchIndex):
  234. model = models.ModuleType
  235. fields = (
  236. ('model', 100),
  237. ('part_number', 200),
  238. ('description', 500),
  239. ('comments', 5000),
  240. )
  241. display_attrs = ('manufacturer', 'model', 'part_number', 'description')
  242. @register_search
  243. class PlatformIndex(SearchIndex):
  244. model = models.Platform
  245. fields = (
  246. ('name', 100),
  247. ('slug', 110),
  248. ('description', 500),
  249. ('comments', 5000),
  250. )
  251. display_attrs = ('manufacturer', 'description')
  252. @register_search
  253. class PowerFeedIndex(SearchIndex):
  254. model = models.PowerFeed
  255. fields = (
  256. ('name', 100),
  257. ('description', 500),
  258. ('comments', 5000),
  259. )
  260. display_attrs = ('power_panel', 'rack', 'status', 'description')
  261. @register_search
  262. class PowerOutletIndex(SearchIndex):
  263. model = models.PowerOutlet
  264. fields = (
  265. ('name', 100),
  266. ('label', 200),
  267. ('description', 500),
  268. )
  269. display_attrs = ('device', 'label', 'type', 'status', 'description')
  270. @register_search
  271. class PowerPanelIndex(SearchIndex):
  272. model = models.PowerPanel
  273. fields = (
  274. ('name', 100),
  275. ('description', 500),
  276. ('comments', 5000),
  277. )
  278. display_attrs = ('site', 'location', 'description')
  279. @register_search
  280. class PowerPortIndex(SearchIndex):
  281. model = models.PowerPort
  282. fields = (
  283. ('name', 100),
  284. ('label', 200),
  285. ('description', 500),
  286. ('maximum_draw', 2000),
  287. ('allocated_draw', 2000),
  288. )
  289. display_attrs = ('device', 'label', 'type', 'description')
  290. @register_search
  291. class RackTypeIndex(SearchIndex):
  292. model = models.RackType
  293. fields = (
  294. ('model', 100),
  295. ('description', 500),
  296. ('comments', 5000),
  297. )
  298. display_attrs = ('model', 'description')
  299. @register_search
  300. class RackIndex(SearchIndex):
  301. model = models.Rack
  302. fields = (
  303. ('asset_tag', 50),
  304. ('serial', 60),
  305. ('name', 100),
  306. ('facility_id', 200),
  307. ('description', 500),
  308. ('comments', 5000),
  309. )
  310. display_attrs = (
  311. 'site', 'location', 'facility_id', 'tenant', 'status', 'role', 'serial', 'asset_tag', 'description',
  312. )
  313. @register_search
  314. class RackReservationIndex(SearchIndex):
  315. model = models.RackReservation
  316. fields = (
  317. ('description', 500),
  318. ('comments', 5000),
  319. )
  320. display_attrs = ('rack', 'tenant', 'user', 'description')
  321. @register_search
  322. class RackGroupIndex(SearchIndex):
  323. model = models.RackGroup
  324. fields = (
  325. ('name', 100),
  326. ('slug', 110),
  327. ('description', 500),
  328. ('comments', 5000),
  329. )
  330. display_attrs = ('description',)
  331. @register_search
  332. class RackRoleIndex(SearchIndex):
  333. model = models.RackRole
  334. fields = (
  335. ('name', 100),
  336. ('slug', 110),
  337. ('description', 500),
  338. ('comments', 5000),
  339. )
  340. display_attrs = ('description',)
  341. @register_search
  342. class RearPortIndex(SearchIndex):
  343. model = models.RearPort
  344. fields = (
  345. ('name', 100),
  346. ('label', 200),
  347. ('description', 500),
  348. )
  349. display_attrs = ('device', 'label', 'type', 'description')
  350. @register_search
  351. class RegionIndex(SearchIndex):
  352. model = models.Region
  353. fields = (
  354. ('name', 100),
  355. ('slug', 110),
  356. ('description', 500),
  357. ('comments', 5000),
  358. )
  359. display_attrs = ('parent', 'description')
  360. @register_search
  361. class SiteIndex(SearchIndex):
  362. model = models.Site
  363. fields = (
  364. ('name', 100),
  365. ('facility', 100),
  366. ('slug', 110),
  367. ('description', 500),
  368. ('physical_address', 2000),
  369. ('shipping_address', 2000),
  370. ('comments', 5000),
  371. )
  372. display_attrs = ('region', 'group', 'status', 'tenant', 'facility', 'description')
  373. @register_search
  374. class SiteGroupIndex(SearchIndex):
  375. model = models.SiteGroup
  376. fields = (
  377. ('name', 100),
  378. ('slug', 110),
  379. ('description', 500),
  380. ('comments', 5000),
  381. )
  382. display_attrs = ('parent', 'description')
  383. @register_search
  384. class VirtualChassisIndex(SearchIndex):
  385. model = models.VirtualChassis
  386. fields = (
  387. ('name', 100),
  388. ('domain', 300),
  389. ('description', 500),
  390. ('comments', 5000),
  391. )
  392. display_attrs = ('master', 'domain', 'description')
  393. @register_search
  394. class VirtualDeviceContextIndex(SearchIndex):
  395. model = models.VirtualDeviceContext
  396. fields = (
  397. ('name', 100),
  398. ('identifier', 300),
  399. ('description', 500),
  400. ('comments', 5000),
  401. )
  402. display_attrs = ('device', 'status', 'identifier', 'tenant', 'description')