Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic authored Nov 29, 2021
2 parents e9e1f6e + 320d9d2 commit 63249db
Show file tree
Hide file tree
Showing 44 changed files with 2,595 additions and 241 deletions.
2 changes: 1 addition & 1 deletion docs/support/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ____________________________________
* :code:`secret` (ios, nxos_ssh) - Password required to enter privileged exec (enable) (default: ``''``).
* :code:`ssh_config_file` (ios, iosxr, junos, nxos_ssh) - File name of OpenSSH configuration file.
* :code:`ssh_strict` (ios, iosxr, nxos_ssh) - Automatically reject unknown SSH host keys (default: ``False``, which means unknown SSH host keys will be accepted).
* :code:`ssl_verify` (nxos) - Requests argument, enable the SSL certificates verification. See requests ssl-cert-verification for valide values (default: ``None`` equivalent to ``False``).
* :code:`ssl_verify` (nxos) - Requests argument, enable the SSL certificates verification. See requests ssl-cert-verification for valid values (default: ``None`` equivalent to ``False``).
* :code:`transport` (eos, ios, nxos) - Protocol to connect with (see `The transport argument`_ for more information).
* :code:`use_keys` (ios, iosxr, nxos_ssh) - Paramiko argument, enable searching for discoverable private key files in ``~/.ssh/`` (default: ``False``).
* :code:`eos_autoComplete` (eos) - Allows to set `autoComplete` when running commands. (default: ``None`` equivalent to ``False``)
Expand Down
24 changes: 23 additions & 1 deletion napalm/base/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.merge = None
self.filename = None
self.config = None
self._pending_commits = False

def _count_calls(self, name):
current_count = self.calls.get(name, 0)
Expand Down Expand Up @@ -168,9 +169,14 @@ def compare_config(self, filename=None, config=None):
self._raise_if_closed()
return mocked_data(self.path, "compare_config", count)["diff"]

def commit_config(self):
def commit_config(self, message="", revert_in=None):
count = self._count_calls("commit_config")
self._raise_if_closed()
if revert_in is not None:
if self.has_pending_commit():
raise napalm.CommitError("Pending commit confirm already in process!")
else:
self._pending_commits = True
self.merge = None
self.filename = None
self.config = None
Expand All @@ -184,6 +190,22 @@ def discard_config(self):
self.config = None
mocked_data(self.path, "discard_config", count)

def confirm_commit(self):
count = self._count_calls("confirm_commit")
self._raise_if_closed()
self.merge = None
self.filename = None
self.config = None
self._pending_commits = False
mocked_data(self.path, "confirm_commit", count)

def has_pending_commit(self):
return self._pending_commits

def rollback(self):
self.config_session = None
self._pending_commits = False

def _rpc(self, get):
"""This one is only useful for junos."""
return list(self.cli([get]).values())[0]
Expand Down
2 changes: 1 addition & 1 deletion napalm/base/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"description": str,
"last_flapped": float,
"mtu": int,
"speed": int,
"speed": float,
"mac_address": str,
},
)
Expand Down
7 changes: 6 additions & 1 deletion napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ def get_interfaces(self):
)

interfaces[interface]["mtu"] = int(values["mtu"])
interfaces[interface]["speed"] = int(values["bandwidth"] * 1e-6)
# interfaces[interface]["speed"] = float(values["bandwidth"] * 1e-6)
interfaces[interface]["speed"] = float(values["bandwidth"] / 1000000.0)
interfaces[interface]["mac_address"] = napalm.base.helpers.convert(
napalm.base.helpers.mac, values.pop("physicalAddress", "")
)
Expand Down Expand Up @@ -1005,6 +1006,10 @@ def parse_options(options, default_value=False):
bgp_neighbors[peer_address] = default_neighbor_dict(local_as)
if options[0] == "peer-group":
bgp_neighbors[peer_address]["__group"] = options[1]
# EOS > 4.23.0 only supports the new syntax
# https://www.arista.com/en/support/advisories-notices/fieldnotices/7097-field-notice-39
elif options[0] == "peer" and options[1] == "group":
bgp_neighbors[peer_address]["__group"] = options[2]

# in the config, neighbor details are lister after
# the group is specified for the neighbor:
Expand Down
9 changes: 6 additions & 3 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ def get_interfaces(self):
speed = speed / 1000.0
elif speedformat.startswith("Gb"):
speed = speed * 1000
speed = int(round(speed))

if interface == "":
raise ValueError(
Expand Down Expand Up @@ -1303,7 +1302,7 @@ def build_prefix_limit(af_table, limit, prefix_percent, prefix_timeout):
if "ipv6" in af_table.lower():
inet6 = True
preifx_type = "inet6"
if len(af_table.split()) == 2:
if not af_table or len(af_table.split()) == 2:
safi = "unicast"
else:
safi = af_table.split()[-1]
Expand Down Expand Up @@ -1355,7 +1354,11 @@ def build_prefix_limit(af_table, limit, prefix_percent, prefix_timeout):
afi_list = napalm.base.helpers.cisco_conf_parse_parents(
r"\s+address-family.*", bgp_neighbor, bgp_config_text
)
afi = afi_list[0]
try:
afi = afi_list[0]
except IndexError:
afi = ""

# Skipping neighbors in VRFs for now
if "vrf" in str(afi_list):
continue
Expand Down
7 changes: 4 additions & 3 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_interfaces(self):
"is_up": False,
"mac_address": "",
"description": "",
"speed": -1,
"speed": -1.0,
"last_flapped": -1.0,
}

Expand Down Expand Up @@ -252,12 +252,13 @@ def get_interfaces(self):
napalm.base.helpers.mac, raw_mac, raw_mac
)
speed = napalm.base.helpers.convert(
int,
float,
napalm.base.helpers.convert(
int, napalm.base.helpers.find_txt(interface_tree, "Bandwidth"), 0
float, napalm.base.helpers.find_txt(interface_tree, "Bandwidth"), 0
)
* 1e-3,
)

mtu = int(napalm.base.helpers.find_txt(interface_tree, "MTU"))
description = napalm.base.helpers.find_txt(interface_tree, "Description")
interfaces[interface_name] = copy.deepcopy(INTERFACE_DEFAULTS)
Expand Down
13 changes: 5 additions & 8 deletions napalm/iosxr_netconf/iosxr_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def get_interfaces(self):
"is_up": False,
"mac_address": "",
"description": "",
"speed": -1,
"speed": -1.0,
"last_flapped": -1.0,
}

Expand Down Expand Up @@ -489,14 +489,15 @@ def get_interfaces(self):
napalm.base.helpers.mac, raw_mac, raw_mac
)
speed = napalm.base.helpers.convert(
int,
float,
napalm.base.helpers.convert(
int,
float,
self._find_txt(interface_tree, "./int:bandwidth", namespaces=C.NS),
0,
)
* 1e-3,
)

mtu = int(
self._find_txt(interface_tree, "./int:mtu", default="", namespaces=C.NS)
)
Expand Down Expand Up @@ -1855,7 +1856,7 @@ def get_vrf_neighbors_detail(
),
0,
)
connection_down_count = napalm.base.helpers.convert(
flap_count = napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
Expand Down Expand Up @@ -1995,10 +1996,6 @@ def get_vrf_neighbors_detail(
),
0,
)
flap_count = int(connection_down_count / 2)
if up:
flap_count -= 1

if remote_as not in bgp_vrf_neighbors_detail[vrf_name].keys():
bgp_vrf_neighbors_detail[vrf_name][remote_as] = []
bgp_vrf_neighbors_detail[vrf_name][remote_as].append(
Expand Down
26 changes: 19 additions & 7 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def load_merge_candidate(self, filename=None, config=None):

def compare_config(self):
"""Compare candidate config with running."""
diff = self.device.cu.diff()
diff = self.device.cu.diff(ignore_warning=self.ignore_warning)

if diff is None:
return ""
Expand Down Expand Up @@ -384,7 +384,7 @@ def confirm_commit(self):

def discard_config(self):
"""Discard changes (rollback 0)."""
self.device.cu.rollback(rb_id=0)
self.device.cu.rollback(rb_id=0, ignore_warning=self.ignore_warning)
if not self.lock_disable and not self.session_config_lock:
self._unlock()
if self.config_private:
Expand Down Expand Up @@ -449,7 +449,7 @@ def _convert_to_dict(interfaces):
iface_data["mac_address"],
str(iface_data["mac_address"]),
),
"speed": -1,
"speed": -1.0,
"mtu": 0,
}
# result[iface]['last_flapped'] = float(result[iface]['last_flapped'])
Expand All @@ -464,12 +464,13 @@ def _convert_to_dict(interfaces):
)
if match is None:
continue
speed_value = napalm.base.helpers.convert(int, match.group(1), -1)
if speed_value == -1:
speed_value = napalm.base.helpers.convert(float, match.group(1), -1.0)

if speed_value == -1.0:
continue
speed_unit = match.group(2)
if speed_unit.lower() == "gbps":
speed_value *= 1000
speed_value *= 1000.0
result[iface]["speed"] = speed_value

return result
Expand Down Expand Up @@ -909,7 +910,18 @@ def get_lldp_neighbors(self):
for neigh in result:
if neigh[0] not in neighbors.keys():
neighbors[neigh[0]] = []
neighbors[neigh[0]].append({x[0]: str(x[1]) for x in neigh[1]})

neigh_dict = {}
for neigh_data in neigh[1]:
key = neigh_data[0]
value = (
str(neigh_data[1][0])
# When return value is a list of multiple objects, we pick the first one
if neigh_data[1] and isinstance(neigh_data[1], list)
else str(neigh_data[1])
)
neigh_dict[key] = value
neighbors[neigh[0]].append(neigh_dict)

return neighbors

Expand Down
2 changes: 1 addition & 1 deletion napalm/junos/utils/junos_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ junos_lldp_table:
junos_lldp_view:
fields:
hostname: lldp-remote-system-name
port: lldp-remote-port-description | lldp-remote-port-id
port: lldp-remote-port-id | lldp-remote-port-description

####
#### Interface counters
Expand Down
4 changes: 4 additions & 0 deletions napalm/nxapi_plumbing/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requests
from requests.auth import HTTPBasicAuth
from requests.exceptions import ConnectionError
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import json

from lxml import etree
Expand Down Expand Up @@ -60,6 +61,9 @@ def _send_request(self, commands, method):
payload = self._build_payload(commands, method)

try:
if not self.verify:
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

response = requests.post(
self.url,
timeout=self.timeout,
Expand Down
2 changes: 1 addition & 1 deletion napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def get_interfaces(self):
interface_speed = 0
if isinstance(interface_speed, list):
interface_speed = interface_speed[0]
interface_speed = int(int(interface_speed) / 1000)
interface_speed = float(float(interface_speed) / 1000.0)

if "admin_state" in interface_details:
is_up = interface_details.get("admin_state", "") == "up"
Expand Down
27 changes: 15 additions & 12 deletions napalm/nxos_ssh/nxos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def parse_intf_section(interface):
re_is_enabled_2 = r"^admin state is (?P<is_enabled>\S+), "
re_is_enabled_3 = r"^.* is down.*Administratively down.*$"
re_mac = r"^\s+Hardware:\s+(?P<hardware>.*),\s+address:\s+(?P<mac_address>\S+) "
re_speed = (
r"\s+MTU (?P<mtu>\S+)\s+bytes,\s+BW\s+(?P<speed>\S+)\s+(?P<speed_unit>\S+).*$"
)
re_speed = r"\s+(MTU (?P<mtu>\S+)\s+bytes)?,\s+BW\s+(?P<speed>\S+)\s+(?P<speed_unit>\S+).*$"
re_mtu_nve = r"\s+MTU (?P<mtu_nve>\S+)\s+bytes.*$"
re_description_1 = r"^\s+Description:\s+(?P<description>.*) (?:MTU|Internet)"
re_description_2 = r"^\s+Description:\s+(?P<description>.*)$"
Expand Down Expand Up @@ -164,19 +162,20 @@ def parse_intf_section(interface):

if speed_exist:
match = re.search(re_speed, interface, flags=re.M)
speed = int(match.group("speed"))
mtu = int(match.group("mtu"))
speed_unit = match.group("speed_unit")
speed_data = match.groupdict(-1)
speed = float(speed_data["speed"])
mtu = int(speed_data["mtu"])
speed_unit = speed_data["speed_unit"]
speed_unit = speed_unit.rstrip(",")
# This was alway in Kbit (in the data I saw)
if speed_unit != "Kbit":
msg = "Unexpected speed unit in show interfaces parsing:\n\n{}".format(
interface
)
raise ValueError(msg)
speed = int(round(speed / 1000.0))
speed = float(speed / 1000.0)
else:
speed = -1
speed = -1.0

description = ""
for x_pattern in [re_description_1, re_description_2]:
Expand Down Expand Up @@ -686,19 +685,19 @@ def get_interfaces(self):
'is_up': True,
'last_flapped': -1.0,
'mac_address': u'a493.4cc1.67a7',
'speed': 100},
'speed': 100.0},
u'Vlan100': { 'description': u'Data Network',
'is_enabled': True,
'is_up': True,
'last_flapped': -1.0,
'mac_address': u'a493.4cc1.67a7',
'speed': 100},
'speed': 100.0},
u'Vlan200': { 'description': u'Voice Network',
'is_enabled': True,
'is_up': True,
'last_flapped': -1.0,
'mac_address': u'a493.4cc1.67a7',
'speed': 100}}
'speed': 100.0}}
"""
interfaces = {}
command = "show interface"
Expand Down Expand Up @@ -1534,7 +1533,11 @@ def get_vlans(self):
for vlan in vlan_table_raw:
if "vlanshowplist-ifidx" not in vlan.keys():
vlan["vlanshowplist-ifidx"] = []
vlans[vlan["vlanshowbr-vlanid"]] = {
if "vlanshowbr-vlanid-utf" in vlan.keys():
vlan_number = vlan["vlanshowbr-vlanid-utf"]
else:
vlan_number = vlan["vlanshowbr-vlanid"]
vlans[vlan_number] = {
"name": vlan["vlanshowbr-vlanname"],
"interfaces": self._parse_vlan_ports(vlan["vlanshowplist-ifidx"]),
}
Expand Down
12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black==21.5b1
coveralls==3.1.0
ddt==1.4.2
black==21.11b1
coveralls==3.2.0
ddt==1.4.4
flake8-import-order==0.18.1
pytest==5.4.3
pytest-cov==2.12.0
pytest-cov==3.0.0
pytest-json==0.4.0
pytest-pythonpath==0.7.3
pylama==7.7.1
mock==4.0.3
tox==3.23.1
mypy==0.812
tox==3.24.4
mypy==0.910
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jinja2
netaddr
pyYAML
pyeapi>=0.8.2
netmiko>=3.1.0
netmiko>=3.3.0,<4.0.0
junos-eznc>=2.2.1
ciscoconfparse
scp
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm",
version="3.3.0",
version="3.3.1",
packages=find_packages(exclude=("test*",)),
test_suite="test_base",
author="David Barroso, Kirk Byers, Mircea Ulinic",
Expand Down
Loading

0 comments on commit 63249db

Please sign in to comment.