mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -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
|
@ -58,7 +58,7 @@ class Cliconf(CliconfBase):
|
|||
if format:
|
||||
option_values = self.get_option_values()
|
||||
if format not in option_values['format']:
|
||||
raise ValueError("'format' value %s is invalid. Valid values of format are %s" % (format, ','.join(option_values['format'])))
|
||||
raise ValueError("'format' value %s is invalid. Valid values of format are %s" % (format, ', '.join(option_values['format'])))
|
||||
|
||||
if format == 'text':
|
||||
out = self.send_command('show configuration')
|
||||
|
@ -79,7 +79,7 @@ class Cliconf(CliconfBase):
|
|||
|
||||
operations = self.get_device_operations()
|
||||
if replace and not operations['supports_replace']:
|
||||
raise ValueError("configuration replace is not supported on vyos")
|
||||
raise ValueError("configuration replace is not supported")
|
||||
|
||||
results = []
|
||||
|
||||
|
@ -110,14 +110,14 @@ class Cliconf(CliconfBase):
|
|||
|
||||
resp['diff'] = diff_config
|
||||
resp['response'] = results[1:-1]
|
||||
return json.dumps(resp)
|
||||
return resp
|
||||
|
||||
def get(self, command=None, prompt=None, answer=None, sendonly=False, output=None):
|
||||
if not command:
|
||||
raise ValueError('must provide value of command to execute')
|
||||
|
||||
if output:
|
||||
raise ValueError("'output' value %s is not supported on vyos" % output)
|
||||
raise ValueError("'output' value %s is not supported for get" % output)
|
||||
|
||||
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
||||
|
||||
|
@ -136,20 +136,20 @@ class Cliconf(CliconfBase):
|
|||
device_operations = self.get_device_operations()
|
||||
option_values = self.get_option_values()
|
||||
|
||||
if candidate is None and not device_operations['supports_onbox_diff']:
|
||||
if candidate is None and device_operations['supports_generate_diff']:
|
||||
raise ValueError("candidate configuration is required to generate diff")
|
||||
|
||||
if match not in option_values['diff_match']:
|
||||
raise ValueError("'match' value %s in invalid, valid values are %s" % (match, option_values['diff_match']))
|
||||
raise ValueError("'match' value %s in invalid, valid values are %s" % (match, ', '.join(option_values['diff_match'])))
|
||||
|
||||
if replace:
|
||||
raise ValueError("'replace' in diff is not supported on vyos")
|
||||
raise ValueError("'replace' in diff is not supported")
|
||||
|
||||
if diff_ignore_lines:
|
||||
raise ValueError("'diff_ignore_lines' in diff is not supported on vyos")
|
||||
raise ValueError("'diff_ignore_lines' in diff is not supported")
|
||||
|
||||
if path:
|
||||
raise ValueError("'path' in diff is not supported on vyos")
|
||||
raise ValueError("'path' in diff is not supported")
|
||||
|
||||
set_format = candidate.startswith('set') or candidate.startswith('delete')
|
||||
candidate_obj = NetworkConfig(indent=4, contents=candidate)
|
||||
|
@ -171,7 +171,7 @@ class Cliconf(CliconfBase):
|
|||
|
||||
if match == 'none':
|
||||
diff['config_diff'] = list(candidate_commands)
|
||||
return json.dumps(diff)
|
||||
return diff
|
||||
|
||||
running_commands = [str(c).replace("'", '') for c in running.splitlines()]
|
||||
|
||||
|
@ -198,9 +198,12 @@ class Cliconf(CliconfBase):
|
|||
visited.add(line)
|
||||
|
||||
diff['config_diff'] = list(updates)
|
||||
return json.dumps(diff)
|
||||
return diff
|
||||
|
||||
def run_commands(self, commands=None, check_rc=True):
|
||||
if commands is None:
|
||||
raise ValueError("'commands' value is required")
|
||||
|
||||
def run_commands(self, commands):
|
||||
responses = list()
|
||||
for cmd in to_list(commands):
|
||||
if not isinstance(cmd, collections.Mapping):
|
||||
|
@ -208,9 +211,17 @@ class Cliconf(CliconfBase):
|
|||
|
||||
output = cmd.pop('output', None)
|
||||
if output:
|
||||
raise ValueError("'output' value %s is not supported on vyos" % output)
|
||||
raise ValueError("'output' value %s is not supported for run_commands" % output)
|
||||
|
||||
try:
|
||||
out = self.send_command(**cmd)
|
||||
except AnsibleConnectionFailure as e:
|
||||
if check_rc:
|
||||
raise
|
||||
out = getattr(e, 'err', e)
|
||||
|
||||
responses.append(out)
|
||||
|
||||
responses.append(self.send_command(**cmd))
|
||||
return responses
|
||||
|
||||
def get_device_operations(self):
|
||||
|
@ -219,7 +230,7 @@ class Cliconf(CliconfBase):
|
|||
'supports_commit': True,
|
||||
'supports_rollback': True,
|
||||
'supports_defaults': False,
|
||||
'supports_onbox_diff': False,
|
||||
'supports_onbox_diff': True,
|
||||
'supports_commit_comment': True,
|
||||
'supports_multiline_delimiter': False,
|
||||
'support_diff_match': True,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue