Skip to content

Commit 818f820

Browse files
committed
Fix EOS filtering and sanitizing
Ensure best-effort sanitizing of EOS configs (EOS does not support sanitized startup configs out of the box) Resolves #2273
1 parent 33e61ce commit 818f820

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

napalm/base/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@
100100
r"^((tacacs|radius) server [^\n]+\n(\s+[^\n]+\n)*\s+key) [^\n]+$": r"\1 <removed>",
101101
r"^(\s+ppp (chap|pap) password \d) .+$": r"\1 <removed>",
102102
}
103+
104+
EOS_SANITIZE_FILTERS = {
105+
**CISCO_SANITIZE_FILTERS,
106+
r"^(\s+aaa root secret \d) .+$": r"\1 <removed>",
107+
r"^(\s+username .+ (password|secret) \d) .+$": r"\1 <removed>",
108+
}

napalm/eos/eos.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ def get_config(self, retrieve="all", full=False, sanitized=False, format="text")
20852085
startup_cfg = str(output[0]["output"]) if get_startup else ""
20862086
if sanitized and startup_cfg:
20872087
startup_cfg = napalm.base.helpers.sanitize_config(
2088-
startup_cfg, c.CISCO_SANITIZE_FILTERS
2088+
startup_cfg, c.EOS_SANITIZE_FILTERS
20892089
)
20902090
return {
20912091
"startup": startup_cfg,
@@ -2094,17 +2094,28 @@ def get_config(self, retrieve="all", full=False, sanitized=False, format="text")
20942094
}
20952095
elif get_startup or get_running:
20962096
if retrieve == "running":
2097-
commands = ["show {}-config{}".format(retrieve, run_full)]
2097+
commands = [
2098+
"show {}-config{}{}".format(retrieve, run_full, run_sanitized)
2099+
]
20982100
elif retrieve == "startup":
20992101
commands = ["show {}-config".format(retrieve)]
21002102
output = self._run_commands(commands, encoding="text")
2103+
startup_cfg = str(output[0]["output"]) if get_startup else ""
2104+
if sanitized and get_startup and startup_cfg:
2105+
startup_cfg = napalm.base.helpers.sanitize_config(
2106+
startup_cfg, c.EOS_SANITIZE_FILTERS
2107+
)
21012108
return {
2102-
"startup": str(output[0]["output"]) if get_startup else "",
2109+
"startup": startup_cfg,
21032110
"running": str(output[0]["output"]) if get_running else "",
21042111
"candidate": "",
21052112
}
21062113
elif get_candidate:
2107-
commands = ["show session-config named {}".format(self.config_session)]
2114+
commands = [
2115+
"show session-config named {}{}".format(
2116+
self.config_session, run_sanitized
2117+
)
2118+
]
21082119
output = self._run_commands(commands, encoding="text")
21092120
return {"startup": "", "running": "", "candidate": str(output[0]["output"])}
21102121
elif retrieve == "candidate":

0 commit comments

Comments
 (0)