-
Notifications
You must be signed in to change notification settings - Fork 237
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
Set napalm connection options if they exist in netbox #569
Set napalm connection options if they exist in netbox #569
Conversation
Thanks for the PR! @wvandeun @clay584 would you mind reviewing this? Due to nornir3 release, you will also need to propose the change here: https://github.com/wvandeun/nornir_netbox You can check https://nornir.tech/2020/06/18/nornir-3-beta/ for more details. Thanks again! |
I like the idea, but it also has an issue in my point of view. The idea of that field in NetBox is to specify optional_args for the Napalm driver for NetBox internal usage. The json data is effectively directly passed on to the Napalm driver optional_args attribute. What you implemented works, but could lead to situation where you have to configure the same parameter twice, if you use both the build-in Napalm support for NetBox and Nornir. For example let's say we want to set the login_method for a particular driver. We want that to work for both the NetBox build-in Napalm support & for Nornir. We would have to come up with the following structure in NetBox for that to work:
This doesn't really make sense to me and is going to be very confusing. At some point I had the idea of making a blend of NBInventory & SimpleInventory. The idea is that we would could create a groups.yaml file where you could specify for example connection parameters, based on some attribute. The advantage is that we could support all connection plugins with this and we don't have to misuse the Napalm attributes field of NetBox. The yaml files can be put in version control, you can use a proper edit to create them (linters, ... ) compared to a simple webform in a browser... |
Couple of comments/ideas :) Given that those are meant to be napalm arguments, why not add them as they are meant to be so nb can consume them and have the nornir plugin adapt it for nornir's consumption? For instance, you define:
so it works out of the box in napalm/netbox integration and then in the plugin you assign it under host -> connection options -> napalm That way it'd work as intended and it'd work with nornir as well thanks to the plugin. In addition, you could also abuse that field to pass connection_options (for any driver, based on a dictionary like in SimpleInventory) and add a flag to nb plugin to use this behavior (the one described before being the default behavior). |
Sounds good to me. |
Thank you for the clarification regarding how that field is intended to work with Netbox. Let me revise it per @dbarrosop suggestions. I will also open a similar PR under https://github.com/wvandeun/nornir_netbox for the nornir 3 release as well if all looks good here. |
I revised my platform NAPALM args in netbox to look like:
The end result looks the same as before but only
|
Some other points:
|
1c5bba4
to
b852356
Compare
@wvandeun I think I have the test fixed up and I ended up adding two additional flags that enable this feature as well as another one that "abuses" the netbox napalm args field and passes the results directly to connection_options. As far as additional documentation I am happy to add whatever may be needed beyond the docstrings. Thanks again for your reviews. I squashed my commits on the off chance this is good to go. |
e7e834c
to
ff5f42e
Compare
@wvandeun Reverted to the previous host
So I made a modification that uses |
👍🏻 we may want to add a test case with mock data for a NetBox version that uses that platform data model Why would we introduce 2 flags? One flag to enable both the Napalm and other connection methods should be sufficient I think? |
You could also use a constant or enumeration or whatever instead. Some flag that if you set to |
My read of your previous comment was that you did not want platform options to be pulled from Netbox at all by default, which is why I have two flags here. I guess I misunderstood your request. Personally I would rather just use platform napalm args if they are available (not gated by any flag) then use one flag ( I will also add some additional mock data formatted as we see it newer versions of Netbox. |
So is abusing fields in applications for things they were not supposed to be used for :) Are we suggesting the flags would be mutual exclusive then? If not, how would we handle the case where we pass napalm arguments as intended and when they are defined in the generic nornir way? |
@wvandeun / @dbarrosop can you have another look? I dropped the second flag and opted to use an environment variable since we require this for setting the base netbox url and api key anyway. If one passes Does that work for you both? |
Starting to look good. |
Updated tests. Will take a crack at updating documentation later today. |
So the current docs for the netbox plugin are pretty sparse if dare I say almost non-existent: Wouldn't it look a bit funny to add documentation for this feature I am adding without also adding documentation for the entire plugin, which frankly I do not really have that much time to invest into at this point. Could we consider updating the documentation for this plugin as a separate PR? |
LGTM Would also need you to open a PR with the same changes for NBInventory on https://github.com/wvandeun/nornir_netbox. Agree on the documentation. Fixing it is as simple as moving the docstring from the init method to the class def level. And we would need to add a bit of words on how to use the env var, which is completely missing. But sure I can work on that if you don't have the time. |
aed5bab
to
5e982af
Compare
Thanks. I rebased and squashed everything into a single commit. I'm happy to take on adding similar changes to https://github.com/wvandeun/nornir_netbox. As far as documentation, I can take a pass at that as well under a separate PR. Hopefully I can look at both this week. Thank you again for the reviews. |
It would be beneficial to load napalm optional arguments as connection options based the platform a host is associated with within netbox.
I have a test group called ros (mikrotik) as follows:
With this change we can do something like the following to automatically load these into
host['connection_options']['napalm']
based on the device platform: