nxos_interface TypeError fix (#32114)
* nxos_inteface TypeError fix Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Make sure that run_commands does not list of strings for json output Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * return default value to handle exception Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
de8d00b401
commit
b0e7c71716
2 changed files with 68 additions and 61 deletions
|
@ -34,7 +34,7 @@ from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.basic import env_fallback, return_values
|
from ansible.module_utils.basic import env_fallback, return_values
|
||||||
from ansible.module_utils.network_common import to_list, ComplexList
|
from ansible.module_utils.network_common import to_list, ComplexList
|
||||||
from ansible.module_utils.connection import exec_command
|
from ansible.module_utils.connection import exec_command
|
||||||
from ansible.module_utils.six import iteritems
|
from ansible.module_utils.six import iteritems, string_types
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
|
||||||
_DEVICE_CONNECTION = None
|
_DEVICE_CONNECTION = None
|
||||||
|
@ -169,6 +169,9 @@ class Cli:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
out = to_text(out).strip()
|
out = to_text(out).strip()
|
||||||
|
|
||||||
|
if item['output'] == 'json' and isinstance(out, string_types):
|
||||||
|
self._module.fail_json(msg='failed to retrieve output of %s in json format' % item['command'])
|
||||||
|
|
||||||
responses.append(out)
|
responses.append(out)
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
|
|
|
@ -275,72 +275,76 @@ def get_interface(intf, module):
|
||||||
try:
|
try:
|
||||||
body = execute_show_command(command, module)[0]
|
body = execute_show_command(command, module)[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
body = []
|
return {}
|
||||||
if body:
|
if body:
|
||||||
interface_table = body['TABLE_interface']['ROW_interface']
|
try:
|
||||||
if interface_table.get('eth_mode') == 'fex-fabric':
|
interface_table = body['TABLE_interface']['ROW_interface']
|
||||||
module.fail_json(msg='nxos_interface does not support interfaces with mode "fex-fabric"')
|
except KeyError:
|
||||||
intf_type = get_interface_type(intf)
|
return {}
|
||||||
if intf_type in ['portchannel', 'ethernet']:
|
if interface_table:
|
||||||
if not interface_table.get('eth_mode'):
|
if interface_table.get('eth_mode') == 'fex-fabric':
|
||||||
interface_table['eth_mode'] = 'layer3'
|
module.fail_json(msg='nxos_interface does not support interfaces with mode "fex-fabric"')
|
||||||
|
intf_type = get_interface_type(intf)
|
||||||
|
if intf_type in ['portchannel', 'ethernet']:
|
||||||
|
if not interface_table.get('eth_mode'):
|
||||||
|
interface_table['eth_mode'] = 'layer3'
|
||||||
|
|
||||||
if intf_type == 'ethernet':
|
if intf_type == 'ethernet':
|
||||||
key_map.update(base_key_map)
|
key_map.update(base_key_map)
|
||||||
key_map.update(mode_map)
|
key_map.update(mode_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
temp_dict = apply_value_map(mode_value_map, temp_dict)
|
temp_dict = apply_value_map(mode_value_map, temp_dict)
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
|
|
||||||
elif intf_type == 'svi':
|
elif intf_type == 'svi':
|
||||||
key_map.update(svi_map)
|
key_map.update(svi_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
attributes = get_manual_interface_attributes(intf, module)
|
attributes = get_manual_interface_attributes(intf, module)
|
||||||
interface['admin_state'] = str(attributes.get('admin_state',
|
interface['admin_state'] = str(attributes.get('admin_state',
|
||||||
'nxapibug'))
|
'nxapibug'))
|
||||||
interface['description'] = str(attributes.get('description',
|
interface['description'] = str(attributes.get('description',
|
||||||
'nxapi_bug'))
|
'nxapi_bug'))
|
||||||
command = 'show run interface {0}'.format(intf)
|
command = 'show run interface {0}'.format(intf)
|
||||||
body = execute_show_command(command, module)[0]
|
body = execute_show_command(command, module)[0]
|
||||||
if 'ip forward' in body:
|
if 'ip forward' in body:
|
||||||
interface['ip_forward'] = 'enable'
|
interface['ip_forward'] = 'enable'
|
||||||
else:
|
else:
|
||||||
interface['ip_forward'] = 'disable'
|
interface['ip_forward'] = 'disable'
|
||||||
if 'fabric forwarding mode anycast-gateway' in body:
|
if 'fabric forwarding mode anycast-gateway' in body:
|
||||||
interface['fabric_forwarding_anycast_gateway'] = True
|
interface['fabric_forwarding_anycast_gateway'] = True
|
||||||
else:
|
else:
|
||||||
interface['fabric_forwarding_anycast_gateway'] = False
|
interface['fabric_forwarding_anycast_gateway'] = False
|
||||||
|
|
||||||
elif intf_type == 'loopback':
|
elif intf_type == 'loopback':
|
||||||
key_map.update(base_key_map)
|
key_map.update(base_key_map)
|
||||||
key_map.pop('admin_state')
|
key_map.pop('admin_state')
|
||||||
key_map.update(loop_map)
|
key_map.update(loop_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
if not temp_dict.get('description'):
|
if not temp_dict.get('description'):
|
||||||
temp_dict['description'] = "None"
|
temp_dict['description'] = "None"
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
|
|
||||||
elif intf_type == 'management':
|
elif intf_type == 'management':
|
||||||
key_map.update(base_key_map)
|
key_map.update(base_key_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
|
|
||||||
elif intf_type == 'portchannel':
|
elif intf_type == 'portchannel':
|
||||||
key_map.update(base_key_map)
|
key_map.update(base_key_map)
|
||||||
key_map.update(mode_map)
|
key_map.update(mode_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
temp_dict = apply_value_map(mode_value_map, temp_dict)
|
temp_dict = apply_value_map(mode_value_map, temp_dict)
|
||||||
if not temp_dict.get('description'):
|
if not temp_dict.get('description'):
|
||||||
temp_dict['description'] = "None"
|
temp_dict['description'] = "None"
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
|
|
||||||
elif intf_type == 'nve':
|
elif intf_type == 'nve':
|
||||||
key_map.update(base_key_map)
|
key_map.update(base_key_map)
|
||||||
temp_dict = apply_key_map(key_map, interface_table)
|
temp_dict = apply_key_map(key_map, interface_table)
|
||||||
if not temp_dict.get('description'):
|
if not temp_dict.get('description'):
|
||||||
temp_dict['description'] = "None"
|
temp_dict['description'] = "None"
|
||||||
interface.update(temp_dict)
|
interface.update(temp_dict)
|
||||||
|
|
||||||
return interface
|
return interface
|
||||||
|
|
||||||
|
@ -369,7 +373,7 @@ def get_interfaces_dict(module):
|
||||||
try:
|
try:
|
||||||
body = execute_show_command(command, module)[0]
|
body = execute_show_command(command, module)[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
body = {}
|
return {}
|
||||||
|
|
||||||
interfaces = {
|
interfaces = {
|
||||||
'ethernet': [],
|
'ethernet': [],
|
||||||
|
|
Loading…
Reference in a new issue