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:
Peter Sprygada 2016-03-13 16:01:58 -07:00
parent 2fa1936ff9
commit 249caac0d3

View file

@ -79,17 +79,15 @@ class Command(object):
class Shell(object):
def __init__(self):
def __init__(self, prompts_re=None, errors_re=None, kickstart=True):
self.ssh = None
self.shell = None
self.kickstart = kickstart
self._matched_prompt = None
self.prompts = list()
self.prompts.extend(CLI_PROMPTS_RE)
self.errors = list()
self.errors.extend(CLI_ERRORS_RE)
self.prompts = prompts_re or CLI_PROMPTS_RE
self.errors = errors_re or CLI_ERRORS_RE
def open(self, host, port=22, username=None, password=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.settimeout(10)
self.shell.sendall("\n")
if self.kickstart:
self.shell.sendall("\n")
self.receive()
def strip(self, data):