mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
feature to allow prompts to be configured at instatiation
This commit adds a new feature to allow implementations of shell to specify the command prompt regexp to be used. It allows adds a new kwarg at instantiation to kick the remote device with a carriage return. By default the kickstart flag is true but can be disabled by passing kickstart=False.
This commit is contained in:
parent
2fa1936ff9
commit
249caac0d3
1 changed files with 8 additions and 7 deletions
|
@ -79,17 +79,15 @@ class Command(object):
|
||||||
|
|
||||||
class Shell(object):
|
class Shell(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, prompts_re=None, errors_re=None, kickstart=True):
|
||||||
self.ssh = None
|
self.ssh = None
|
||||||
self.shell = None
|
self.shell = None
|
||||||
|
|
||||||
|
self.kickstart = kickstart
|
||||||
self._matched_prompt = None
|
self._matched_prompt = None
|
||||||
|
|
||||||
self.prompts = list()
|
self.prompts = prompts_re or CLI_PROMPTS_RE
|
||||||
self.prompts.extend(CLI_PROMPTS_RE)
|
self.errors = errors_re or CLI_ERRORS_RE
|
||||||
|
|
||||||
self.errors = list()
|
|
||||||
self.errors.extend(CLI_ERRORS_RE)
|
|
||||||
|
|
||||||
def open(self, host, port=22, username=None, password=None,
|
def open(self, host, port=22, username=None, password=None,
|
||||||
timeout=10, key_filename=None, pkey=None, look_for_keys=None,
|
timeout=10, key_filename=None, pkey=None, look_for_keys=None,
|
||||||
|
@ -109,7 +107,10 @@ class Shell(object):
|
||||||
|
|
||||||
self.shell = self.ssh.invoke_shell()
|
self.shell = self.ssh.invoke_shell()
|
||||||
self.shell.settimeout(10)
|
self.shell.settimeout(10)
|
||||||
|
|
||||||
|
if self.kickstart:
|
||||||
self.shell.sendall("\n")
|
self.shell.sendall("\n")
|
||||||
|
|
||||||
self.receive()
|
self.receive()
|
||||||
|
|
||||||
def strip(self, data):
|
def strip(self, data):
|
||||||
|
|
Loading…
Reference in a new issue