fix nxos edit_config for httpapi and have uniform load_config (#41358)

* fix nxos load_config for httpapi and migrate to cliconf

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* add comment

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* address review comment

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* address review comment

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
(cherry picked from commit f170298332)
pull/41597/head
Trishna Guha 7 years ago committed by Matt Clay
parent 09aae2e33d
commit dcfea7d822

@ -160,8 +160,7 @@ class Cli:
msgs = []
try:
responses = connection.edit_config(config)
out = json.loads(responses)[1:-1]
msg = out
msg = json.loads(responses)
except ConnectionError as e:
code = getattr(e, 'code', 1)
message = getattr(e, 'err', e)

@ -25,6 +25,7 @@ from itertools import chain
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.cliconf import CliconfBase
from ansible.plugins.connection.network_cli import Connection as NetworkCli
@ -86,8 +87,8 @@ class Cliconf(CliconfBase):
responses = []
for cmd in chain(['configure'], to_list(command), ['end']):
responses.append(self.send_command(cmd))
return json.dumps(responses)
resp = responses[1:-1]
return json.dumps(resp)
def get(self, command, prompt=None, answer=None, sendonly=False):
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)

@ -75,8 +75,15 @@ class HttpApi:
# Migrated from module_utils
def edit_config(self, command):
resp = list()
responses = self.send_request(command, output='config')
return json.dumps(responses)
for response in to_list(responses):
if response != '{}':
resp.append(response)
if not resp:
resp = ['']
return json.dumps(resp)
def run_commands(self, commands, check_rc=True):
"""Runs list of commands on remote device and returns results

Loading…
Cancel
Save