- self.logger.debug("Using Arista Leaf switch: {} {} {}".format(
- s,
- self.switches[s]["ip"],
- self.switches[s]["usr"]))
- if self.is_valid_destination(self.switches[s]["ip"]):
- self.s_api[s] = AristaSwitch(host=self.switches[s]["ip"],
- user=self.switches[s]["usr"],
- passwd=self.switches[s]["passwd"],
- logger=self.logger)
-
- 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)
+ for device in self.allDeviceFacts:
+ if device['hostname'] == s:
+ if not self.switches[s].get('ip'):
+ self.switches[s]['ip'] = device['ipAddress']
+ self.switches[s]['serialNumber'] = device['serialNumber']
+ break
+
+ # Each switch has a different loopback address,
+ # so it's a different configLet
+ if not self.switches[s].get('lo0'):
+ self.switches[s]["lo0"] = self.__get_interface_ip(self.switches[s]['serialNumber'], self.__LOOPBACK_INTF)
+ if not self.switches[s].get('AS'):
+ self.switches[s]["AS"] = self.__get_device_ASN(self.switches[s]['serialNumber'])
+ self.logger.debug("Using Arista Leaf switches: {}".format(
+ self.delete_keys_from_dict(self.switches, ('passwd',))))