wvandeun/nornir_netbox

How to handle virtual chassis

andershagman opened this issue · 4 comments

A typical setup is that the DNS name is the virtual chassis (VC) and the individual switches have a sw1, sw2... added to the switch name.
The inventory is on the devices and not on VC. This make nornir to ssh to switches that does not exist.

Ex:
VC: vsh07-41-l2-a -> switches: vsh07-41-l2-a sw1, vsh07-41-l2-a sw2 ...

Could you clarify which Netbox version you are using?

I use both 2.11.12 and 3.2.4 and it does not matter.
The virtual chassis is the same.

So you have virtual-chassis defined, and the name of the vc represents the FQDN that you want to connect to?
The devices that should are part of the stack should be ignored? Is that what you are asking for?

Yes

The most common scenario that I have encountered is that people define the management IP address of the vc on the
member that is performing the master role in the vc.

Yes, that is usually the case.

You can then filter the inventory from devices that are in a vc, but are not the master.
Would that work for you?

I can filter on belong to vc, but there is no master YES/NO flag. The master key points to the master name.
I have to filter out when the inventory name is not eq master name.

ex:
.filter(F(name__eq=inventory['hosts'][NAME]['data']['virtual_chassis']['master']['name']))
But how do I get the var NAME right? NAME = name

Something like this should work:

def remove_vc_non_master(host):
    if not host.get("virtual_chassis", None):
        return True
    elif host["virtual_chassis"]["master"]["name"] == host.name:
        return True
    return False

nr = nr.filter(filter_func=remove_vc_non_master)