nxos cliconf plugin refactor (#43203)

* nxos cliconf plugin refactor

Fixes #39056

*  Refactor nxos cliconf plugin as per new api definition
*  Minor changes in ios, eos, vyos cliconf plugin
*  Change nxos httpapi plugin edit_config method to be in sync with
   nxos cliconf edit_config

* Fix CI failure

* Fix unit test failure and review comment
This commit is contained in:
Ganesh Nalawade 2018-07-27 11:05:40 +05:30 committed by GitHub
parent e215f842ba
commit af3f510316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 426 additions and 245 deletions

View file

@ -66,29 +66,20 @@ class Cliconf(CliconfBase):
out = self.send_command('show configuration commands')
return out
def edit_config(self, candidate=None, commit=True, replace=False, comment=None):
def edit_config(self, candidate=None, commit=True, replace=None, comment=None):
resp = {}
if not candidate:
raise ValueError('must provide a candidate config to load')
if commit not in (True, False):
raise ValueError("'commit' must be a bool, got %s" % commit)
if replace not in (True, False):
raise ValueError("'replace' must be a bool, got %s" % replace)
operations = self.get_device_operations()
if replace and not operations['supports_replace']:
raise ValueError("configuration replace is not supported")
self.check_edit_config_capabiltiy(operations, candidate, commit, replace, comment)
results = []
for cmd in chain(['configure'], to_list(candidate)):
requests = []
self.send_command('configure')
for cmd in to_list(candidate):
if not isinstance(cmd, collections.Mapping):
cmd = {'command': cmd}
results.append(self.send_command(**cmd))
requests.append(cmd['command'])
out = self.get('compare')
out = to_text(out, errors='surrogate_or_strict')
diff_config = out if not out.startswith('No changes') else None
@ -109,7 +100,8 @@ class Cliconf(CliconfBase):
self.send_command('exit')
resp['diff'] = diff_config
resp['response'] = results[1:-1]
resp['response'] = results
resp['request'] = requests
return resp
def get(self, command=None, prompt=None, answer=None, sendonly=False, output=None):
@ -131,7 +123,7 @@ class Cliconf(CliconfBase):
def discard_changes(self):
self.send_command('exit discard')
def get_diff(self, candidate=None, running=None, match='line', diff_ignore_lines=None, path=None, replace=None):
def get_diff(self, candidate=None, running=None, diff_match='line', diff_ignore_lines=None, path=None, diff_replace=None):
diff = {}
device_operations = self.get_device_operations()
option_values = self.get_option_values()
@ -139,10 +131,10 @@ class Cliconf(CliconfBase):
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, ', '.join(option_values['diff_match'])))
if diff_match not in option_values['diff_match']:
raise ValueError("'match' value %s in invalid, valid values are %s" % (diff_match, ', '.join(option_values['diff_match'])))
if replace:
if diff_replace:
raise ValueError("'replace' in diff is not supported")
if diff_ignore_lines:
@ -169,7 +161,7 @@ class Cliconf(CliconfBase):
else:
candidate_commands = str(candidate).strip().split('\n')
if match == 'none':
if diff_match == 'none':
diff['config_diff'] = list(candidate_commands)
return diff