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>
This commit is contained in:
Trishna Guha 2018-06-14 22:02:12 +05:30 committed by GitHub
parent 0d885260a5
commit f170298332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -164,8 +164,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)

View file

@ -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)

View file

@ -80,8 +80,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