mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Update eos, ios, vyos cliconf plugin (#42300)
* Update eos cliconf plugin methods * Refactor eos cliconf plugin * Changes in eos module_utils as per cliconf plugin refactor * Fix unit test and sanity failures * Fix review comment
This commit is contained in:
parent
2aa81bf05d
commit
c068b88b38
14 changed files with 444 additions and 299 deletions
|
@ -266,33 +266,32 @@ backup_path:
|
|||
"""
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.module_utils.network.eos.eos import get_config, load_config
|
||||
from ansible.module_utils.network.eos.eos import get_config, load_config, get_connection
|
||||
from ansible.module_utils.network.eos.eos import run_commands
|
||||
from ansible.module_utils.network.eos.eos import eos_argument_spec
|
||||
from ansible.module_utils.network.eos.eos import check_args
|
||||
|
||||
|
||||
def get_candidate(module):
|
||||
candidate = NetworkConfig(indent=3)
|
||||
candidate = ''
|
||||
if module.params['src']:
|
||||
candidate.load(module.params['src'])
|
||||
candidate = module.params['src']
|
||||
elif module.params['lines']:
|
||||
candidate_obj = NetworkConfig(indent=3)
|
||||
parents = module.params['parents'] or list()
|
||||
candidate.add(module.params['lines'], parents=parents)
|
||||
candidate_obj.add(module.params['lines'], parents=parents)
|
||||
candidate = dumps(candidate_obj, 'raw')
|
||||
return candidate
|
||||
|
||||
|
||||
def get_running_config(module, config=None):
|
||||
def get_running_config(module, config=None, flags=None):
|
||||
contents = module.params['running_config']
|
||||
if not contents:
|
||||
if config:
|
||||
contents = config
|
||||
else:
|
||||
flags = []
|
||||
if module.params['defaults']:
|
||||
flags.append('all')
|
||||
contents = get_config(module, flags=flags)
|
||||
return NetworkConfig(indent=3, contents=contents)
|
||||
return contents
|
||||
|
||||
|
||||
def save_config(module, result):
|
||||
|
@ -363,30 +362,31 @@ def main():
|
|||
if warnings:
|
||||
result['warnings'] = warnings
|
||||
|
||||
diff_ignore_lines = module.params['diff_ignore_lines']
|
||||
config = None
|
||||
contents = None
|
||||
flags = ['all'] if module.params['defaults'] else []
|
||||
connection = get_connection(module)
|
||||
|
||||
if module.params['backup'] or (module._diff and module.params['diff_against'] == 'running'):
|
||||
contents = get_config(module)
|
||||
config = NetworkConfig(indent=3, contents=contents)
|
||||
contents = get_config(module, flags=flags)
|
||||
config = NetworkConfig(indent=1, contents=contents)
|
||||
if module.params['backup']:
|
||||
result['__backup__'] = contents
|
||||
|
||||
if any((module.params['src'], module.params['lines'])):
|
||||
match = module.params['match']
|
||||
replace = module.params['replace']
|
||||
path = module.params['parents']
|
||||
|
||||
candidate = get_candidate(module)
|
||||
running = get_running_config(module, contents, flags=flags)
|
||||
|
||||
if match != 'none' and replace != 'config':
|
||||
config_text = get_running_config(module)
|
||||
config = NetworkConfig(indent=3, contents=config_text)
|
||||
path = module.params['parents']
|
||||
configobjs = candidate.difference(config, match=match, replace=replace, path=path)
|
||||
else:
|
||||
configobjs = candidate.items
|
||||
response = connection.get_diff(candidate=candidate, running=running, match=match, diff_ignore_lines=diff_ignore_lines, path=path, replace=replace)
|
||||
config_diff = response['config_diff']
|
||||
|
||||
if configobjs:
|
||||
commands = dumps(configobjs, 'commands').split('\n')
|
||||
if config_diff:
|
||||
commands = config_diff.split('\n')
|
||||
|
||||
if module.params['before']:
|
||||
commands[:0] = module.params['before']
|
||||
|
@ -413,16 +413,14 @@ def main():
|
|||
running_config = module.params['running_config']
|
||||
startup_config = None
|
||||
|
||||
diff_ignore_lines = module.params['diff_ignore_lines']
|
||||
|
||||
if module.params['save_when'] == 'always' or module.params['save']:
|
||||
save_config(module, result)
|
||||
elif module.params['save_when'] == 'modified':
|
||||
output = run_commands(module, [{'command': 'show running-config', 'output': 'text'},
|
||||
{'command': 'show startup-config', 'output': 'text'}])
|
||||
|
||||
running_config = NetworkConfig(indent=1, contents=output[0], ignore_lines=diff_ignore_lines)
|
||||
startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines)
|
||||
running_config = NetworkConfig(indent=3, contents=output[0], ignore_lines=diff_ignore_lines)
|
||||
startup_config = NetworkConfig(indent=3, contents=output[1], ignore_lines=diff_ignore_lines)
|
||||
|
||||
if running_config.sha1 != startup_config.sha1:
|
||||
save_config(module, result)
|
||||
|
@ -438,7 +436,7 @@ def main():
|
|||
contents = running_config
|
||||
|
||||
# recreate the object in order to process diff_ignore_lines
|
||||
running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
running_config = NetworkConfig(indent=3, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
|
||||
if module.params['diff_against'] == 'running':
|
||||
if module.check_mode:
|
||||
|
@ -458,7 +456,7 @@ def main():
|
|||
contents = module.params['intended_config']
|
||||
|
||||
if contents is not None:
|
||||
base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
base_config = NetworkConfig(indent=3, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
|
||||
if running_config.sha1 != base_config.sha1:
|
||||
if module.params['diff_against'] == 'intended':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue