net-api
net-api copied to clipboard
Can one use Netbox inventory plugin with Nornir in net-api?
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?
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?
Hi @wdennis,
Just following up on whether you wanted to share some code so I can take a look?
@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:
- https://github.com/nornir-automation/nornir/issues/486
- https://nornir.readthedocs.io/en/3.0.0/upgrading/2_to_3.html
- https://github.com/wvandeun/nornir_netbox/blob/develop/README.md (see NetBoxInventory2 note)
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?
Sounds good to me, let me know when you are ready...
On Thu, Sep 17, 2020 at 5:57 AM Daniel Teycheney [email protected] wrote:
Hi @wdennis https://github.com/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?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/writememe/net-api/issues/28#issuecomment-694128210, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNDWNLLQ4NBDUP7Z2W5A6DSGHMP7ANCNFSM4QNUWNWA .
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:
https://github.com/writememe/net-api/blob/ed69b1566cb45b9f860d30e35236abbdef898253/app/net.py#L81
With the netbox plugin in it? What are you thinking?