From 3f17e87c5a47a81e3514fa6ea3c57c504597e39b Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sat, 17 Jun 2017 16:14:48 -0400 Subject: [PATCH] pulls the jsonrpc request builder code into top level function (#25833) refactors the Connection class to use the top level function. This will make the request_builder() function useful for other components such as action handlers. --- lib/ansible/module_utils/connection.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/connection.py b/lib/ansible/module_utils/connection.py index 821716c0c1f..c092536f960 100644 --- a/lib/ansible/module_utils/connection.py +++ b/lib/ansible/module_utils/connection.py @@ -82,6 +82,17 @@ def exec_command(module, command): return rc, to_native(stdout), to_native(stderr) +def request_builder(method, *args, **kwargs): + reqid = str(uuid.uuid4()) + req = {'jsonrpc': '2.0', 'method': method, 'id': reqid} + + params = list(args) or kwargs or None + if params: + req['params'] = params + + return req + + class Connection: def __init__(self, module): @@ -104,13 +115,8 @@ class Connection: For usage refer the respective connection plugin docs. """ - - reqid = str(uuid.uuid4()) - req = {'jsonrpc': '2.0', 'method': name, 'id': reqid} - - params = list(args) or kwargs or None - if params: - req['params'] = params + req = request_builder(name, *args, **kwargs) + reqid = req['id'] if not self._module._socket_path: self._module.fail_json(msg='provider support not available for this host')