mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
New ansible module netconf_rpc (#40358)
* New ansible module netconf_rpc * add integration test for module netconf_rpc * pep8/meta-data corrections * usage of jxmlease for all XML processing separation of attributes "rpc" and "content" * removed unused imports improved error handling * fixed pep8 * usage of ast.literal_eval instead of eval added description to SROS integration test for cases commented out
This commit is contained in:
parent
ea4a78b2a1
commit
387a23c3d1
13 changed files with 561 additions and 19 deletions
|
@ -32,6 +32,11 @@ try:
|
|||
except ImportError:
|
||||
raise AnsibleError("ncclient is not installed")
|
||||
|
||||
try:
|
||||
from lxml.etree import Element, SubElement, tostring, fromstring
|
||||
except ImportError:
|
||||
from xml.etree.ElementTree import Element, SubElement, tostring, fromstring
|
||||
|
||||
|
||||
def ensure_connected(func):
|
||||
@wraps(func)
|
||||
|
@ -106,7 +111,7 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
|||
resp = self.m.rpc(obj)
|
||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||
except RPCError as exc:
|
||||
msg = exc.data_xml if hasattr(exc, 'data_xml') else exc.xml
|
||||
msg = exc.xml
|
||||
raise Exception(to_xml(msg))
|
||||
|
||||
@ensure_connected
|
||||
|
@ -174,6 +179,15 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
|||
resp = self.m.copy_config(*args, **kwargs)
|
||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||
|
||||
@ensure_connected
|
||||
def dispatch(self, request):
|
||||
"""Execute operation on the remote device
|
||||
:request: is the rpc request including attributes as XML string
|
||||
"""
|
||||
req = fromstring(request)
|
||||
resp = self.m.dispatch(req)
|
||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||
|
||||
@ensure_connected
|
||||
def lock(self, target=None):
|
||||
"""
|
||||
|
@ -228,13 +242,6 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
|||
resp = self.m.commit(*args, **kwargs)
|
||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||
|
||||
@ensure_connected
|
||||
def validate(self, *args, **kwargs):
|
||||
"""Validate the contents of the specified configuration.
|
||||
:source: name of configuration data store"""
|
||||
resp = self.m.validate(*args, **kwargs)
|
||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||
|
||||
@ensure_connected
|
||||
def get_schema(self, *args, **kwargs):
|
||||
"""Retrieves the required schema from the device
|
||||
|
@ -277,15 +284,15 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
|||
def get_device_operations(self, server_capabilities):
|
||||
operations = {}
|
||||
capabilities = '\n'.join(server_capabilities)
|
||||
operations['supports_commit'] = True if ':candidate' in capabilities else False
|
||||
operations['supports_defaults'] = True if ':with-defaults' in capabilities else False
|
||||
operations['supports_confirm_commit'] = True if ':confirmed-commit' in capabilities else False
|
||||
operations['supports_startup'] = True if ':startup' in capabilities else False
|
||||
operations['supports_xpath'] = True if ':xpath' in capabilities else False
|
||||
operations['supports_writeable_running'] = True if ':writable-running' in capabilities else False
|
||||
operations['supports_commit'] = ':candidate' in capabilities
|
||||
operations['supports_defaults'] = ':with-defaults' in capabilities
|
||||
operations['supports_confirm_commit'] = ':confirmed-commit' in capabilities
|
||||
operations['supports_startup'] = ':startup' in capabilities
|
||||
operations['supports_xpath'] = ':xpath' in capabilities
|
||||
operations['supports_writable_running'] = ':writable-running' in capabilities
|
||||
|
||||
operations['lock_datastore'] = []
|
||||
if operations['supports_writeable_running']:
|
||||
if operations['supports_writable_running']:
|
||||
operations['lock_datastore'].append('running')
|
||||
|
||||
if operations['supports_commit']:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue