From d211b4c9623474284540d880f703c03cf3a27444 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 13 Mar 2016 16:06:25 -0700 Subject: [PATCH] feature to implement localized cli prompts to eos This change localizes the cli prompt regexps to the eos shared module instead of the common prompts implemented in shell --- lib/ansible/module_utils/eos.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index 41dfbaeadd3..37e62a4de27 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -31,6 +31,23 @@ NET_COMMON_ARGS = dict( provider=dict(type='dict') ) +CLI_PROMPTS_RE = [ + re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"), + re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$") +] + +CLI_ERRORS_RE = [ + re.compile(r"% ?Error"), + re.compile(r"^% \w+", re.M), + re.compile(r"% ?Bad secret"), + re.compile(r"invalid input", re.I), + re.compile(r"(?:incomplete|ambiguous) command", re.I), + re.compile(r"connection timed out", re.I), + re.compile(r"[^\r\n]+ not found", re.I), + re.compile(r"'[^']' +returned error code: ?\d+"), + re.compile(r"[^\r\n]\/bin\/(?:ba)?sh") +] + def to_list(val): if isinstance(val, (list, tuple)): return list(val) @@ -123,9 +140,8 @@ class Cli(object): username = self.module.params['username'] password = self.module.params['password'] - self.shell = Shell() - try: + self.shell = Shell(CLI_PROMPTS_RE, CLI_ERRORS_RE) self.shell.open(host, port=port, username=username, password=password) except Exception, exc: msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc))