mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Add support for multiple prompt answers in network_cli (#44492)
* Currently network_cli support multiple prompts single answer as response. This PR adds support for multiple answers. * In case of multiple prompts and mulitple answers the index of a particular prompt in the prompts list should match with the index in the answer list.
This commit is contained in:
parent
24c26aded8
commit
e25d8e2b99
2 changed files with 9 additions and 3 deletions
|
@ -404,19 +404,22 @@ class Connection(NetworkConnectionBase):
|
|||
|
||||
:arg resp: Byte string containing the raw response from the remote
|
||||
:arg prompts: Sequence of byte strings that we consider prompts for input
|
||||
:arg answer: Byte string to send back to the remote if we find a prompt.
|
||||
:arg answer: Sequence of Byte string to send back to the remote if we find a prompt.
|
||||
A carriage return is automatically appended to this string.
|
||||
:returns: True if a prompt was found in ``resp``. False otherwise
|
||||
'''
|
||||
if not isinstance(prompts, list):
|
||||
prompts = [prompts]
|
||||
if not isinstance(answer, list):
|
||||
answer = [answer]
|
||||
prompts = [re.compile(r, re.I) for r in prompts]
|
||||
for regex in prompts:
|
||||
for index, regex in enumerate(prompts):
|
||||
match = regex.search(resp)
|
||||
if match:
|
||||
# if prompt_retry_check is enabled to check if same prompt is
|
||||
# repeated don't send answer again.
|
||||
if not prompt_retry_check:
|
||||
answer = answer[index] if len(answer) > index else answer[0]
|
||||
self._ssh_shell.sendall(b'%s' % answer)
|
||||
if newline:
|
||||
self._ssh_shell.sendall(b'\r')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue