Allow persistent connection plugins to queue messages back to ansible-connection (#49977)

* Connections can queue messages to be returned from ansible-connection

* Provide fallback for invalid display level

* Strip display from plugins

* Route messages through helper method to try to avoid improper appends
This commit is contained in:
Nathaniel Case 2018-12-19 10:54:42 -05:00 committed by GitHub
commit 1829a72885
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 75 additions and 83 deletions

View file

@ -25,7 +25,6 @@ from functools import wraps
from ansible.plugins import AnsiblePlugin
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_text
from ansible.utils.display import Display
try:
from scp import SCPClient
@ -33,8 +32,6 @@ try:
except ImportError:
HAS_SCP = False
display = Display()
def enable_mode(func):
@wraps(func)
@ -88,7 +85,7 @@ class CliconfBase(AnsiblePlugin):
def _alarm_handler(self, signum, frame):
"""Alarm handler raised in case of command timeout """
display.display('closing shell due to command timeout (%s seconds).' % self._connection._play_context.timeout, log_only=True)
self._connection.queue_message('log', 'closing shell due to command timeout (%s seconds).' % self._connection._play_context.timeout)
self.close()
def send_command(self, command=None, prompt=None, answer=None, sendonly=False, newline=True, prompt_retry_check=False, check_all=False):