mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-23 06:21:43 -07:00
Netconf bytes fixes (#41607)
* Solve some bytes issues on iosxr * Solve some bytes issues in junos * Do the correct thing with tostring based on lxml or not
This commit is contained in:
parent
c144adc9de
commit
9aa8c652ba
23 changed files with 54 additions and 113 deletions
|
@ -27,10 +27,10 @@ from ansible.module_utils.network.common.netconf import NetconfConnection
|
|||
from ansible.module_utils._text import to_text
|
||||
|
||||
try:
|
||||
from lxml.etree import Element, SubElement, fromstring, tostring
|
||||
from lxml.etree import Element, SubElement, tostring as xml_to_string
|
||||
HAS_LXML = True
|
||||
except ImportError:
|
||||
from xml.etree.ElementTree import Element, SubElement, fromstring, tostring
|
||||
from xml.etree.ElementTree import Element, SubElement, tostring as xml_to_string
|
||||
HAS_LXML = False
|
||||
|
||||
ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
|
||||
|
@ -62,6 +62,13 @@ junos_top_spec = {
|
|||
junos_argument_spec.update(junos_top_spec)
|
||||
|
||||
|
||||
def tostring(element, encoding='UTF-8'):
|
||||
if HAS_LXML:
|
||||
return xml_to_string(element, encoding='unicode')
|
||||
else:
|
||||
return to_text(xml_to_string(element, encoding), encoding=encoding)
|
||||
|
||||
|
||||
def get_provider_argspec():
|
||||
return junos_provider_spec
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue