junos_config: Remove reliance on ability to output configuration in set format (#23225)

* Remove reliance on ability to output configuration in `set` format
* Support multiple warnings per rpc-reply
This commit is contained in:
Nathaniel Case 2017-04-04 15:00:00 -04:00 committed by GitHub
commit 597bca3129
4 changed files with 37 additions and 16 deletions

View file

@ -157,7 +157,7 @@ def main():
module.fail_json(msg='unable to retrieve device configuration')
result['__backup__'] = str(match.text).strip()
diff = load_config(module, src, action=action, commit=commit, format=fmt)
diff = load_config(module, src, warnings, action=action, commit=commit, format=fmt)
if diff:
result['changed'] = True
if module._diff:

View file

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