mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
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:
parent
0d885260a5
commit
f170298332
3 changed files with 12 additions and 5 deletions
|
@ -164,8 +164,7 @@ class Cli:
|
||||||
msgs = []
|
msgs = []
|
||||||
try:
|
try:
|
||||||
responses = connection.edit_config(config)
|
responses = connection.edit_config(config)
|
||||||
out = json.loads(responses)[1:-1]
|
msg = json.loads(responses)
|
||||||
msg = out
|
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
code = getattr(e, 'code', 1)
|
code = getattr(e, 'code', 1)
|
||||||
message = getattr(e, 'err', e)
|
message = getattr(e, 'err', e)
|
||||||
|
|
|
@ -25,6 +25,7 @@ from itertools import chain
|
||||||
|
|
||||||
from ansible.errors import AnsibleConnectionFailure
|
from ansible.errors import AnsibleConnectionFailure
|
||||||
from ansible.module_utils._text import to_bytes, to_text
|
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.module_utils.network.common.utils import to_list
|
||||||
from ansible.plugins.cliconf import CliconfBase
|
from ansible.plugins.cliconf import CliconfBase
|
||||||
from ansible.plugins.connection.network_cli import Connection as NetworkCli
|
from ansible.plugins.connection.network_cli import Connection as NetworkCli
|
||||||
|
@ -86,8 +87,8 @@ class Cliconf(CliconfBase):
|
||||||
responses = []
|
responses = []
|
||||||
for cmd in chain(['configure'], to_list(command), ['end']):
|
for cmd in chain(['configure'], to_list(command), ['end']):
|
||||||
responses.append(self.send_command(cmd))
|
responses.append(self.send_command(cmd))
|
||||||
|
resp = responses[1:-1]
|
||||||
return json.dumps(responses)
|
return json.dumps(resp)
|
||||||
|
|
||||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||||
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
||||||
|
|
|
@ -80,8 +80,15 @@ class HttpApi:
|
||||||
|
|
||||||
# Migrated from module_utils
|
# Migrated from module_utils
|
||||||
def edit_config(self, command):
|
def edit_config(self, command):
|
||||||
|
resp = list()
|
||||||
responses = self.send_request(command, output='config')
|
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):
|
def run_commands(self, commands, check_rc=True):
|
||||||
"""Runs list of commands on remote device and returns results
|
"""Runs list of commands on remote device and returns results
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue