|
|
@ -219,12 +219,10 @@ def filter_delete_statements(module, candidate):
|
|
|
|
reply = get_configuration(module, format='set')
|
|
|
|
reply = get_configuration(module, format='set')
|
|
|
|
match = reply.find('.//configuration-set')
|
|
|
|
match = reply.find('.//configuration-set')
|
|
|
|
if match is None:
|
|
|
|
if match is None:
|
|
|
|
module.fail_json(msg='unable to retrieve device configuration')
|
|
|
|
# Could not find configuration-set in reply, perhaps device does not support it?
|
|
|
|
|
|
|
|
return candidate
|
|
|
|
config = str(match.text)
|
|
|
|
config = str(match.text)
|
|
|
|
|
|
|
|
|
|
|
|
#if 'delete interfaces lo0' in candidate:
|
|
|
|
|
|
|
|
# raise ValueError(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modified_candidate = candidate[:]
|
|
|
|
modified_candidate = candidate[:]
|
|
|
|
for index, line in enumerate(candidate):
|
|
|
|
for index, line in enumerate(candidate):
|
|
|
|
if line.startswith('delete'):
|
|
|
|
if line.startswith('delete'):
|
|
|
@ -234,7 +232,7 @@ def filter_delete_statements(module, candidate):
|
|
|
|
|
|
|
|
|
|
|
|
return modified_candidate
|
|
|
|
return modified_candidate
|
|
|
|
|
|
|
|
|
|
|
|
def configure_device(module):
|
|
|
|
def configure_device(module, warnings):
|
|
|
|
candidate = module.params['lines'] or module.params['src']
|
|
|
|
candidate = module.params['lines'] or module.params['src']
|
|
|
|
if isinstance(candidate, string_types):
|
|
|
|
if isinstance(candidate, string_types):
|
|
|
|
candidate = candidate.split('\n')
|
|
|
|
candidate = candidate.split('\n')
|
|
|
@ -266,7 +264,7 @@ def configure_device(module):
|
|
|
|
kwargs['format'] = 'text'
|
|
|
|
kwargs['format'] = 'text'
|
|
|
|
kwargs['action'] = 'set'
|
|
|
|
kwargs['action'] = 'set'
|
|
|
|
|
|
|
|
|
|
|
|
return load_config(module, candidate, **kwargs)
|
|
|
|
return load_config(module, candidate, warnings, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
""" main entry point for module execution
|
|
|
|
""" main entry point for module execution
|
|
|
@ -307,10 +305,14 @@ def main():
|
|
|
|
result = {'changed': False, 'warnings': warnings}
|
|
|
|
result = {'changed': False, 'warnings': warnings}
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['backup']:
|
|
|
|
if module.params['backup']:
|
|
|
|
reply = get_configuration(module, format='set')
|
|
|
|
for conf_format in ['set', 'text']:
|
|
|
|
match = reply.find('.//configuration-set')
|
|
|
|
reply = get_configuration(module, format=conf_format)
|
|
|
|
if match is None:
|
|
|
|
match = reply.find('.//configuration-%s' % conf_format)
|
|
|
|
|
|
|
|
if match is not None:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
module.fail_json(msg='unable to retrieve device configuration')
|
|
|
|
module.fail_json(msg='unable to retrieve device configuration')
|
|
|
|
|
|
|
|
|
|
|
|
result['__backup__'] = str(match.text).strip()
|
|
|
|
result['__backup__'] = str(match.text).strip()
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['rollback']:
|
|
|
|
if module.params['rollback']:
|
|
|
@ -326,7 +328,7 @@ def main():
|
|
|
|
result['changed'] = True
|
|
|
|
result['changed'] = True
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
diff = configure_device(module)
|
|
|
|
diff = configure_device(module, warnings)
|
|
|
|
if diff:
|
|
|
|
if diff:
|
|
|
|
if module._diff:
|
|
|
|
if module._diff:
|
|
|
|
result['diff'] = {'prepared': diff}
|
|
|
|
result['diff'] = {'prepared': diff}
|
|
|
|