mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
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:
@@ -32,9 +32,6 @@ from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.plugins.httpapi import HttpApiBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
OPTIONS = {
|
||||
@@ -73,7 +70,7 @@ class HttpApi(HttpApiBase):
|
||||
def send_request(self, data, **message_kwargs):
|
||||
data = to_list(data)
|
||||
if self._become:
|
||||
display.vvvv('firing event: on_become')
|
||||
self.connection.queue_message('vvvv', 'firing event: on_become')
|
||||
data.insert(0, {"cmd": "enable", "input": self._become_pass})
|
||||
|
||||
output = message_kwargs.get('output', 'text')
|
||||
|
||||
@@ -60,7 +60,6 @@ from ansible.plugins.httpapi import HttpApiBase
|
||||
from urllib3 import encode_multipart_formdata
|
||||
from urllib3.fields import RequestField
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.utils.display import Display
|
||||
|
||||
BASE_HEADERS = {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -70,8 +69,6 @@ BASE_HEADERS = {
|
||||
TOKEN_EXPIRATION_STATUS_CODE = 408
|
||||
UNAUTHORIZED_STATUS_CODE = 401
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class HttpApi(HttpApiBase):
|
||||
def __init__(self, connection):
|
||||
@@ -224,7 +221,7 @@ class HttpApi(HttpApiBase):
|
||||
return None
|
||||
|
||||
def _display(self, http_method, title, msg=''):
|
||||
display.vvvv('REST:%s:%s:%s\n%s' % (http_method, self.connection._url, title, msg))
|
||||
self.connection.queue_message('vvvv', 'REST:%s:%s:%s\n%s' % (http_method, self.connection._url, title, msg))
|
||||
|
||||
@staticmethod
|
||||
def _get_response_value(response_data):
|
||||
|
||||
@@ -22,9 +22,6 @@ from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.plugins.httpapi import HttpApiBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
OPTIONS = {
|
||||
@@ -75,7 +72,7 @@ class HttpApi(HttpApiBase):
|
||||
|
||||
def _run_queue(self, queue, output):
|
||||
if self._become:
|
||||
display.vvvv('firing event: on_become')
|
||||
self.connection.queue_message('vvvv', 'firing event: on_become')
|
||||
queue.insert(0, 'enable')
|
||||
|
||||
request = request_builder(queue, output)
|
||||
|
||||
Reference in New Issue
Block a user