Add junos_system declartive module and other related change (#25859)

* Add junos_system declartive module and other related change

*  junos_system declartive module
*  integration test for junos_system
*  integration test for net_system (junos platform)
*  pep8 fixes for junos modules
*  move to lxml from elementree for xml parsing as it support
   complete set of xpath api's
*  other minor changes

* Fix CI and doc changes

* Fix unit test failures

* Fix typo in import

* Fix import issue for py2.6

* Add missed Element in import
This commit is contained in:
Ganesh Nalawade 2017-06-22 09:34:50 +05:30 committed by GitHub
commit b2f46753ec
29 changed files with 1075 additions and 96 deletions

View file

@ -104,6 +104,10 @@ options:
version_added: "2.3"
requirements:
- jxmlease
- ncclient (>=v0.5.2)
notes:
- This module requires the netconf system service be enabled on
the remote device being managed
"""
EXAMPLES = """
@ -163,17 +167,17 @@ import time
import re
import shlex
from functools import partial
from xml.etree import ElementTree as etree
from xml.etree.ElementTree import Element, SubElement, tostring
from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcli import Conditional, FailedConditionalError
from ansible.module_utils.netconf import send_request
from ansible.module_utils.network_common import ComplexList, to_list
from ansible.module_utils.six import string_types, iteritems
try:
from lxml.etree import Element, SubElement, tostring
except ImportError:
from xml.etree.ElementTree import Element, SubElement, tostring
try:
import jxmlease
HAS_JXMLEASE = True
@ -182,6 +186,7 @@ except ImportError:
USE_PERSISTENT_CONNECTION = True
def to_lines(stdout):
lines = list()
for item in stdout:
@ -190,6 +195,7 @@ def to_lines(stdout):
lines.append(item)
return lines
def rpc(module, items):
responses = list()
@ -238,6 +244,7 @@ def rpc(module, items):
return responses
def split(value):
lex = shlex.shlex(value)
lex.quotes = '"'
@ -245,6 +252,7 @@ def split(value):
lex.commenters = ''
return list(lex)
def parse_rpcs(module):
items = list()
@ -270,6 +278,7 @@ def parse_rpcs(module):
return items
def parse_commands(module, warnings):
items = list()
@ -329,7 +338,6 @@ def main():
items.extend(parse_rpcs(module))
wait_for = module.params['wait_for'] or list()
display = module.params['display']
conditionals = [Conditional(c) for c in wait_for]
retries = module.params['retries']
@ -344,8 +352,8 @@ def main():
for item, resp in zip(items, responses):
if item['xattrs']['format'] == 'xml':
if not HAS_JXMLEASE:
module.fail_json(msg='jxmlease is required but does not appear to '
'be installed. It can be installed using `pip install jxmlease`')
module.fail_json(msg='jxmlease is required but does not appear to be installed. '
'It can be installed using `pip install jxmlease`')
try:
transformed.append(jxmlease.parse(resp))
@ -382,9 +390,7 @@ def main():
'stdout_lines': to_lines(responses)
}
module.exit_json(**result)
if __name__ == '__main__':
main()