-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Custom Validators #157
Comments
Seems like this was introduced in 3.1.0? (netbox-community/netbox#7619) So from my perspective this is one of those features that should be configurable by this role in order to get 3.1.0 support through the door in the first place. If I understand correctly this would fundamentally be the same as |
They were part of the 3.0 release. They are slightly different from reports and scripts because there is no "root" folder that NetBox automatically looks for them in. That means the user has to have a package/folder in the path so NetBox can followed the dotted path configured (I use Other than that, I am using similar logic to reports/scripts for copying & linking files. |
Oh I thought the custom validator support in 3.0 was just a specific DSL in I just thought of something I've done before that might be useful. You can add directories to the import os
import sys
sys.path.insert(0, os.path.join(os.getcwd(), "{{ shared_directory }}/validators")) That could go at the top of the |
It's both :) The external files part is where you want to write a CustomValidator class that overrides the |
custom validators go in /srv/netbox/current/netbox/, I use name
file deployment isn't hard but the template for configuration.py might need some work if @lae is happy with the way I've done #190 I'll have a look into doing this in a similar way |
#190 is from my perspective a simpler feature because we're only copying a singular file there which NetBox seems to already be aware of. Anyway feel free to have a go at this. From what I gather, I would add the snippet from earlier into the I'm not sure if the |
I think I tried, a fairly long time ago, to add the My understanding of the custom validator file(s) is custom validators could use any file name or have multiple files. But to make the automation simple I'd choose a static filename and everything can be put in there, that will make it similar to #190 in that we just need to deploy 1 file to shared, link it the right location and add the config to |
I'm kind of on the fence about it being a single file since it deviates from what Tyler and I discussed previously, so I'm postponing my review for it for a bit to give some time for Tyler (or anyone else who already use custom validators through external tasks) to pitch in their thoughts. |
I think a single file is probably fine. I could see a scenario where someone has a LOT (15+) of custom validator classes and would want to organize them into separate files, but I suspect that would be more rare. |
I've been thinking the way to use these is source: This is the same pattern I used with I could change this to a list of files, update the readme to use a subdir so it is clear they are netbox files and not something else and then use
edit: I'm only going to make this change if it is requested |
A single file is okay. I don't personally use custom validators myself so didn't really have any idea how involved real world setups may or may not be, so wanted to defer my judgement to someone who has. |
I put all my validators in a single file because there are shared functions and this way I don't need to stuff around with getting the import right too. Also means I can be lazy with my ide setup (aka, none) :) |
This patch was also tested with built in custom validators as well as the file based ones, the config deploy'd correctly for both.
|
I did notice your use of |
I propose adding support for
Custom Validators
using the dotted path configuration method so users can still take advantage of the Dynamic Configuration support.I'm already working on a branch to develop this but wanted to get an issue in place.
The text was updated successfully, but these errors were encountered: