Skip to content

Commit

Permalink
Use json version instead of text
Browse files Browse the repository at this point in the history
  • Loading branch information
bewing committed May 1, 2020
1 parent 692fdf5 commit e28ac71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
24 changes: 3 additions & 21 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,6 @@ class EOSDriver(NetworkDriver):
re.VERBOSE,
)

def _determine_syntax_version(self, ver_output):
"""
Determine cli syntax version from "sh ver" output
Syntax versions:
1: all EOS versions before 4.23.0
2: all EOS version 4.23.0 and higher
:param ver_output: list of lines for "sh ver" command output
:return: int: cli version
"""
regexp = re.compile(r"^Software image version:\s+(?P<version>\d+\.\d+\.\d+)")

for line in ver_output.split("\n"):
m = regexp.match(line)

if m and EOSVersion(m.group("version")) >= EOSVersion("4.23.0"):
return 2

return 1

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""
Initialize EOS Driver.
Expand Down Expand Up @@ -181,8 +162,9 @@ def open(self):
# does not raise an Exception if unusable

# let's try to determine if we need to use new EOS cli syntax
cli_version = self._determine_syntax_version(
self.device.run_commands(["show version"], encoding="text")[0]["output"]
sh_ver = self.device.run_commands(["show version"])
cli_version = (
2 if EOSVersion(sh_ver[0]["version"]) >= EOSVersion("4.23.0") else 1
)

self.device.update_cli_version(cli_version)
Expand Down
16 changes: 16 additions & 0 deletions test/eos/mocked_data/show_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"memTotal": 3954980,
"uptime": 200478.31,
"modelName": "DCS-7150S-64-CL-R",
"internalVersion": "4.21.8M-2GB-13902577.4218M",
"mfgName": "Arista",
"serialNumber": "JPE00000000",
"systemMacAddress": "00:1c:73:00:00:00",
"bootupTimestamp": 1588135848.0,
"memFree": 2558364,
"version": "4.21.8M-2GB",
"architecture": "i386",
"isIntlVersion": false,
"internalBuildId": "5af75062-ded5-4c99-8f44-daa88aa4414d",
"hardwareRevision": "01.03"
}
13 changes: 0 additions & 13 deletions test/eos/mocked_data/show_version.text

This file was deleted.

0 comments on commit e28ac71

Please sign in to comment.