search.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. from netbox.search import SearchIndex, register_search
  2. from . import models
  3. @register_search
  4. class AggregateIndex(SearchIndex):
  5. model = models.Aggregate
  6. fields = (
  7. ('prefix', 120),
  8. ('description', 500),
  9. ('date_added', 2000),
  10. ('comments', 5000),
  11. )
  12. display_attrs = ('rir', 'tenant', 'description')
  13. @register_search
  14. class ASNIndex(SearchIndex):
  15. model = models.ASN
  16. fields = (
  17. ('asn', 100),
  18. ('prefixed_name', 110),
  19. ('description', 500),
  20. )
  21. display_attrs = ('rir', 'tenant', 'description')
  22. @register_search
  23. class ASNRangeIndex(SearchIndex):
  24. model = models.ASNRange
  25. fields = (
  26. ('name', 100),
  27. ('description', 500),
  28. )
  29. display_attrs = ('rir', 'tenant', 'description')
  30. @register_search
  31. class FHRPGroupIndex(SearchIndex):
  32. model = models.FHRPGroup
  33. fields = (
  34. ('name', 100),
  35. ('group_id', 2000),
  36. ('description', 500),
  37. ('comments', 5000),
  38. )
  39. display_attrs = ('protocol', 'auth_type', 'description')
  40. @register_search
  41. class IPAddressIndex(SearchIndex):
  42. model = models.IPAddress
  43. fields = (
  44. ('address', 100),
  45. ('dns_name', 300),
  46. ('description', 500),
  47. ('comments', 5000),
  48. )
  49. display_attrs = ('vrf', 'tenant', 'status', 'role', 'description')
  50. @register_search
  51. class IPRangeIndex(SearchIndex):
  52. model = models.IPRange
  53. fields = (
  54. ('start_address', 100),
  55. ('end_address', 300),
  56. ('description', 500),
  57. ('comments', 5000),
  58. )
  59. display_attrs = ('vrf', 'tenant', 'status', 'role', 'description')
  60. @register_search
  61. class PrefixIndex(SearchIndex):
  62. model = models.Prefix
  63. fields = (
  64. ('prefix', 110),
  65. ('description', 500),
  66. ('comments', 5000),
  67. )
  68. display_attrs = ('scope', 'vrf', 'tenant', 'vlan', 'status', 'role', 'description')
  69. @register_search
  70. class RIRIndex(SearchIndex):
  71. model = models.RIR
  72. fields = (
  73. ('name', 100),
  74. ('slug', 110),
  75. ('description', 500),
  76. )
  77. display_attrs = ('description',)
  78. @register_search
  79. class RoleIndex(SearchIndex):
  80. model = models.Role
  81. fields = (
  82. ('name', 100),
  83. ('slug', 110),
  84. ('description', 500),
  85. )
  86. display_attrs = ('description',)
  87. @register_search
  88. class RouteTargetIndex(SearchIndex):
  89. model = models.RouteTarget
  90. fields = (
  91. ('name', 100),
  92. ('description', 500),
  93. ('comments', 5000),
  94. )
  95. display_attrs = ('tenant', 'description')
  96. @register_search
  97. class ServiceIndex(SearchIndex):
  98. model = models.Service
  99. fields = (
  100. ('name', 100),
  101. ('description', 500),
  102. ('comments', 5000),
  103. )
  104. display_attrs = ('parent', 'description')
  105. @register_search
  106. class ServiceTemplateIndex(SearchIndex):
  107. model = models.ServiceTemplate
  108. fields = (
  109. ('name', 100),
  110. ('description', 500),
  111. ('comments', 5000),
  112. )
  113. display_attrs = ('description',)
  114. @register_search
  115. class VLANIndex(SearchIndex):
  116. model = models.VLAN
  117. fields = (
  118. ('name', 100),
  119. ('vid', 100),
  120. ('description', 500),
  121. ('comments', 5000),
  122. )
  123. display_attrs = ('site', 'group', 'tenant', 'status', 'role', 'description')
  124. @register_search
  125. class VLANGroupIndex(SearchIndex):
  126. model = models.VLANGroup
  127. fields = (
  128. ('name', 100),
  129. ('slug', 110),
  130. ('description', 500),
  131. )
  132. display_attrs = ('scope_type', 'description')
  133. @register_search
  134. class VLANTranslationPolicyIndex(SearchIndex):
  135. model = models.VLANTranslationPolicy
  136. fields = (
  137. ('name', 100),
  138. ('description', 500),
  139. )
  140. display_attrs = ('description',)
  141. @register_search
  142. class VLANTranslationRuleIndex(SearchIndex):
  143. model = models.VLANTranslationRule
  144. fields = (
  145. ('policy', 100),
  146. ('local_vid', 200),
  147. ('remote_vid', 200),
  148. )
  149. display_attrs = ('policy', 'local_vid', 'remote_vid')
  150. @register_search
  151. class VRFIndex(SearchIndex):
  152. model = models.VRF
  153. fields = (
  154. ('name', 100),
  155. ('rd', 200),
  156. ('description', 500),
  157. ('comments', 5000),
  158. )
  159. display_attrs = ('rd', 'tenant', 'description')