Skip to content

Commit

Permalink
Merge branch 'develop' into commit_confirm_eos
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Sep 12, 2020
2 parents a4503ca + 49554bb commit 1851336
Show file tree
Hide file tree
Showing 31 changed files with 6,941 additions and 46 deletions.
2 changes: 1 addition & 1 deletion napalm/base/constants.py
Expand Up @@ -64,7 +64,7 @@
"nxos_ssh": "cisco_nxos",
"iosxr": "cisco_iosxr",
"eos": "arista_eos",
"junos": "juniper_eos",
"junos": "juniper_junos",
}
LLDP_CAPAB_TRANFORM_TABLE = {
"o": "other",
Expand Down
15 changes: 14 additions & 1 deletion napalm/eos/eos.py
Expand Up @@ -1013,7 +1013,7 @@ def get_arp_table(self, vrf=""):
interface = str(neighbor.get("interface"))
mac_raw = neighbor.get("hwAddress")
ip = str(neighbor.get("address"))
age = float(neighbor.get("age"))
age = float(neighbor.get("age", -1.0))
arp_table.append(
{
"interface": interface,
Expand Down Expand Up @@ -2037,3 +2037,16 @@ def ping(
)
ping_dict["success"].update({"results": results_array})
return ping_dict

def get_vlans(self):
command = ["show vlan"]
output = self.device.run_commands(command, encoding="json")[0]["vlans"]

vlans = {}
for vlan, vlan_config in output.items():
vlans[vlan] = {
"name": vlan_config["name"],
"interfaces": list(vlan_config["interfaces"].keys()),
}

return vlans
2 changes: 2 additions & 0 deletions napalm/eos/utils/cli_syntax.py
Expand Up @@ -92,6 +92,7 @@
"show dot1x all brief": "show dot1x all summary",
"show system environment all": "show environment all",
"show system environment cooling": "show environment cooling",
"show system environment temperature": "show environment temperature",
"show interfaces hardware": "show interfaces capabilities",
"show interfaces flow-control": "show interfaces flowcontrol",
"show pvlan mapping interfaces": "show interfaces private-vlan mapping",
Expand Down Expand Up @@ -244,6 +245,7 @@
"show dot1x all summary": "show dot1x all brief",
"show environment all": "show system environment all",
"show environment cooling": "show system environment cooling",
"show environment temperature": "show system environment temperature",
"show interfaces capabilities": "show interfaces hardware",
"show interfaces flowcontrol": "show interfaces flow-control",
"show interfaces private-vlan mapping": "show pvlan mapping interfaces",
Expand Down
40 changes: 28 additions & 12 deletions napalm/ios/ios.py
Expand Up @@ -88,6 +88,7 @@
RE_BGP_REMOTE_AS = re.compile(r"remote AS (" + ASN_REGEX + r")")
RE_BGP_AS_PATH = re.compile(r"^[ ]{2}([\d\(]([\d\) ]+)|Local)")

RE_RP_ROUTE = re.compile(r"Routing entry for (" + IP_ADDR_REGEX + r"\/\d+)")
RE_RP_FROM = re.compile(r"Known via \"([a-z]+)[ \"]")
RE_RP_VIA = re.compile(r"via (\S+)")
RE_RP_METRIC = re.compile(r"[ ]+Route metric is (\d+)")
Expand Down Expand Up @@ -2322,7 +2323,7 @@ def get_arp_table(self, vrf=""):

try:
if age == "-":
age = 0
age = -1
age = float(age)
except ValueError:
raise ValueError("Unable to convert age value to float: {}".format(age))
Expand Down Expand Up @@ -2696,18 +2697,22 @@ def process_mac_fields(vlan, mac, mac_type, interface):

def get_probes_config(self):
probes = {}

probes_regex = (
r"ip\s+sla\s+(?P<id>\d+)\n"
r"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*\n).*"
r"\s+tag\s+(?P<name>\S+)\n.*"
r"\s+history\s+buckets-kept\s+(?P<probe_count>\d+)\n.*"
r"\s+frequency\s+(?P<interval>\d+)$"
r"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*)\n"
r"\s+tag\s+(?P<name>[\S ]+)\n"
r"(\s+.*\n)*"
r"((\s+frequency\s+(?P<interval0>\d+)\n(\s+.*\n)*\s+history"
r"\s+buckets-kept\s+(?P<probe_count0>\d+))|(\s+history\s+buckets-kept"
r"\s+(?P<probe_count1>\d+)\n.*\s+frequency\s+(?P<interval1>\d+)))"
)

probe_args = {
"icmp-echo": r"^(?P<target>\S+)\s+source-(?:ip|interface)\s+(?P<source>\S+)$"
}
probe_type_map = {"icmp-echo": "icmp-ping"}
command = "show run | include ip sla [0-9]"
command = "show run | section ip sla [0-9]"
output = self._send_command(command)
for match in re.finditer(probes_regex, output, re.M):
probe = match.groupdict()
Expand All @@ -2723,8 +2728,8 @@ def get_probes_config(self):
"probe_type": probe_type_map[probe["probe_type"]],
"target": probe_data["target"],
"source": probe_data["source"],
"probe_count": int(probe["probe_count"]),
"test_interval": int(probe["interval"]),
"probe_count": int(probe["probe_count0"] or probe["probe_count1"]),
"test_interval": int(probe["interval0"] or probe["interval1"]),
}
}

Expand Down Expand Up @@ -2773,7 +2778,7 @@ def _get_bgp_route_attr(self, destination, vrf, next_hop, ip_version=4):

search_re_dict = {
"aspath": {
"re": r"[^|\\n][ ]{2}([\d\(\)]([\d\(\) ])*)",
"re": r"[^|\\n][ ]{2}([\d\(\)]([\d\(\) ])*|Local)",
"group": 1,
"default": "",
},
Expand Down Expand Up @@ -2947,8 +2952,11 @@ def get_route_to(self, destination="", protocol="", longer=False):
vrfs.append("default") # global VRF
ipnet_dest = IPNetwork(destination)
prefix = str(ipnet_dest.network)
netmask = str(ipnet_dest.netmask)
routes = {destination: []}
netmask = ""
routes = {}
if "/" in destination:
netmask = str(ipnet_dest.netmask)
routes = {destination: []}
commands = []
for _vrf in vrfs:
if _vrf == "default":
Expand All @@ -2969,6 +2977,14 @@ def get_route_to(self, destination="", protocol="", longer=False):
for (outitem, _vrf) in zip(output, vrfs): # for all VRFs
route_proto_regex = RE_RP_FROM.search(outitem)
if route_proto_regex:
route_match = destination
if netmask == "":
# Get the matching route for a non-exact lookup
route_match_regex = RE_RP_ROUTE.search(outitem)
if route_match_regex:
route_match = route_match_regex.group(1)
if route_match not in routes:
routes[route_match] = []
# routing protocol name (bgp, ospf, ...)
route_proto = route_proto_regex.group(1)
rdb = outitem.split("Routing Descriptor Blocks:")
Expand Down Expand Up @@ -3037,7 +3053,7 @@ def get_route_to(self, destination="", protocol="", longer=False):
nh_line_found = (
False # for next RT entry processing ...
)
routes[destination].append(route_entry)
routes[route_match].append(route_entry)
return routes

def get_snmp_information(self):
Expand Down
39 changes: 27 additions & 12 deletions napalm/iosxr/iosxr.py
Expand Up @@ -41,6 +41,7 @@
from napalm.base.exceptions import CommandTimeoutException

logger = logging.getLogger(__name__)
IP_RIBRoute = "IP_RIBRoute"


class IOSXRDriver(NetworkDriver):
Expand Down Expand Up @@ -1169,13 +1170,13 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
vrf_keepalive = napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
instance_active_list, "GlobalProcessInfo/VRF/KeepAliveTime"
vrf_tree, "GlobalProcessInfo/VRF/KeepAliveTime"
),
)
vrf_holdtime = napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
instance_active_list, "GlobalProcessInfo/VRF/HoldTime"
vrf_tree, "GlobalProcessInfo/VRF/HoldTime"
),
)
if vrf_name not in bgp_neighbors_detail.keys():
Expand Down Expand Up @@ -1402,7 +1403,7 @@ def get_arp_table(self, vrf=""):
str, napalm.base.helpers.find_txt(arp_entry, ".//Address")
)
age = napalm.base.helpers.convert(
float, napalm.base.helpers.find_txt(arp_entry, ".//Age"), 0.0
float, napalm.base.helpers.find_txt(arp_entry, ".//Age"), -1.0
)
mac_raw = napalm.base.helpers.find_txt(arp_entry, ".//HardwareAddress")

Expand Down Expand Up @@ -1641,6 +1642,7 @@ def get_mac_address_table(self):
def get_route_to(self, destination="", protocol="", longer=False):

routes = {}
global IP_RIBRoute

if not isinstance(destination, str):
raise TypeError("Please specify a valid destination!")
Expand Down Expand Up @@ -1672,32 +1674,45 @@ def get_route_to(self, destination="", protocol="", longer=False):
"<Get><Operational><IPV6_RIB><VRFTable><VRF><Naming><VRFName>"
"default</VRFName></Naming><AFTable><AF><Naming><AFName>IPv6</AFName></Naming>"
"<SAFTable>"
"<SAF><Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute>"
"<SAF><Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><{ipribroute}>"
"<Naming>"
"<RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming>"
"<Address>"
"{network}</Address>{prefix}</Naming></Route></RouteTable></IP_RIBRoute>"
"{network}</Address>{prefix}</Naming></Route></RouteTable></{ipribroute}>"
"</IP_RIBRouteTable></SAF></SAFTable></AF></AFTable></VRF></VRFTable></IPV6_RIB>"
"</Operational></Get>"
).format(network=network, prefix=prefix_tag)
).format(network=network, prefix=prefix_tag, ipribroute=IP_RIBRoute)
else:
route_info_rpc_command = (
"<Get><Operational><RIB><VRFTable><VRF><Naming><VRFName>"
"default"
"</VRFName></Naming><AFTable><AF><Naming><AFName>IPv4</AFName></Naming>"
"<SAFTable><SAF>"
"<Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute>"
"<Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><{ipribroute}>"
"<Naming>"
"<RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming>"
"<Address>"
"{network}</Address>{prefix}</Naming></Route></RouteTable></IP_RIBRoute>"
"{network}</Address>{prefix}</Naming></Route></RouteTable></{ipribroute}>"
"</IP_RIBRouteTable>"
"</SAF></SAFTable></AF></AFTable></VRF></VRFTable></RIB></Operational></Get>"
).format(network=network, prefix=prefix_tag)
).format(network=network, prefix=prefix_tag, ipribroute=IP_RIBRoute)

routes_tree = ETREE.fromstring(
self.device.make_rpc_call(route_info_rpc_command)
)
try:
routes_tree = ETREE.fromstring(
self.device.make_rpc_call(route_info_rpc_command)
)
except Exception:
pass
# Some versions of IOS-XR use IP_RIBRouteTableName instead of IP_RIBRoute.
# If IP_RIBRoute throws an exception, try again with IP_RIBRouteTableName
# and have subsequent get_route_to calls use that.
IP_RIBRoute = "IP_RIBRouteTableName"
route_info_rpc_command = route_info_rpc_command.replace(
"IP_RIBRoute>", "{ipribroute}>".format(ipribroute=IP_RIBRoute)
)
routes_tree = ETREE.fromstring(
self.device.make_rpc_call(route_info_rpc_command)
)

for route in routes_tree.xpath(".//Route"):
route_protocol = napalm.base.helpers.convert(
Expand Down
97 changes: 97 additions & 0 deletions napalm/nxos_ssh/nxos_ssh.py
Expand Up @@ -1641,3 +1641,100 @@ def get_optics(self):
optics_detail[port] = port_detail

return optics_detail

def get_interfaces_counters(self):
"""
Return interface counters and errors.
'tx_errors': int,
'rx_errors': int,
'tx_discards': int,
'rx_discards': int,
'tx_octets': int,
'rx_octets': int,
'tx_unicast_packets': int,
'rx_unicast_packets': int,
'tx_multicast_packets': int,
'rx_multicast_packets': int,
'tx_broadcast_packets': int,
'rx_broadcast_packets': int,
"""
if_mapping = {
"eth": {
"regexp": re.compile("^(Ether|port-channel).*"),
"mapping": {
"tx_errors": "eth_outerr",
"rx_errors": "eth_inerr",
"tx_discards": "eth_outdiscard",
"rx_discards": "eth_indiscard",
"tx_octets": "eth_outbytes",
"rx_octets": "eth_inbytes",
"tx_unicast_packets": "eth_outucast",
"rx_unicast_packets": "eth_inucast",
"tx_multicast_packets": "eth_outmcast",
"rx_multicast_packets": "eth_inmcast",
"tx_broadcast_packets": "eth_outbcast",
"rx_broadcast_packets": "eth_inbcast",
},
},
"mgmt": {
"regexp": re.compile("mgm.*"),
"mapping": {
"tx_errors": None,
"rx_errors": None,
"tx_discards": None,
"rx_discards": None,
"tx_octets": "mgmt_out_bytes",
"rx_octets": "mgmt_in_bytes",
"tx_unicast_packets": None,
"rx_unicast_packets": None,
"tx_multicast_packets": "mgmt_out_mcast",
"rx_multicast_packets": "mgmt_in_mcast",
"tx_broadcast_packets": None,
"rx_broadcast_packets": None,
},
},
}
command = "show interface counters detailed | json"
# To retrieve discards
command_interface = "show interface | json"
counters_table_raw = self._get_command_table(
command, "TABLE_interface", "ROW_interface"
)
counters_interface_table_raw = self._get_command_table(
command_interface, "TABLE_interface", "ROW_interface"
)
all_stats_d = {}
# Start with show interface as all interfaces
# Are surely listed
for row in counters_interface_table_raw:
if_counter = {}
# loop through regexp to find mapping
for if_v in if_mapping:
my_re = if_mapping[if_v]["regexp"]
re_match = my_re.match(row["interface"])
if re_match:
interface = re_match.group()
map_d = if_mapping[if_v]["mapping"]
for k, v in map_d.items():
if_counter[k] = int(row[v]) if v in row else 0
all_stats_d[interface] = if_counter
break
print(all_stats_d)

for row in counters_table_raw:
if_counter = {}
# loop through regexp to find mapping
for if_v in if_mapping:
my_re = if_mapping[if_v]["regexp"]
re_match = my_re.match(row["interface"])
if re_match:
interface = re_match.group()
map_d = if_mapping[if_v]["mapping"]
for k, v in map_d.items():
if v in row:
if_counter[k] = int(row[v])
all_stats_d[interface].update(if_counter)
break

return all_stats_d
8 changes: 4 additions & 4 deletions requirements-dev.txt
@@ -1,11 +1,11 @@
black==19.10b0
coveralls==2.1.1
black==20.8b1
coveralls==2.1.2
ddt==1.4.1
flake8-import-order==0.18.1
pytest==5.4.3
pytest-cov==2.10.0
pytest-cov==2.10.1
pytest-json==0.4.0
pytest-pythonpath==0.7.3
pylama==7.7.1
mock==4.0.2
tox==3.18.1
tox==3.20.0
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -12,16 +12,18 @@

setup(
name="napalm",
version="3.1.0",
version="3.2.0",
packages=find_packages(exclude=("test*",)),
test_suite="test_base",
author="David Barroso, Kirk Byers, Mircea Ulinic",
author_email="dbarrosop@dravetech.com, ping@mirceaulinic.net, ktbyers@twb-tech.com",
description="Network Automation and Programmability Abstraction Layer with Multivendor support",
license="Apache 2.0",
long_description=long_description,
long_description_content_type="text/markdown",
classifiers=[
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
Expand Down
@@ -0,0 +1 @@
[{"interface": "Ethernet45", "ip": "172.17.17.1", "mac": "DC:38:E1:11:97:CF", "age": -1.0}, {"interface": "Ethernet36", "ip": "172.17.17.1", "mac": "90:E2:BA:5C:25:FD", "age": 0.0}]

0 comments on commit 1851336

Please sign in to comment.