From b14f256d4156fe53ea4e69df56537af9223d47ae Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Tue, 14 Aug 2018 11:35:09 +0530 Subject: [PATCH] Fixes ios_l2_interface and ios_vlan not working on certain interface types issue (#43819) * Fixes #43654 and #43582 * Remove q statement * Fix shippable errors * Fix more shippable errors * Fix unittest --- lib/ansible/module_utils/network/ios/ios.py | 48 +++++++++++++++++++ .../modules/network/ios/ios_l2_interface.py | 2 +- lib/ansible/modules/network/ios/ios_vlan.py | 4 +- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/network/ios/ios.py b/lib/ansible/module_utils/network/ios/ios.py index 306e176b73e..ac79357033d 100644 --- a/lib/ansible/module_utils/network/ios/ios.py +++ b/lib/ansible/module_utils/network/ios/ios.py @@ -145,3 +145,51 @@ def load_config(module, commands): return resp.get('response') except ConnectionError as exc: module.fail_json(msg=to_text(exc)) + + +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('gi'): + if_type = 'GigabitEthernet' + elif name.lower().startswith('te'): + if_type = 'TenGigabitEthernet' + elif name.lower().startswith('fa'): + if_type = 'FastEthernet' + elif name.lower().startswith('fo'): + if_type = 'FortyGigabitEthernet' + elif 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: + if_number = number_list[-1].strip() + else: + if_number = _get_number(name) + + if if_type: + proper_interface = if_type + if_number + else: + proper_interface = name + + return proper_interface diff --git a/lib/ansible/modules/network/ios/ios_l2_interface.py b/lib/ansible/modules/network/ios/ios_l2_interface.py index ac48f576439..a3d983e48ac 100644 --- a/lib/ansible/modules/network/ios/ios_l2_interface.py +++ b/lib/ansible/modules/network/ios/ios_l2_interface.py @@ -118,7 +118,7 @@ from ansible.module_utils.network.ios.ios import ios_argument_spec def get_interface_type(interface): intf_type = 'unknown' - if interface.upper()[:2] in ('ET', 'GI'): + if interface.upper()[:2] in ('ET', 'GI', 'FA', 'TE', 'FO'): intf_type = 'ethernet' elif interface.upper().startswith('VL'): intf_type = 'svi' diff --git a/lib/ansible/modules/network/ios/ios_vlan.py b/lib/ansible/modules/network/ios/ios_vlan.py index 7a186777c77..e8ac49cc93d 100644 --- a/lib/ansible/modules/network/ios/ios_vlan.py +++ b/lib/ansible/modules/network/ios/ios_vlan.py @@ -103,7 +103,7 @@ from copy import deepcopy from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.ios.ios import load_config, run_commands +from ansible.module_utils.network.ios.ios import load_config, run_commands, normalize_interface from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args @@ -231,7 +231,7 @@ def parse_to_logical_rows(out): def map_ports_str_to_list(ports_str): - return list(filter(bool, (p.strip().replace('Gi', 'GigabitEthernet') for p in ports_str.split(', ')))) + return list(filter(bool, (normalize_interface(p.strip()) for p in ports_str.split(', ')))) def parse_to_obj(logical_rows):