- def __lldp_find_neighbor(self, tlv_name=None, tlv_value=None):
- """Returns a list of dicts where a mathing LLDP neighbor has been found
- Each dict has:
- switch -> switch name
- interface -> switch interface
- """
- r = []
- lldp_info = {}
-
- # Get LLDP info from each switch
- for s in self.s_api:
- result = self.s_api[s].run("show lldp neighbors detail")
- lldp_info[s] = result[0]["lldpNeighbors"]
- # Look LLDP match on each interface
- # Note that eAPI returns [] for an interface with no LLDP neighbors
- # in the corresponding interface lldpNeighborInfo field
- for interface in lldp_info[s]:
- if lldp_info[s][interface]["lldpNeighborInfo"]:
- lldp_nInf = lldp_info[s][interface]["lldpNeighborInfo"][0]
- if tlv_name in lldp_nInf:
- if lldp_nInf[tlv_name] == tlv_value:
- r.append({"name": s, "interface": interface})
-
- return r
-
- def __get_switch_asn(self, switch):
- """Returns switch ASN in default VRF
- """
- bgp_info = self.s_api[switch].run("show ip bgp summary")[0]
- return(bgp_info["vrfs"]["default"]["asn"])
-
- def __get_switch_po(self, switch, interface=None):
- """Returns Port-Channels for a given interface
- If interface is None returns a list with all PO interfaces
- Note that if specified, interface should be exact name
- for instance: Ethernet3 and not e3 eth3 and so on
- """
- po_inf = self.s_api[switch].run("show port-channel")[0]["portChannels"]
-
- if interface:
- r = [x for x in po_inf if interface in po_inf[x]["activePorts"]]
- else:
- r = po_inf
-
- return r
-
- def __get_switch_interface_ip(self, switch, interface=None):
- """Returns interface primary ip
- interface should be exact name
- for instance: Ethernet3 and not ethernet 3, e3 eth3 and so on
- """
- cmd = "show ip interface {}".format(interface)
- ip_info = self.s_api[switch].run(cmd)[0]["interfaces"][interface]
-
- ip = ip_info["interfaceAddress"]["primaryIp"]["address"]
- mask = ip_info["interfaceAddress"]["primaryIp"]["maskLen"]
-
- return "{}/{}".format(ip, mask)
-