Skip to content

Commit

Permalink
Handle modern memory output from Arista EOS 4.27+
Browse files Browse the repository at this point in the history
Arista EOS 4.27+ (and possibly earlier versions, untested on
4.24-4.26) changes the output from `show processes top once`
command, rendering values decimal numbers of MB instead of integer
numbers of KB, and also reorders the fields.

This commit extends the `get_environment` function with additional
logic to handle the output from both older and newer OS versions.

The memory expressed in MB is converted into KB for backward
compatibility, but because the switch has done some rounding and
displays only a limited number of decimal places, the conversion
into KB will not be exact. There is nothing that Napalm can do
about this.

Fixes #1671
  • Loading branch information
optiz0r committed Jun 15, 2022
1 parent dde6a59 commit 44fcfab
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,16 +846,31 @@ def extract_temperature_data(data):
# Matches either of
# Mem: 3844356k total, 3763184k used, 81172k free, 16732k buffers ( 4.16 > )
# KiB Mem: 32472080 total, 5697604 used, 26774476 free, 372052 buffers ( 4.16 < )
# MiB Mem : 3889.2 total, 150.3 free, 1104.5 used, 2634.4 buff/cache (4.27 < )
mem_regex = (
r"[^\d]*(?P<total>\d+)[k\s]+total,"
r"\s+(?P<used>\d+)[k\s]+used,"
r"\s+(?P<free>\d+)[k\s]+free,.*"
r"^(?:(?P<unit>\S+)\s+)?Mem\s*:"
r"\s+(?P<total>[0-9.]+)[k\s]+total,"
r"(?:\s+(?P<used1>[0-9.]+)[k\s]+used,)?"
r"\s+(?P<free>[0-9.]+)[k\s]+free,"
r"(?:\s+(?P<used2>[0-9.]+)[k\s]+used,)?"
r".*"
)
m = re.match(mem_regex, cpu_lines[3])
environment_counters["memory"] = {
"available_ram": int(m.group("total")),
"used_ram": int(m.group("used")),
}

def _parse_memory(unit, total, used):
if unit == "MiB":
return {
"available_ram": float(total) * 1024,
"used_ram": float(used) * 1024,
}
return {
"available_ram": int(total),
"used_ram": int(used),
}

environment_counters["memory"] = _parse_memory(
m.group("unit"), m.group("total"), m.group("used1") or m.group("used2"))

return environment_counters

def _transform_lldp_capab(self, capabilities):
Expand Down

0 comments on commit 44fcfab

Please sign in to comment.