summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2016-09-04 09:21:28 -0400
committerGitHub <noreply@github.com>2016-09-04 09:21:28 -0400
commit06c76034dc203dac52ddf5cb6b6afc4b484a25af (patch)
tree55fa89d91d4d136c4b4a3383072bea6ec355bc06
parent1b1c1fe992373749d56c59993c3db4d5658d4e8d (diff)
parenta40515524f3f243a35aaa4ded8c5725f80d43f71 (diff)
downloadansible-06c76034dc203dac52ddf5cb6b6afc4b484a25af.tar.gz
Merge pull request #17385 from privateip/shell
minor optimizations and clean up in shell.py
-rw-r--r--lib/ansible/module_utils/shell.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/lib/ansible/module_utils/shell.py b/lib/ansible/module_utils/shell.py
index 1094601f40..a2738d481d 100644
--- a/lib/ansible/module_utils/shell.py
+++ b/lib/ansible/module_utils/shell.py
@@ -135,11 +135,7 @@ class Shell(object):
window = self.strip(recv.read())
if hasattr(cmd, 'prompt') and not handled:
- if self.handle_prompt(window, prompt=cmd.prompt, response=cmd.response):
- handled = True
- time.sleep(cmd.delay)
- if cmd.is_reboot:
- return
+ handled = self.handle_prompt(window, cmd)
try:
if self.find_prompt(window):
@@ -167,18 +163,15 @@ class Shell(object):
def close(self):
self.shell.close()
- def handle_prompt(self, resp, prompt, response):
- if not prompt or not response:
- return
-
- prompt = to_list(prompt)
- response = to_list(response)
+ def handle_prompt(self, resp, cmd):
+ prompt = to_list(cmd.prompt)
+ response = to_list(cmd.response)
for pr, ans in zip(prompt, response):
match = pr.search(resp)
if match:
- cmd = '%s\r' % ans
- self.shell.sendall(cmd)
+ answer = '%s\r' % ans
+ self.shell.sendall(answer)
return True
def sanitize(self, cmd, resp):
@@ -215,7 +208,7 @@ class CliBase(object):
self._connected = False
self.default_output = 'text'
- def connect(self, params, kickstart=True, **kwargs):
+ def connect(self, params, kickstart=True):
host = params['host']
port = params.get('port') or 22
@@ -242,7 +235,7 @@ class CliBase(object):
self._connected = True
- def disconnect(self, **kwargs):
+ def disconnect(self):
self.shell.close()
self._connected = False
@@ -251,22 +244,25 @@ class CliBase(object):
### Command methods ###
- def execute(self, commands, **kwargs):
+ def execute(self, commands):
try:
return self.shell.send(commands)
except ShellError:
exc = get_exception()
raise NetworkError(exc.message, commands=commands)
- def run_commands(self, commands, **kwargs):
+ def run_commands(self, commands):
return self.execute(to_list(commands))
### Config methods ###
- def load_config(self, commands, **kwargs):
+ def configure(self, commands):
+ raise NotImplementedError
+
+ def get_config(self, commands):
raise NotImplementedError
- def replace_config(self, commands, **kwargs):
+ def load_config(self, commands):
raise NotImplementedError
def save_config(self):