wvandeun / nornir_netbox

NetBox plugin for Nornir
Apache License 2.0
69 stars 17 forks source link

How to handle virtual chassis #42

Closed andershagman closed 2 years ago

andershagman commented 2 years ago

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 ...

wvandeun commented 2 years ago

Could you clarify which Netbox version you are using?

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?

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.

You can then filter the inventory from devices that are in a vc, but are not the master.

Would that work for you?

andershagman @.***> writes:

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 ...

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

andershagman commented 2 years ago

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

wvandeun commented 2 years ago

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)
andershagman commented 2 years ago

Hi

That’s what I did. Found an example of a self made filter and could do the needed logic.

Tanks

MHV /Anders Hagman

29 juli 2022 kl. 17:09 skrev Wim Van Deun @.***>:

 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) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.