1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

httpapi fix nxos (#40806)

* httpapi fix nxos

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

* nxos_hsrp fix

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2018-05-29 21:43:34 +05:30 committed by GitHub
parent 36c8441c6d
commit a7421e8611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 23 deletions

View file

@ -160,21 +160,6 @@ PARAM_TO_DEFAULT_KEYMAP = {
}
def execute_show_command(command, module):
device_info = get_capabilities(module)
network_api = device_info.get('network_api', 'nxapi')
if network_api == 'cliconf':
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif network_api == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
return body
def apply_key_map(key_map, table):
new_dict = {}
for key in table:
@ -189,11 +174,11 @@ def apply_key_map(key_map, table):
def get_interface_mode(interface, intf_type, module):
command = 'show interface {0}'.format(interface)
command = 'show interface {0} | json'.format(interface)
interface = {}
mode = 'unknown'
try:
body = execute_show_command(command, module)[0]
body = run_commands(module, [command])[0]
except IndexError:
return None
@ -208,7 +193,7 @@ def get_interface_mode(interface, intf_type, module):
def get_hsrp_group(group, interface, module):
command = 'show hsrp group {0} all'.format(group)
command = 'show hsrp group {0} all | json'.format(group)
hsrp = {}
hsrp_key = {
@ -224,9 +209,9 @@ def get_hsrp_group(group, interface, module):
}
try:
body = execute_show_command(command, module)[0]
body = run_commands(module, [command])[0]
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
except (AttributeError, IndexError, TypeError):
except (AttributeError, IndexError, TypeError, KeyError):
return {}
if isinstance(hsrp_table, dict):
@ -349,7 +334,7 @@ def is_default(interface, module):
command = 'show run interface {0}'.format(interface)
try:
body = execute_show_command(command, module)[0]
body = run_commands(module, [command], check_rc=False)[0]
if 'invalid' in body.lower():
return 'DNE'
else:

View file

@ -94,8 +94,11 @@ class Cliconf(CliconfBase):
def get_capabilities(self):
result = {}
result['rpc'] = self.get_base_rpc()
result['network_api'] = 'cliconf'
result['device_info'] = self.get_device_info()
if isinstance(self._connection, NetworkCli):
result['network_api'] = 'cliconf'
else:
result['network_api'] = 'eapi'
return json.dumps(result)
# Imported from module_utils

View file

@ -95,8 +95,11 @@ class Cliconf(CliconfBase):
def get_capabilities(self):
result = {}
result['rpc'] = self.get_base_rpc()
result['network_api'] = 'cliconf'
result['device_info'] = self.get_device_info()
if isinstance(self._connection, NetworkCli):
result['network_api'] = 'cliconf'
else:
result['network_api'] = 'nxapi'
return json.dumps(result)
# Migrated from module_utils

View file

@ -89,9 +89,13 @@ class HttpApi:
out = to_text(exc)
out = to_list(out)
if not out[0]:
return out
for index, response in enumerate(out):
if response[0] == '{':
out[index] = json.loads(response)
return out