mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Refactor junos modules to Use netconf and cliconf plugins (#32621)
* Fix junos integration test fixes as per connection refactor (#33050) Refactor netconf connection plugin to work with netconf plugin * Fix junos integration test fixes as per connection refactor (#33050) Refactor netconf connection plugin to work with netconf plugin Fix CI failure Fix unit test failure Fix review comments
This commit is contained in:
@@ -171,11 +171,11 @@ import re
|
||||
import shlex
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.junos import junos_argument_spec, check_args, get_configuration
|
||||
from ansible.module_utils.netconf import exec_rpc
|
||||
from ansible.module_utils.junos import junos_argument_spec, get_configuration, get_connection, get_capabilities
|
||||
from ansible.module_utils.netcli import Conditional, FailedConditionalError
|
||||
from ansible.module_utils.netconf import send_request
|
||||
from ansible.module_utils.six import string_types, iteritems
|
||||
from ansible.module_utils.connection import Connection
|
||||
|
||||
|
||||
try:
|
||||
from lxml.etree import Element, SubElement, tostring
|
||||
@@ -203,7 +203,6 @@ def to_lines(stdout):
|
||||
def rpc(module, items):
|
||||
|
||||
responses = list()
|
||||
|
||||
for item in items:
|
||||
name = item['name']
|
||||
xattrs = item['xattrs']
|
||||
@@ -241,7 +240,7 @@ def rpc(module, items):
|
||||
if fetch_config:
|
||||
reply = get_configuration(module, format=xattrs['format'])
|
||||
else:
|
||||
reply = send_request(module, element, ignore_warning=False)
|
||||
reply = exec_rpc(module, tostring(element), ignore_warning=False)
|
||||
|
||||
if xattrs['format'] == 'text':
|
||||
if fetch_config:
|
||||
@@ -365,16 +364,24 @@ def main():
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
conn = get_connection(module)
|
||||
capabilities = get_capabilities(module)
|
||||
|
||||
if module.params['provider'] and module.params['provider']['transport'] == 'cli':
|
||||
if capabilities.get('network_api') == 'cliconf':
|
||||
if any((module.params['wait_for'], module.params['match'], module.params['rpcs'])):
|
||||
module.warn('arguments wait_for, match, rpcs are not supported when using transport=cli')
|
||||
commands = module.params['commands']
|
||||
conn = Connection(module)
|
||||
|
||||
output = list()
|
||||
display = module.params['display']
|
||||
for cmd in commands:
|
||||
output.append(conn.get(cmd))
|
||||
# if display format is not mentioned in command, add the display format
|
||||
# from the modules params
|
||||
if ('display json' not in cmd) and ('display xml' not in cmd):
|
||||
if display and display != 'text':
|
||||
cmd += ' | display {0}'.format(display)
|
||||
output.append(conn.get(command=cmd))
|
||||
|
||||
lines = [out.split('\n') for out in output]
|
||||
result = {'changed': False, 'stdout': output, 'stdout_lines': lines}
|
||||
module.exit_json(**result)
|
||||
|
||||
Reference in New Issue
Block a user