mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
exposes rpc method to plugin (#35507)
The rpc method should be exposed to the modules over the connection rpc mechanism. This fix will expose the rpc method to call generalized rpc endpoints on remote devices
This commit is contained in:
parent
bf5770dec4
commit
58d54799b8
2 changed files with 13 additions and 6 deletions
|
@ -24,10 +24,11 @@ from functools import wraps
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six import with_metaclass
|
from ansible.module_utils.six import with_metaclass
|
||||||
|
from ansible.module_utils._text import to_bytes
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ncclient.operations import RPCError
|
from ncclient.operations import RPCError
|
||||||
from ncclient.xml_ import to_xml
|
from ncclient.xml_ import to_xml, to_ele
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise AnsibleError("ncclient is not installed")
|
raise AnsibleError("ncclient is not installed")
|
||||||
|
|
||||||
|
@ -96,6 +97,16 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
self.m = self._connection._manager
|
self.m = self._connection._manager
|
||||||
|
|
||||||
|
@ensure_connected
|
||||||
|
def rpc(self, name):
|
||||||
|
"""RPC to be execute on remote device
|
||||||
|
:name: Name of rpc in string format"""
|
||||||
|
try:
|
||||||
|
obj = to_ele(to_bytes(name, errors='surrogate_or_strict'))
|
||||||
|
return self.m.rpc(obj).data_xml
|
||||||
|
except RPCError as exc:
|
||||||
|
raise Exception(to_xml(exc.xml))
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def get_config(self, *args, **kwargs):
|
def get_config(self, *args, **kwargs):
|
||||||
"""Retrieve all or part of a specified configuration.
|
"""Retrieve all or part of a specified configuration.
|
||||||
|
|
|
@ -63,11 +63,7 @@ class Netconf(NetconfBase):
|
||||||
def execute_rpc(self, name):
|
def execute_rpc(self, name):
|
||||||
"""RPC to be execute on remote device
|
"""RPC to be execute on remote device
|
||||||
:name: Name of rpc in string format"""
|
:name: Name of rpc in string format"""
|
||||||
try:
|
return self.rpc(name)
|
||||||
obj = to_ele(to_bytes(name, errors='surrogate_or_strict'))
|
|
||||||
return self.m.rpc(obj).data_xml
|
|
||||||
except RPCError as exc:
|
|
||||||
raise Exception(to_xml(exc.xml))
|
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def load_configuration(self, *args, **kwargs):
|
def load_configuration(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue