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

Can one use Netbox inventory plugin with Nornir in net-api? #28

Open
wdennis opened this issue Aug 28, 2020 · 6 comments
Open

Can one use Netbox inventory plugin with Nornir in net-api? #28

wdennis opened this issue Aug 28, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@wdennis
Copy link

wdennis commented Aug 28, 2020

Took a look at this project, is interesting as I'm using Nornir to do network automation, and want to progress to front-ending it. However, taking a look at net.py, it looks like the get_nr() function only allows Nornir "simple inventory"... As I already have all my network devices in Netbox, and that has an inventory plugin for Nornir, is using Netbox inventory a possibility with this project?

@wdennis wdennis changed the title Can one use Netbox inventory plugin with Nornir? Can one use Netbox inventory plugin with Nornir in net-api? Aug 28, 2020
@writememe
Copy link
Owner

Hi @wdennis,

It's technically possible. All that function needs to return is the nr object. You could write a second function named get_nb_nr() and make sure it returns the object in the similar way.

I haven't used the netbox inventory plugin before, so perhaps you could share some code or an example?

@writememe
Copy link
Owner

Hi @wdennis,

Just following up on whether you wanted to share some code so I can take a look?

@wdennis
Copy link
Author

wdennis commented Sep 9, 2020

@writememe Sorry for late reply, been busy + holiday time here...
</excuse>

Example of my InitNornir invocation and the associated config file:

nr = InitNornir(
    config_file="config_nb_network_switches.yaml",
    dry_run=False,
)
nr.inventory.defaults.username = "superuser"
nr.inventory.defaults.password = "5uper53cre7"

config_nb_network_switches.yaml:

---
core:
    num_workers: 20
inventory:
    plugin: nornir.plugins.inventory.netbox.NBInventory
    options:
        nb_url: "http://netbox.mycompany.com"
        nb_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        use_slugs: True
        flatten_custom_fields: True
        filter_parameters:
            'role': ["core-switch", "distribution-switch", "access-switch", "transit-switch", "management-switch"]

This against Nornir 2.4.0; please note that the impending Nornir 3.0.0 will change things in regards to both the way plugins works, as well as the Netbox inventory plugin itself -- see:

@writememe
Copy link
Owner

Hi @wdennis all good mate, so am I :). I'm going to create a branch and work out what changes are needed to uplift the code to support nornir 3. When that's done and working, perhaps we can look at the new netbox plugin then?

@writememe writememe added the enhancement New feature or request label Sep 17, 2020
@wdennis
Copy link
Author

wdennis commented Sep 17, 2020 via email

@writememe
Copy link
Owner

Hi @wdennis, just finished the nornir 3 refactor now. If you pull the latest version of the code, you should be able to work from that now.

Haven't used netbox much to be honest, but I'm guessing it just need another get_nr function similar to line 97:

def get_nr():

With the netbox plugin in it? What are you thinking?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants