fix bugs for ce (#54750)

* Update ce.py

            while to_text(out, errors='surrogate_then_replace').strip().endswith(']'):
                display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
                conn.exec_command('return')
                out = conn.get_prompt()

connetion has no send_command function and ce device has no 'exit' command to return user-view(a correct context),but 'return' .command.

* Add files via upload

Some bugs fix.

* Add files via upload

fix some bugs

* fix a bug for ce_command

Running a command with prompt via ce_command, It doesn't work.The reason is that the key word for network_cli recognition is answer not response.

* fix bugs

fix bugs for ce modules

* Update ce.py

* Delete ce_ftp.py

need modify

* Delete ce_lacp.py

* Add files via upload

* Delete ce_aaa_server.py

* Delete ce_aaa_server_host.py

* Compatible with Python 3

Compatible with Python 3 and fix bugs for ce

* Update ce_aaa_server.py

* Add files via upload

modify doc

* Add files via upload

Compatible with Python 3 and fix bugs

* Add files via upload

Compatible with Python 3 and fix bugs

* Add files via upload

Cancellation of change

* Update ce_netconf.py

It is a bug that response has no xml attribute:line 183

* Add files via upload

* Add files via upload

Compatible with Python 3 and fix bugs

* updatp ce_config.py

a bug for this module.
This commit is contained in:
xuxiaowei 2019-04-17 15:21:58 +08:00 committed by Ganesh Nalawade
parent f8bebc61c8
commit 1017f15c38
9 changed files with 315 additions and 269 deletions

View file

@ -224,6 +224,7 @@ from ansible.module_utils.network.common.config import NetworkConfig, dumps
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, run_commands
from ansible.module_utils.network.cloudengine.ce import ce_argument_spec
from ansible.module_utils.network.cloudengine.ce import check_args as ce_check_args
import re
def check_args(module, warnings):
@ -240,10 +241,45 @@ def get_running_config(module):
return NetworkConfig(indent=1, contents=contents)
def conversion_src(module):
src_list = module.params['src'].split('\n')
src_list_organize = []
exit_list = [' return', ' system-view']
if src_list[0].strip() == '#':
src_list.pop(0)
for per_config in src_list:
if per_config.strip() == '#':
if per_config.rstrip() == '#':
src_list_organize.extend(exit_list)
else:
src_list_organize.append('quit')
else:
src_list_organize.append(per_config)
src_str = '\n'.join(src_list_organize)
return src_str
def conversion_lines(commands):
all_config = []
exit_list = [' return', ' system-view']
for per_command in commands:
if re.search(r',', per_command):
all_config.extend(exit_list)
per_config = per_command.split(',')
for config in per_config:
if config:
all_config.append(config)
all_config.extend(exit_list)
else:
all_config.append(per_command)
return all_config
def get_candidate(module):
candidate = NetworkConfig(indent=1)
if module.params['src']:
candidate.load(module.params['src'])
config = conversion_src(module)
candidate.load(config)
elif module.params['lines']:
parents = module.params['parents'] or list()
candidate.add(module.params['lines'], parents=parents)
@ -253,7 +289,6 @@ def get_candidate(module):
def run(module, result):
match = module.params['match']
replace = module.params['replace']
candidate = get_candidate(module)
if match != 'none':
@ -265,21 +300,27 @@ def run(module, result):
if configobjs:
commands = dumps(configobjs, 'commands').split('\n')
if module.params['lines']:
commands = conversion_lines(commands)
if module.params['before']:
commands[:0] = module.params['before']
if module.params['after']:
commands.extend(module.params['after'])
result['commands'] = commands
result['updates'] = commands
command_display = []
for per_command in commands:
if per_command.strip() not in ['quit', 'return', 'system-view']:
command_display.append(per_command)
result['commands'] = command_display
result['updates'] = command_display
if not module.check_mode:
load_config(module, commands)
result['changed'] = True
if result['commands']:
result['changed'] = True
def main():