Skip to content
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

Add use_napalm parameter to NetBoxInventory2 #27

Merged
merged 7 commits into from
Apr 13, 2021

Conversation

johanek
Copy link
Contributor

@johanek johanek commented Mar 10, 2021

Allow the use of napalm_driver value from the device platform to set the platform value

This could resolve #22

I wasn't certain how to deal with the priority of use_platform_slug or use_napalm, so I defaulted to use_platform_slug "winning".


self.session = requests.Session()
self.session.headers.update({"Authorization": f"Token {nb_token}"})
self.session.verify = ssl_verify

def load(self) -> Inventory:

platforms: List[Dict[str, Any]] = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fence this with a if use_napalm. This shouldn't be called if there is no intention for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, updated

@wvandeun
Copy link
Owner

Thx for the work on this.
Haven't had to time yet to look into this.

We could argue that both arguments can't be "True" at the same time and raise an exception?
I'll (try to) have a better look at this, this weekend.

@johanek
Copy link
Contributor Author

johanek commented Mar 22, 2021

We could argue that both arguments can't be "True" at the same time and raise an exception?

That sounds good to me - if it's what you think best I'll implement it and also update the README to explain the behaviour

@@ -256,6 +266,10 @@ def load(self) -> Inventory:

if isinstance(device["platform"], dict) and self.use_platform_slug:
platform = device["platform"].get("slug")
elif isinstance(device["platform"], dict) and self.use_napalm:
platform = [
d for d in platforms if device["platform"]["slug"] == d["slug"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pick a better var name than d. platform makes a lot of sens to me.

README.md Outdated
@@ -107,6 +107,8 @@ Arguments:
(defaults to False)
use_platform_slug: Use the NetBox platform slug for the platform attribute of a Host
(defaults to False)
use_napalm: Use the Netbox platform napalm driver setting for the platform attribute
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the option to use_platform_napalm_driver. It better describes what the option exactly does

@wvandeun
Copy link
Owner

wvandeun commented Apr 5, 2021

We could argue that both arguments can't be "True" at the same time and raise an exception?

That sounds good to me - if it's what you think best I'll implement it and also update the README to explain the behaviour

Yes, the should be "mutually exclusive". It doesn't make sense for them to be True at the same time and we should raise.
We will also need a testcase and the documentation needs to be updated.

@johanek
Copy link
Contributor Author

johanek commented Apr 6, 2021

Thanks for the review suggestions - I made the changes as requested.

The tests are failing on something unrelated - I also have some changes to update python versions and package dependencies which shows the tests passing, but I wanted to keep that change separate so as not to pollute this PR:

https://github.com/vdltech/nornir_netbox/compare/develop...vdltech:feature/fix-tests?expand=1

@wvandeun
Copy link
Owner

wvandeun commented Apr 12, 2021

Can you rebase on develop branch? That should fix the tests.

The last piece I see missing is documentation:
https://github.com/wvandeun/nornir_netbox/blob/develop/docs/usage.md#configuration-options

@johanek
Copy link
Contributor Author

johanek commented Apr 13, 2021

Can you rebase on develop branch? That should fix the tests.

The last piece I see missing is documentation:
https://github.com/wvandeun/nornir_netbox/blob/develop/docs/usage.md#configuration-options

Hi, both are done 👍

@wvandeun wvandeun merged commit 5428547 into wvandeun:develop Apr 13, 2021
@wvandeun
Copy link
Owner

LGTM! Thx

@johanek
Copy link
Contributor Author

johanek commented Apr 15, 2021

Nice one! Thank you for the project, it's really useful 👍

@wvandeun wvandeun mentioned this pull request Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Give the ability to use Napalm driver as the platform rather than the actual platform name or slug
2 participants