Updated the config module to use the new Parse method for OS6

pull/18777/head
Senthil Kumar Ganesan 8 years ago committed by Matt Clay
parent 8adc05051c
commit a7242039ad

@ -192,12 +192,13 @@ saved:
sample: True sample: True
""" """
from ansible.module_utils.netcfg import NetworkConfig, dumps, ConfigLine from ansible.module_utils.netcfg import dumps
from ansible.module_utils.network import NetworkModule from ansible.module_utils.network import NetworkModule
from ansible.module_utils.dellos6 import get_config from ansible.module_utils.dnos6 import get_config, get_sublevel_config, Dellos6NetworkConfig
def get_candidate(module): def get_candidate(module):
candidate = NetworkConfig(indent=1) candidate = Dellos6NetworkConfig(indent=0)
if module.params['src']: if module.params['src']:
candidate.load(module.params['src']) candidate.load(module.params['src'])
elif module.params['lines']: elif module.params['lines']:
@ -205,22 +206,9 @@ def get_candidate(module):
candidate.add(module.params['lines'], parents=parents) candidate.add(module.params['lines'], parents=parents)
return candidate return candidate
def get_contents(other,module):
contents =list()
parent = ''.join(module.params['parents'])
start = False
for item in other.items:
if item.text == parent:
start = True
elif item.text != 'exit' and start:
contents.append(item.text)
elif item.text == 'exit' and start:
start = False
break
return contents
def main(): def main():
argument_spec = dict( argument_spec = dict(
lines=dict(aliases=['commands'], type='list'), lines=dict(aliases=['commands'], type='list'),
parents=dict(type='list'), parents=dict(type='list'),
@ -250,30 +238,31 @@ def main():
match = module.params['match'] match = module.params['match']
replace = module.params['replace'] replace = module.params['replace']
before = module.params['before']
result = dict(changed=False, saved=False) result = dict(changed=False, saved=False)
candidate = get_candidate(module) candidate = get_candidate(module)
if module.params['match'] != 'none': if match != 'none':
config = get_config(module) config = get_config(module)
if parents: if parents:
con = get_contents(config,module) config = get_sublevel_config(config, module)
config = NetworkConfig(indent=1)
config.add(con,parents=module.params['parents'])
configobjs = candidate.difference(config, match=match, replace=replace) configobjs = candidate.difference(config, match=match, replace=replace)
else: else:
configobjs = candidate.items configobjs = candidate.items
if module.params['backup']: if module.params['backup']:
result['__backup__'] = module.cli('show running-config')[0] result['__backup__'] = module.cli('show running-config')[0]
commands = list() commands = list()
if configobjs: if configobjs:
commands = dumps(configobjs, 'commands') commands = dumps(configobjs, 'commands')
commands = commands.split('\n') commands = commands.split('\n')
if module.params['before']: if module.params['before']:
commands[:0] = before commands[:0] = module.params['before']
if module.params['after']: if module.params['after']:
commands.extend(module.params['after']) commands.extend(module.params['after'])
if not module.check_mode and module.params['update'] == 'merge': if not module.check_mode and module.params['update'] == 'merge':
response = module.config.load_config(commands) response = module.config.load_config(commands)
result['responses'] = response result['responses'] = response
@ -282,13 +271,11 @@ def main():
module.config.save_config() module.config.save_config()
result['saved'] = True result['saved'] = True
result['changed'] = True result['changed'] = True
result['updates'] = commands result['updates'] = commands
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save