mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Fix ios and vyos cliconf edit_config return type (#41896)
* Fix ios and vyos cliconf edit_config return type Modify cliconf edit_config api to return a json string with diff and response received from remote host for ios and vyos. * Doc change
This commit is contained in:
parent
d4b9105c9c
commit
b84adfd885
5 changed files with 21 additions and 8 deletions
|
@ -166,7 +166,8 @@ def load_config(module, commands):
|
||||||
connection = get_connection(module)
|
connection = get_connection(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
diff, response = connection.edit_config(commands)
|
resp = connection.edit_config(commands)
|
||||||
return response
|
resp = json.loads(resp)
|
||||||
|
return resp.get('response')
|
||||||
except ConnectionError as exc:
|
except ConnectionError as exc:
|
||||||
module.fail_json(msg=to_text(exc))
|
module.fail_json(msg=to_text(exc))
|
||||||
|
|
|
@ -133,7 +133,9 @@ def load_config(module, commands, commit=False, comment=None):
|
||||||
connection = get_connection(module)
|
connection = get_connection(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
diff_config, resp = connection.edit_config(candidate=commands, commit=commit, diff=module._diff, comment=comment)
|
resp = connection.edit_config(candidate=commands, commit=commit, diff=module._diff, comment=comment)
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
|
@ -206,9 +206,13 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:param diff: Boolean flag to indicate if configuration that is applied on remote host should
|
:param diff: Boolean flag to indicate if configuration that is applied on remote host should
|
||||||
generated and returned in response or not
|
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 tuple, the first entry of tupe is configuration diff if diff flag is enable else
|
:return: Returns a json string with contains configuration applied on remote host, the returned
|
||||||
it is None. Second entry is the list of response received from remote host on executing
|
response on executing configuration commands and platform relevant data.
|
||||||
configuration commands.
|
{
|
||||||
|
"diff": "",
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ class Cliconf(CliconfBase):
|
||||||
|
|
||||||
@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, diff=False, comment=None):
|
||||||
|
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")
|
||||||
|
|
||||||
|
@ -154,7 +155,9 @@ class Cliconf(CliconfBase):
|
||||||
if diff:
|
if diff:
|
||||||
diff_config = candidate
|
diff_config = candidate
|
||||||
|
|
||||||
return diff_config, results[1:-1]
|
resp['diff'] = diff_config
|
||||||
|
resp['response'] = results[1:-1]
|
||||||
|
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):
|
||||||
if not command:
|
if not command:
|
||||||
|
|
|
@ -61,6 +61,7 @@ class Cliconf(CliconfBase):
|
||||||
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, diff=False, comment=None):
|
||||||
|
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')
|
||||||
|
|
||||||
|
@ -98,7 +99,9 @@ class Cliconf(CliconfBase):
|
||||||
else:
|
else:
|
||||||
self.discard_changes()
|
self.discard_changes()
|
||||||
|
|
||||||
return diff_config, results[1:]
|
resp['diff'] = diff_config
|
||||||
|
resp['response'] = results[1:]
|
||||||
|
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):
|
||||||
if not command:
|
if not command:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue