enabled initial support for password prompt on become

- moved check prompt/password functions to connection, make more senes there
- TODO: consider moving make_become to connection from connection_info
- removed executable param that was never overriden outside of connection info
This commit is contained in:
Brian Coca 2015-06-15 00:09:25 -04:00
commit 580993fef7
5 changed files with 37 additions and 38 deletions

View file

@ -20,6 +20,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import gettext
from abc import ABCMeta, abstractmethod, abstractproperty
from functools import wraps
@ -97,7 +98,7 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
@ensure_connect
@abstractmethod
def exec_command(self, cmd, tmp_path, executable=None, in_data=None, sudoable=True):
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True):
"""Run a command on the remote host"""
pass
@ -117,3 +118,17 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
def close(self):
"""Terminate the connection"""
pass
def check_become_success(self, output, success_key):
return success_key in output
def check_password_prompt(self, output, prompt):
if isinstance(prompt, basestring):
return output.endswith(prompt)
else:
return prompt(output)
def check_incorrect_password(self, output, prompt):
incorrect_password = gettext.dgettext(self._connection_info.become_method, "Sorry, try again.")
return output.endswith(incorrect_password)