roll up of eos fixes (#21987)

* fixes to_command function in eos to not iterate over commands twice
* fixes lots of minor issues with _eos_template
pull/21926/merge
Peter Sprygada 8 years ago committed by GitHub
parent 888c8614fb
commit c1c54f1bf4

@ -432,15 +432,7 @@ def to_command(module, commands):
answer=dict() answer=dict()
), module) ), module)
commands = transform(to_list(commands)) return transform(to_list(commands))
for index, item in enumerate(commands):
if is_json(item['command']):
item['output'] = 'json'
elif is_text(item['command']):
item['output'] = 'text'
return commands
def get_config(module, flags=[]): def get_config(module, flags=[]):
conn = get_connection(module) conn = get_connection(module)

@ -123,17 +123,28 @@ responses:
""" """
import re import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import load_config, get_config from ansible.module_utils.eos import load_config, get_config
from ansible.module_utils.basic import AnsibleModle from ansible.module_utils.eos import eos_argument_spec
from ansible.module_utils.eos import check_args as eos_check_args
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
def check_args(module, warnings):
eos_check_args(module, warnings)
transport = module.params['transport']
provider_transport = (module.params['provider'] or {}).get('transport')
if module.params['replace'] and 'eapi' in (transport, provider_transport):
module.fail_json(msg='config replace is only supported over cli')
def get_current_config(module): def get_current_config(module):
config = module.params.get('config') config = module.params.get('config')
if not config and not module.params['force']: if not config and not module.params['force']:
flags = [] flags = []
if module.params['include_defaults']: if module.params['include_defaults']:
flags.append('all') flags.append('all')
config = module.config.get_config(include_defaults=defaults) config = get_config(module, flags)
return config return config
def filter_exit(commands): def filter_exit(commands):
@ -173,7 +184,7 @@ def main():
config=dict() config=dict()
) )
argument_spec.update(eos_local.eapi_argument_spec) argument_spec.update(eos_argument_spec)
mutually_exclusive = [('config', 'backup'), ('config', 'force')] mutually_exclusive = [('config', 'backup'), ('config', 'force')]
@ -181,7 +192,8 @@ def main():
mutually_exclusive=mutually_exclusive, mutually_exclusive=mutually_exclusive,
supports_check_mode=True) supports_check_mode=True)
warnings = check_args(module) warnings = list()
check_args(module, warnings)
result = {'changed': False} result = {'changed': False}
if warnings: if warnings:
@ -191,7 +203,7 @@ def main():
candidate = NetworkConfig(contents=src, indent=3) candidate = NetworkConfig(contents=src, indent=3)
if module.params['backup']: if module.params['backup']:
result['__backup__'] = get_config() result['__backup__'] = get_config(module)
if not module.params['force']: if not module.params['force']:
contents = get_current_config(module) contents = get_current_config(module)
@ -202,18 +214,16 @@ def main():
else: else:
commands = [c.strip() for c in str(candidate).split('\n')] commands = [c.strip() for c in str(candidate).split('\n')]
# FIXME not implemented yet!! #commands = str(candidate).split('\n')
if replace:
if module.params['transport'] == 'cli':
module.fail_json(msg='config replace is only supported over eos_local')
commands = str(candidate).split('\n')
if commands: if commands:
commands = filter_exit(commands) commands = filter_exit(commands)
commit = not module.check_mode commit = not module.check_mode
load_config(commands, commit=commit) replace = module.params['replace'] or False
load_config(module, commands, commit=commit, replace=replace)
result['changed'] = True result['changed'] = True
result['commands'] = commands
result['updates'] = commands result['updates'] = commands
module.exit_json(**result) module.exit_json(**result)

Loading…
Cancel
Save