Page MenuHomePhabricator

Netbox: use Custom Model Validation
Open, Needs TriagePublic


The upgrade to Netbox 3.2 brings Custom Model Validation:

As it was only supported on custom fields until now.

We should leverage this new feature to prevent entry mistakes.

Next step is to list all the fields that require custom validation and their expected patterns.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I did a quick pass in the UI and found some things, ofc to be integrated with all the checks in the current reports that can be converted to field validators:

  • site.slug: lower case, maybe also 5 chars?
  • valid hostname (not FQDN, so no dots) regex, in addition if a 4 digit number is present the first digit must match the DC's digit prefix rule (eqiad => 1, etc.)
  • device.asset_tag: custom WMF asset tag regex, to be removed from reports
  • virtual_chassis.domain: FQDN regex (unless already validated by netbox)
  • unclear from the data, most have console0, some console-re[0-1], Ripe atlas devices have different values
  • port[1-9][0-9]?
  • PSU[1-2] (the current report checks for PSU\d|PEM \d|Power Supply \d, we still need all of them?)
  • a positive integer
  • see the INTERFACES_REGEXP in the current report
  • cables

Agreed, we need to keep a close look at any risk of performance hit (eg. the ones that iterate over all objects), but a lot of reports/tests could be replaced by those validators.

We had an IRC chat with @Volans about its actual implementation especially regarding:

  • How it's loaded (dynamic or not)
    • do we need to reload uwsgi?
    • Do we have to define them in the dynamic config or can we define them in the regular
  • How to structure them
    • One multiple validator per model (eg. for multiple conditions), one validator per model?

So far the idea is to:

  • Use the dotted-path format (more dynamic/flexible/explicit)
  • Use 1 validator per model for performance reasons
  • Put the file in netbox-deploy
    • No risk to break Netbox with a change to netbox-extra
    • Somehow have it exposed in the venv (TODO figure out how)
  • Ideally use the file config knob to keep all the config in a single location and benefit from git history
ayounsi removed Volans as the assignee of this task.