From 3c35dd4f7f8e3ce163451fc879ce8e29f1be801b Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Tue, 8 May 2018 11:15:05 +0530 Subject: [PATCH] nxos_linkagg normalize interface (#39591) Signed-off-by: Trishna Guha --- .../modules/network/nxos/nxos_linkagg.py | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_linkagg.py b/lib/ansible/modules/network/nxos/nxos_linkagg.py index 2437ebdc3d7..48d8fb16a29 100644 --- a/lib/ansible/modules/network/nxos/nxos_linkagg.py +++ b/lib/ansible/modules/network/nxos/nxos_linkagg.py @@ -132,6 +132,46 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.utils import remove_default_spec +def normalize_interface(name): + """Return the normalized interface name + """ + if not name: + return + + def _get_number(name): + digits = '' + for char in name: + if char.isdigit() or char in '/.': + digits += char + return digits + + if name.lower().startswith('et'): + if_type = 'Ethernet' + elif name.lower().startswith('vl'): + if_type = 'Vlan' + elif name.lower().startswith('lo'): + if_type = 'loopback' + elif name.lower().startswith('po'): + if_type = 'port-channel' + elif name.lower().startswith('nv'): + if_type = 'nve' + else: + if_type = None + + number_list = name.split(' ') + if len(number_list) == 2: + number = number_list[-1].strip() + else: + number = _get_number(name) + + if if_type: + proper_interface = if_type + number + else: + proper_interface = name + + return proper_interface + + def execute_show_command(command, module): device_info = get_capabilities(module) network_api = device_info.get('network_api', 'nxapi') @@ -244,14 +284,20 @@ def map_params_to_obj(module): d = item.copy() d['group'] = str(d['group']) d['min_links'] = str(d['min_links']) + if d['members']: + d['members'] = [normalize_interface(i) for i in d['members']] obj.append(d) else: + members = None + if module.params['members']: + members = [normalize_interface(i) for i in module.params['members']] + obj.append({ 'group': str(module.params['group']), 'mode': module.params['mode'], 'min_links': str(module.params['min_links']), - 'members': module.params['members'], + 'members': members, 'state': module.params['state'] }) @@ -290,10 +336,10 @@ def get_members(channel): return list() if isinstance(interfaces, dict): - members.append(interfaces.get('port')) + members.append(normalize_interface(interfaces.get('port'))) elif isinstance(interfaces, list): for i in interfaces: - members.append(i.get('port')) + members.append(normalize_interface(i.get('port'))) return members