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:
parent
36c8441c6d
commit
a7421e8611
4 changed files with 18 additions and 23 deletions
|
@ -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):
|
def apply_key_map(key_map, table):
|
||||||
new_dict = {}
|
new_dict = {}
|
||||||
for key in table:
|
for key in table:
|
||||||
|
@ -189,11 +174,11 @@ def apply_key_map(key_map, table):
|
||||||
|
|
||||||
|
|
||||||
def get_interface_mode(interface, intf_type, module):
|
def get_interface_mode(interface, intf_type, module):
|
||||||
command = 'show interface {0}'.format(interface)
|
command = 'show interface {0} | json'.format(interface)
|
||||||
interface = {}
|
interface = {}
|
||||||
mode = 'unknown'
|
mode = 'unknown'
|
||||||
try:
|
try:
|
||||||
body = execute_show_command(command, module)[0]
|
body = run_commands(module, [command])[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -208,7 +193,7 @@ def get_interface_mode(interface, intf_type, module):
|
||||||
|
|
||||||
|
|
||||||
def get_hsrp_group(group, interface, 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 = {}
|
||||||
|
|
||||||
hsrp_key = {
|
hsrp_key = {
|
||||||
|
@ -224,9 +209,9 @@ def get_hsrp_group(group, interface, module):
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
body = execute_show_command(command, module)[0]
|
body = run_commands(module, [command])[0]
|
||||||
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
|
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
|
||||||
except (AttributeError, IndexError, TypeError):
|
except (AttributeError, IndexError, TypeError, KeyError):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if isinstance(hsrp_table, dict):
|
if isinstance(hsrp_table, dict):
|
||||||
|
@ -349,7 +334,7 @@ def is_default(interface, module):
|
||||||
command = 'show run interface {0}'.format(interface)
|
command = 'show run interface {0}'.format(interface)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
body = execute_show_command(command, module)[0]
|
body = run_commands(module, [command], check_rc=False)[0]
|
||||||
if 'invalid' in body.lower():
|
if 'invalid' in body.lower():
|
||||||
return 'DNE'
|
return 'DNE'
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -94,8 +94,11 @@ class Cliconf(CliconfBase):
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
result = {}
|
result = {}
|
||||||
result['rpc'] = self.get_base_rpc()
|
result['rpc'] = self.get_base_rpc()
|
||||||
result['network_api'] = 'cliconf'
|
|
||||||
result['device_info'] = self.get_device_info()
|
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)
|
return json.dumps(result)
|
||||||
|
|
||||||
# Imported from module_utils
|
# Imported from module_utils
|
||||||
|
|
|
@ -95,8 +95,11 @@ class Cliconf(CliconfBase):
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
result = {}
|
result = {}
|
||||||
result['rpc'] = self.get_base_rpc()
|
result['rpc'] = self.get_base_rpc()
|
||||||
result['network_api'] = 'cliconf'
|
|
||||||
result['device_info'] = self.get_device_info()
|
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)
|
return json.dumps(result)
|
||||||
|
|
||||||
# Migrated from module_utils
|
# Migrated from module_utils
|
||||||
|
|
|
@ -89,9 +89,13 @@ class HttpApi:
|
||||||
out = to_text(exc)
|
out = to_text(exc)
|
||||||
|
|
||||||
out = to_list(out)
|
out = to_list(out)
|
||||||
|
if not out[0]:
|
||||||
|
return out
|
||||||
|
|
||||||
for index, response in enumerate(out):
|
for index, response in enumerate(out):
|
||||||
if response[0] == '{':
|
if response[0] == '{':
|
||||||
out[index] = json.loads(response)
|
out[index] = json.loads(response)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue