mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 06:31:23 -07:00
Add netconf_get module (#39869)
* Add netconf_get module Implements part-1 of proposal #104 https://github.com/ansible/proposals/issues/104 * Add netconf_get module * Refactor `get`, `get_config`, `lock`, `unlock` and `discard_changes` netconf plugin api's * Add netconf module_utils file which netconf module related common functions * Refactor junos and iosxr netconf plugins * Fix source option handling * Fix review comments * Update botmeta file * Update review comments and add support for lock * Lock update fix * Fix CI issue * Add integration test and minor fixes * Fix review comments * Fix CI failure * Fix CI issues * Fix CI issues * Fix review comments and update integration test * Fix review comments * Fix review comments * Fix review comments Fix reveiw comments
This commit is contained in:
parent
4c0ceaea3d
commit
30f992f260
16 changed files with 841 additions and 119 deletions
|
@ -30,6 +30,12 @@ import sys
|
|||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.module_utils.connection import Connection, ConnectionError
|
||||
|
||||
try:
|
||||
from ncclient.xml_ import NCElement
|
||||
HAS_NCCLIENT = True
|
||||
except ImportError:
|
||||
HAS_NCCLIENT = False
|
||||
|
||||
try:
|
||||
from lxml.etree import Element, fromstring, XMLSyntaxError
|
||||
except ImportError:
|
||||
|
@ -100,3 +106,40 @@ class NetconfConnection(Connection):
|
|||
return warnings
|
||||
except XMLSyntaxError:
|
||||
raise ConnectionError(rpc_error)
|
||||
|
||||
|
||||
def transform_reply():
|
||||
reply = '''<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="xml" indent="no"/>
|
||||
|
||||
<xsl:template match="/|comment()|processing-instruction()">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="*">
|
||||
<xsl:element name="{local-name()}">
|
||||
<xsl:apply-templates select="@*|node()"/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="@*">
|
||||
<xsl:attribute name="{local-name()}">
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:attribute>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
'''
|
||||
if sys.version < '3':
|
||||
return reply
|
||||
else:
|
||||
return reply.encode('UTF-8')
|
||||
|
||||
|
||||
# Note: Workaround for ncclient 0.5.3
|
||||
def remove_namespaces(data):
|
||||
if not HAS_NCCLIENT:
|
||||
raise ImportError("ncclient is required but does not appear to be installed. "
|
||||
"It can be installed using `pip install ncclient`")
|
||||
return NCElement(data, transform_reply()).data_xml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue