mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Refactor junos modules to Use netconf and cliconf plugins (#32621)
* Fix junos integration test fixes as per connection refactor (#33050) Refactor netconf connection plugin to work with netconf plugin * Fix junos integration test fixes as per connection refactor (#33050) Refactor netconf connection plugin to work with netconf plugin Fix CI failure Fix unit test failure Fix review comments
This commit is contained in:
parent
0c75f00248
commit
3d63ecb6f3
37 changed files with 543 additions and 320 deletions
|
@ -34,8 +34,7 @@ import traceback
|
|||
import uuid
|
||||
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
||||
|
@ -77,7 +76,7 @@ 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
|
||||
params = args or kwargs or None
|
||||
if params:
|
||||
req['params'] = params
|
||||
|
||||
|
@ -92,7 +91,7 @@ class ConnectionError(Exception):
|
|||
setattr(self, k, v)
|
||||
|
||||
|
||||
class Connection:
|
||||
class Connection(object):
|
||||
|
||||
def __init__(self, socket_path):
|
||||
if socket_path is None:
|
||||
|
@ -107,15 +106,8 @@ class Connection:
|
|||
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
|
||||
return partial(self.__rpc__, name)
|
||||
|
||||
def __rpc__(self, name, *args, **kwargs):
|
||||
"""Executes the json-rpc and returns the output received
|
||||
from remote device.
|
||||
:name: rpc method to be executed over connection plugin that implements jsonrpc 2.0
|
||||
:args: Ordered list of params passed as arguments to rpc method
|
||||
:kwargs: Dict of valid key, value pairs passed as arguments to rpc method
|
||||
def _exec_jsonrpc(self, name, *args, **kwargs):
|
||||
|
||||
For usage refer the respective connection plugin docs.
|
||||
"""
|
||||
req = request_builder(name, *args, **kwargs)
|
||||
reqid = req['id']
|
||||
|
||||
|
@ -133,6 +125,20 @@ class Connection:
|
|||
if response['id'] != reqid:
|
||||
raise ConnectionError('invalid json-rpc id received')
|
||||
|
||||
return response
|
||||
|
||||
def __rpc__(self, name, *args, **kwargs):
|
||||
"""Executes the json-rpc and returns the output received
|
||||
from remote device.
|
||||
:name: rpc method to be executed over connection plugin that implements jsonrpc 2.0
|
||||
:args: Ordered list of params passed as arguments to rpc method
|
||||
:kwargs: Dict of valid key, value pairs passed as arguments to rpc method
|
||||
|
||||
For usage refer the respective connection plugin docs.
|
||||
"""
|
||||
|
||||
response = self._exec_jsonrpc(name, *args, **kwargs)
|
||||
|
||||
if 'error' in response:
|
||||
err = response.get('error')
|
||||
msg = err.get('data') or err['message']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue