nxos_linkagg normalize interface (#39591)

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2018-05-08 11:15:05 +05:30 committed by GitHub
parent ef577b71cc
commit 3c35dd4f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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