-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v2.10.6
Feature type
New functionality
Proposed functionality
Provide a mechanism for users to configure simple custom validation rules for fields on built-in models. This could be done by declaring a suite of custom validators to apply to specific model fields within NetBox's configuration. For example, such a configuration might look like this:
VALIDATION_RULES = {
'dcim.Site': {
'name': {
'regex': '^[A-Z]{3}\d{2}$',
},
'asn': {
'min_value': 65000,
}
}
}
When a site is saved, NetBox would reference this configuration in addition to its own built-in validators. This specific example would require each site's name to match the specified regular expression, and its AS number (if provided) to be equal to or greater than the specified value.
I can see common use cases for the following validator types:
regex: Force matching of a specified regular expressionmin_value: Minimum numeric valuemax_value: Maximum numeric valuemin_length: Minimum length (string)max_length: Maximum length (string)required: Force a normally-optional field to be required (this would not work in the inverse)
This feature is being proposed with the intention of providing a very simple avenue to address very simple requirements. Bearing that in mind, it does not seek to provide conditional validation, which cannot be reasonably expressed in a declarative manner.
Use case
Common examples might include:
- Forcing device names to follow a particular pattern
- Requiring a tenant to be assigned for each prefix
- Limiting the range of AS numbers that can be assigned to sites
Database changes
None, provided the validation rules are defined in the configuration as in the example above.
External dependencies
No response