mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
add normalize_interface in module_utils and fix nxos_l3_interface module (#40598)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
@@ -439,3 +439,43 @@ def load_config(module, config, return_error=False, opts=None):
|
||||
def get_capabilities(module):
|
||||
conn = get_connection(module)
|
||||
return conn.get_capabilities()
|
||||
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user