parameters.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. from django import forms
  2. from django.contrib.postgres.forms import SimpleArrayField
  3. class ConfigParam:
  4. def __init__(self, name, label, default, description='', field=None, field_kwargs=None):
  5. self.name = name
  6. self.label = label
  7. self.default = default
  8. self.field = field or forms.CharField
  9. self.description = description
  10. self.field_kwargs = field_kwargs or {}
  11. PARAMS = (
  12. # Banners
  13. ConfigParam(
  14. name='BANNER_LOGIN',
  15. label='Login banner',
  16. default='',
  17. description="Additional content to display on the login page",
  18. field_kwargs={
  19. 'widget': forms.Textarea(
  20. attrs={'class': 'vLargeTextField'}
  21. ),
  22. },
  23. ),
  24. ConfigParam(
  25. name='BANNER_TOP',
  26. label='Top banner',
  27. default='',
  28. description="Additional content to display at the top of every page",
  29. field_kwargs={
  30. 'widget': forms.Textarea(
  31. attrs={'class': 'vLargeTextField'}
  32. ),
  33. },
  34. ),
  35. ConfigParam(
  36. name='BANNER_BOTTOM',
  37. label='Bottom banner',
  38. default='',
  39. description="Additional content to display at the bottom of every page",
  40. field_kwargs={
  41. 'widget': forms.Textarea(
  42. attrs={'class': 'vLargeTextField'}
  43. ),
  44. },
  45. ),
  46. # IPAM
  47. ConfigParam(
  48. name='ENFORCE_GLOBAL_UNIQUE',
  49. label='Globally unique IP space',
  50. default=False,
  51. description="Enforce unique IP addressing within the global table",
  52. field=forms.BooleanField
  53. ),
  54. ConfigParam(
  55. name='PREFER_IPV4',
  56. label='Prefer IPv4',
  57. default=False,
  58. description="Prefer IPv4 addresses over IPv6",
  59. field=forms.BooleanField
  60. ),
  61. # Racks
  62. ConfigParam(
  63. name='RACK_ELEVATION_DEFAULT_UNIT_HEIGHT',
  64. label='Rack unit height',
  65. default=22,
  66. description="Default unit height for rendered rack elevations",
  67. field=forms.IntegerField
  68. ),
  69. ConfigParam(
  70. name='RACK_ELEVATION_DEFAULT_UNIT_WIDTH',
  71. label='Rack unit width',
  72. default=220,
  73. description="Default unit width for rendered rack elevations",
  74. field=forms.IntegerField
  75. ),
  76. # Power
  77. ConfigParam(
  78. name='POWERFEED_DEFAULT_VOLTAGE',
  79. label='Powerfeed voltage',
  80. default=120,
  81. description="Default voltage for powerfeeds",
  82. field=forms.IntegerField
  83. ),
  84. ConfigParam(
  85. name='POWERFEED_DEFAULT_AMPERAGE',
  86. label='Powerfeed amperage',
  87. default=15,
  88. description="Default amperage for powerfeeds",
  89. field=forms.IntegerField
  90. ),
  91. ConfigParam(
  92. name='POWERFEED_DEFAULT_MAX_UTILIZATION',
  93. label='Powerfeed max utilization',
  94. default=80,
  95. description="Default max utilization for powerfeeds",
  96. field=forms.IntegerField
  97. ),
  98. # Security
  99. ConfigParam(
  100. name='ALLOWED_URL_SCHEMES',
  101. label='Allowed URL schemes',
  102. default=(
  103. 'file', 'ftp', 'ftps', 'http', 'https', 'irc', 'mailto', 'sftp', 'ssh', 'tel', 'telnet', 'tftp', 'vnc',
  104. 'xmpp',
  105. ),
  106. description="Permitted schemes for URLs in user-provided content",
  107. field=SimpleArrayField,
  108. field_kwargs={'base_field': forms.CharField()}
  109. ),
  110. # Pagination
  111. ConfigParam(
  112. name='PAGINATE_COUNT',
  113. label='Default page size',
  114. default=50,
  115. field=forms.IntegerField
  116. ),
  117. ConfigParam(
  118. name='MAX_PAGE_SIZE',
  119. label='Maximum page size',
  120. default=1000,
  121. field=forms.IntegerField
  122. ),
  123. # Validation
  124. ConfigParam(
  125. name='CUSTOM_VALIDATORS',
  126. label='Custom validators',
  127. default={},
  128. description="Custom validation rules (JSON)",
  129. field=forms.JSONField,
  130. field_kwargs={
  131. 'widget': forms.Textarea(
  132. attrs={'class': 'vLargeTextField'}
  133. ),
  134. },
  135. ),
  136. # NAPALM
  137. ConfigParam(
  138. name='NAPALM_USERNAME',
  139. label='NAPALM username',
  140. default='',
  141. description="Username to use when connecting to devices via NAPALM"
  142. ),
  143. ConfigParam(
  144. name='NAPALM_PASSWORD',
  145. label='NAPALM password',
  146. default='',
  147. description="Password to use when connecting to devices via NAPALM"
  148. ),
  149. ConfigParam(
  150. name='NAPALM_TIMEOUT',
  151. label='NAPALM timeout',
  152. default=30,
  153. description="NAPALM connection timeout (in seconds)",
  154. field=forms.IntegerField
  155. ),
  156. ConfigParam(
  157. name='NAPALM_ARGS',
  158. label='NAPALM arguments',
  159. default={},
  160. description="Additional arguments to pass when invoking a NAPALM driver (as JSON data)",
  161. field=forms.JSONField,
  162. field_kwargs={
  163. 'widget': forms.Textarea(
  164. attrs={'class': 'vLargeTextField'}
  165. ),
  166. },
  167. ),
  168. # User preferences
  169. ConfigParam(
  170. name='DEFAULT_USER_PREFERENCES',
  171. label='Default preferences',
  172. default={},
  173. description="Default preferences for new users",
  174. field=forms.JSONField
  175. ),
  176. # Miscellaneous
  177. ConfigParam(
  178. name='MAINTENANCE_MODE',
  179. label='Maintenance mode',
  180. default=False,
  181. description="Enable maintenance mode",
  182. field=forms.BooleanField
  183. ),
  184. ConfigParam(
  185. name='GRAPHQL_ENABLED',
  186. label='GraphQL enabled',
  187. default=True,
  188. description="Enable the GraphQL API",
  189. field=forms.BooleanField
  190. ),
  191. ConfigParam(
  192. name='CHANGELOG_RETENTION',
  193. label='Changelog retention',
  194. default=90,
  195. description="Days to retain changelog history (set to zero for unlimited)",
  196. field=forms.IntegerField
  197. ),
  198. ConfigParam(
  199. name='JOBRESULT_RETENTION',
  200. label='Job result retention',
  201. default=90,
  202. description="Days to retain job result history (set to zero for unlimited)",
  203. field=forms.IntegerField
  204. ),
  205. ConfigParam(
  206. name='MAPS_URL',
  207. label='Maps URL',
  208. default='https://maps.google.com/?q=',
  209. description="Base URL for mapping geographic locations"
  210. ),
  211. )