mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
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.
This commit is contained in:
parent
450263e934
commit
3f17e87c5a
1 changed files with 13 additions and 7 deletions
|
@ -82,6 +82,17 @@ def exec_command(module, command):
|
||||||
return rc, to_native(stdout), to_native(stderr)
|
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:
|
class Connection:
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
@ -104,13 +115,8 @@ class Connection:
|
||||||
|
|
||||||
For usage refer the respective connection plugin docs.
|
For usage refer the respective connection plugin docs.
|
||||||
"""
|
"""
|
||||||
|
req = request_builder(name, *args, **kwargs)
|
||||||
reqid = str(uuid.uuid4())
|
reqid = req['id']
|
||||||
req = {'jsonrpc': '2.0', 'method': name, 'id': reqid}
|
|
||||||
|
|
||||||
params = list(args) or kwargs or None
|
|
||||||
if params:
|
|
||||||
req['params'] = params
|
|
||||||
|
|
||||||
if not self._module._socket_path:
|
if not self._module._socket_path:
|
||||||
self._module.fail_json(msg='provider support not available for this host')
|
self._module.fail_json(msg='provider support not available for this host')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue