Coverage for netbox/config/parameters.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from django import forms 

2from django.contrib.postgres.forms import SimpleArrayField 

3from django.utils.translation import gettext_lazy as _ 

4 

5 

6class ConfigParam: 

7 

8 def __init__(self, name, label, default, description='', field=None, field_kwargs=None): 

9 self.name = name 

10 self.label = label 

11 self.default = default 

12 self.field = field or forms.CharField 

13 self.description = description 

14 self.field_kwargs = field_kwargs or {} 

15 

16 

17PARAMS = ( 

18 

19 # Banners 

20 ConfigParam( 

21 name='BANNER_LOGIN', 

22 label=_('Login banner'), 

23 default='', 

24 description=_("Additional content to display on the login page"), 

25 field_kwargs={ 

26 'widget': forms.Textarea( 

27 attrs={'class': 'font-monospace'} 

28 ), 

29 }, 

30 ), 

31 ConfigParam( 

32 name='BANNER_MAINTENANCE', 

33 label=_('Maintenance banner'), 

34 default='NetBox is currently in maintenance mode. Functionality may be limited.', 

35 description=_('Additional content to display when in maintenance mode'), 

36 field_kwargs={ 

37 'widget': forms.Textarea( 

38 attrs={'class': 'font-monospace'} 

39 ), 

40 }, 

41 ), 

42 ConfigParam( 

43 name='BANNER_TOP', 

44 label=_('Top banner'), 

45 default='', 

46 description=_("Additional content to display at the top of every page"), 

47 field_kwargs={ 

48 'widget': forms.Textarea( 

49 attrs={'class': 'font-monospace'} 

50 ), 

51 }, 

52 ), 

53 ConfigParam( 

54 name='BANNER_BOTTOM', 

55 label=_('Bottom banner'), 

56 default='', 

57 description=_("Additional content to display at the bottom of every page"), 

58 field_kwargs={ 

59 'widget': forms.Textarea( 

60 attrs={'class': 'font-monospace'} 

61 ), 

62 }, 

63 ), 

64 

65 # IPAM 

66 ConfigParam( 

67 name='ENFORCE_GLOBAL_UNIQUE', 

68 label=_('Globally unique IP space'), 

69 default=True, 

70 description=_("Enforce unique IP addressing within the global table"), 

71 field=forms.BooleanField 

72 ), 

73 ConfigParam( 

74 name='PREFER_IPV4', 

75 label=_('Prefer IPv4'), 

76 default=False, 

77 description=_("Prefer IPv4 addresses over IPv6"), 

78 field=forms.BooleanField 

79 ), 

80 

81 # Racks 

82 ConfigParam( 

83 name='RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', 

84 label=_('Rack unit height'), 

85 default=22, 

86 description=_("Default unit height for rendered rack elevations"), 

87 field=forms.IntegerField 

88 ), 

89 ConfigParam( 

90 name='RACK_ELEVATION_DEFAULT_UNIT_WIDTH', 

91 label=_('Rack unit width'), 

92 default=220, 

93 description=_("Default unit width for rendered rack elevations"), 

94 field=forms.IntegerField 

95 ), 

96 

97 # Power 

98 ConfigParam( 

99 name='POWERFEED_DEFAULT_VOLTAGE', 

100 label=_('Powerfeed voltage'), 

101 default=120, 

102 description=_("Default voltage for powerfeeds"), 

103 field=forms.IntegerField 

104 ), 

105 ConfigParam( 

106 name='POWERFEED_DEFAULT_AMPERAGE', 

107 label=_('Powerfeed amperage'), 

108 default=15, 

109 description=_("Default amperage for powerfeeds"), 

110 field=forms.IntegerField 

111 ), 

112 ConfigParam( 

113 name='POWERFEED_DEFAULT_MAX_UTILIZATION', 

114 label=_('Powerfeed max utilization'), 

115 default=80, 

116 description=_("Default max utilization for powerfeeds"), 

117 field=forms.IntegerField 

118 ), 

119 

120 # Security 

121 ConfigParam( 

122 name='ALLOWED_URL_SCHEMES', 

123 label=_('Allowed URL schemes'), 

124 default=( 

125 'file', 'ftp', 'ftps', 'http', 'https', 'irc', 'mailto', 'sftp', 'ssh', 'tel', 'telnet', 'tftp', 'vnc', 

126 'xmpp', 

127 ), 

128 description=_("Permitted schemes for URLs in user-provided content"), 

129 field=SimpleArrayField, 

130 field_kwargs={'base_field': forms.CharField()} 

131 ), 

132 

133 # Pagination 

134 ConfigParam( 

135 name='PAGINATE_COUNT', 

136 label=_('Default page size'), 

137 default=50, 

138 field=forms.IntegerField 

139 ), 

140 ConfigParam( 

141 name='MAX_PAGE_SIZE', 

142 label=_('Maximum page size'), 

143 default=1000, 

144 field=forms.IntegerField 

145 ), 

146 

147 # Validation 

148 ConfigParam( 

149 name='CUSTOM_VALIDATORS', 

150 label=_('Custom validators'), 

151 default={}, 

152 description=_("Custom validation rules (JSON)"), 

153 field=forms.JSONField, 

154 field_kwargs={ 

155 'widget': forms.Textarea(), 

156 }, 

157 ), 

158 ConfigParam( 

159 name='PROTECTION_RULES', 

160 label=_('Protection rules'), 

161 default={}, 

162 description=_("Deletion protection rules (JSON)"), 

163 field=forms.JSONField, 

164 field_kwargs={ 

165 'widget': forms.Textarea(), 

166 }, 

167 ), 

168 

169 # User preferences 

170 ConfigParam( 

171 name='DEFAULT_USER_PREFERENCES', 

172 label=_('Default preferences'), 

173 default={}, 

174 description=_("Default preferences for new users"), 

175 field=forms.JSONField 

176 ), 

177 

178 # Change log 

179 ConfigParam( 

180 name='CHANGELOG_RETENTION', 

181 label=_('Changelog retention'), 

182 default=90, 

183 description=_("Days to retain changelog history (set to zero for unlimited)"), 

184 field=forms.IntegerField, 

185 ), 

186 ConfigParam( 

187 name='CHANGELOG_RETAIN_CREATE_LAST_UPDATE', 

188 label=_('Retain create & last update changelog records'), 

189 default=False, 

190 description=_( 

191 "Retain each object's create record and most recent update record when pruning expired changelog entries " 

192 "(excluding objects with a delete record)." 

193 ), 

194 field=forms.BooleanField, 

195 ), 

196 

197 # Miscellaneous 

198 ConfigParam( 

199 name='MAINTENANCE_MODE', 

200 label=_('Maintenance mode'), 

201 default=False, 

202 description=_("Enable maintenance mode"), 

203 field=forms.BooleanField 

204 ), 

205 ConfigParam( 

206 name='COPILOT_ENABLED', 

207 label=_('NetBox Copilot enabled'), 

208 default=True, 

209 description=_( 

210 "Enable the NetBox Copilot AI agent globally. If enabled, users can toggle the agent individually." 

211 ), 

212 field=forms.BooleanField 

213 ), 

214 ConfigParam( 

215 name='GRAPHQL_ENABLED', 

216 label=_('GraphQL enabled'), 

217 default=True, 

218 description=_("Enable the GraphQL API"), 

219 field=forms.BooleanField 

220 ), 

221 ConfigParam( 

222 name='JOB_RETENTION', 

223 label=_('Job result retention'), 

224 default=90, 

225 description=_("Days to retain job result history (set to zero for unlimited)"), 

226 field=forms.IntegerField 

227 ), 

228 ConfigParam( 

229 name='MAPS_URL', 

230 label=_('Maps URL'), 

231 default='https://maps.google.com/?q=', 

232 description=_( 

233 "URL for mapping geographic locations. For GPS coordinates, include {lat} and/or {lon} placeholders, " 

234 "or omit them to append coordinates as a comma-separated pair. " 

235 "Note: when {lat} or {lon} placeholders are present, address-based map links will be disabled." 

236 ) 

237 ), 

238 

239)