mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-05 10:13:09 +00:00
feature to localize prompt search login to iosxr shared module
this localizes the cli prompt search logic to the iosxr shared module instead of using the common regexp list in shell.py
This commit is contained in:
@@ -27,6 +27,21 @@ NET_COMMON_ARGS = dict(
|
||||
provider=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"% ?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+"),
|
||||
]
|
||||
|
||||
def to_list(val):
|
||||
if isinstance(val, (list, tuple)):
|
||||
return list(val)
|
||||
@@ -48,9 +63,9 @@ class Cli(object):
|
||||
username = self.module.params['username']
|
||||
password = self.module.params['password']
|
||||
|
||||
self.shell = Shell()
|
||||
|
||||
try:
|
||||
self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE,
|
||||
errors_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))
|
||||
@@ -98,7 +113,10 @@ class NetworkModule(AnsibleModule):
|
||||
return responses
|
||||
|
||||
def execute(self, commands, **kwargs):
|
||||
return self.connection.send(commands)
|
||||
try:
|
||||
return self.connection.send(commands)
|
||||
except ShellError, exc:
|
||||
self.fail_json(msg=exc.message, command=exc.command)
|
||||
|
||||
def disconnect(self):
|
||||
self.connection.close()
|
||||
|
||||
Reference in New Issue
Block a user