mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Add diff capability in vyos edit_config (#41950)
* Add diff capability in vyos edit_config Fetch onbox diff within edit_config cliconf plugin and return it in response * Remove diff returned from ios edit_config * Fix CI failure * More CI fixes
This commit is contained in:
parent
e60da3feaf
commit
9acb5780bc
4 changed files with 25 additions and 29 deletions
|
@ -133,10 +133,9 @@ def load_config(module, commands, commit=False, comment=None):
|
||||||
connection = get_connection(module)
|
connection = get_connection(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = connection.edit_config(candidate=commands, commit=commit, diff=module._diff, comment=comment)
|
resp = connection.edit_config(candidate=commands, commit=commit, comment=comment)
|
||||||
resp = json.loads(resp)
|
resp = json.loads(resp)
|
||||||
diff_config = resp.get('diff')
|
|
||||||
except ConnectionError as exc:
|
except ConnectionError as exc:
|
||||||
module.fail_json(msg=to_text(exc))
|
module.fail_json(msg=to_text(exc))
|
||||||
|
|
||||||
return diff_config
|
return resp.get('diff')
|
||||||
|
|
|
@ -203,8 +203,6 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
|
||||||
|
|
||||||
:param replace: Boolean flag to indicate if running configuration should be completely
|
:param replace: Boolean flag to indicate if running configuration should be completely
|
||||||
replace by candidate configuration.
|
replace by candidate configuration.
|
||||||
:param diff: Boolean flag to indicate if configuration that is applied on remote host should
|
|
||||||
generated and returned in response or not
|
|
||||||
:param comment: Commit comment provided it is supported by remote host
|
:param comment: Commit comment provided it is supported by remote host
|
||||||
:return: Returns a json string with contains configuration applied on remote host, the returned
|
:return: Returns a json string with contains configuration applied on remote host, the returned
|
||||||
response on executing configuration commands and platform relevant data.
|
response on executing configuration commands and platform relevant data.
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Cliconf(CliconfBase):
|
||||||
return json.dumps(diff)
|
return json.dumps(diff)
|
||||||
|
|
||||||
@enable_mode
|
@enable_mode
|
||||||
def edit_config(self, candidate=None, commit=True, replace=False, diff=False, comment=None):
|
def edit_config(self, candidate=None, commit=True, replace=False, comment=None):
|
||||||
resp = {}
|
resp = {}
|
||||||
if not candidate:
|
if not candidate:
|
||||||
raise ValueError("must provide a candidate config to load")
|
raise ValueError("must provide a candidate config to load")
|
||||||
|
@ -151,11 +151,6 @@ class Cliconf(CliconfBase):
|
||||||
|
|
||||||
results.append(self.send_command('end'))
|
results.append(self.send_command('end'))
|
||||||
|
|
||||||
diff_config = None
|
|
||||||
if diff:
|
|
||||||
diff_config = candidate
|
|
||||||
|
|
||||||
resp['diff'] = diff_config
|
|
||||||
resp['response'] = results[1:-1]
|
resp['response'] = results[1:-1]
|
||||||
return json.dumps(resp)
|
return json.dumps(resp)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import collections
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ class Cliconf(CliconfBase):
|
||||||
out = self.send_command('show configuration commands')
|
out = self.send_command('show configuration commands')
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def edit_config(self, candidate=None, commit=True, replace=False, diff=False, comment=None):
|
def edit_config(self, candidate=None, commit=True, replace=False, comment=None):
|
||||||
resp = {}
|
resp = {}
|
||||||
if not candidate:
|
if not candidate:
|
||||||
raise ValueError('must provide a candidate config to load')
|
raise ValueError('must provide a candidate config to load')
|
||||||
|
@ -78,15 +79,16 @@ class Cliconf(CliconfBase):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for cmd in chain(['configure'], to_list(candidate)):
|
for cmd in chain(['configure'], to_list(candidate)):
|
||||||
results.append(self.send_command(cmd))
|
if not isinstance(cmd, collections.Mapping):
|
||||||
|
cmd = {'command': cmd}
|
||||||
|
|
||||||
|
results.append(self.send_command(**cmd))
|
||||||
|
|
||||||
diff_config = None
|
|
||||||
if diff:
|
|
||||||
out = self.get('compare')
|
out = self.get('compare')
|
||||||
out = to_text(out, errors='surrogate_or_strict')
|
out = to_text(out, errors='surrogate_or_strict')
|
||||||
if not out.startswith('No changes'):
|
diff_config = out if not out.startswith('No changes') else None
|
||||||
diff_config = out
|
|
||||||
|
|
||||||
|
if diff_config:
|
||||||
if commit:
|
if commit:
|
||||||
try:
|
try:
|
||||||
self.commit(comment)
|
self.commit(comment)
|
||||||
|
@ -98,9 +100,11 @@ class Cliconf(CliconfBase):
|
||||||
self.get('exit')
|
self.get('exit')
|
||||||
else:
|
else:
|
||||||
self.discard_changes()
|
self.discard_changes()
|
||||||
|
else:
|
||||||
|
self.get('exit')
|
||||||
|
|
||||||
resp['diff'] = diff_config
|
resp['diff'] = diff_config
|
||||||
resp['response'] = results[1:]
|
resp['response'] = results[1:-1]
|
||||||
return json.dumps(resp)
|
return json.dumps(resp)
|
||||||
|
|
||||||
def get(self, command=None, prompt=None, answer=None, sendonly=False):
|
def get(self, command=None, prompt=None, answer=None, sendonly=False):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue