nxos_snmp_* fixes : Fixes #30997, #30999 (#31000)

* add codeblock to handle 5K platform for nxos_snmp_host

* fix get_snmp_traps for 5K platform

* Make shippable happy
This commit is contained in:
rahushen 2017-10-06 08:51:59 -04:00 committed by Trishna Guha
parent 0218fdcd80
commit 48f4643a66
2 changed files with 63 additions and 10 deletions

View file

@ -150,6 +150,14 @@ def get_snmp_host(host, module):
'secname': 'community'
}
host_map_5k = {
'port': 'udp',
'version': 'version',
'sec_level': 'v3',
'notif_type': 'snmp_type',
'commun_or_user': 'community'
}
resource = {}
if body:
@ -177,8 +185,35 @@ def get_snmp_host(host, module):
if vrf:
host_resource['vrf'] = vrf.split(':')[1].strip()
resource[key] = host_resource
except KeyError:
# Handle the 5K case
try:
resource_table = body[0]['TABLE_hosts']['ROW_hosts']
except (KeyError, AttributeError, TypeError):
if isinstance(resource_table, dict):
resource_table = [resource_table]
for each in resource_table:
key = str(each['address'])
src = each.get('src_intf')
host_resource = apply_key_map(host_map_5k, each)
if src:
host_resource['src_intf'] = src.split(':')[1].strip()
vrf_filt = each.get('TABLE_filter_vrf')
if vrf_filt:
vrf_filter = vrf_filt['ROW_filter_vrf']['filter_vrf_name'].split(',')
filters = [vrf.strip() for vrf in vrf_filter]
host_resource['vrf_filter'] = filters
vrf = each.get('use_vrf_name')
if vrf:
host_resource['vrf'] = vrf.strip()
resource[key] = host_resource
except (KeyError, AttributeError, TypeError):
return resource
except (AttributeError, TypeError):
return resource
find = resource.get(host)

View file

@ -120,17 +120,21 @@ def get_snmp_traps(group, module):
'isEnabled': 'enabled'
}
resource = {}
trap_key_5k = {
'trap': 'trap',
'enabled': 'enabled'
}
resource = {}
feature_list = ['aaa', 'bridge', 'callhome', 'cfs', 'config',
'entity', 'feature-control', 'hsrp', 'license',
'link', 'lldp', 'ospf', 'pim', 'rf', 'rmon',
'snmp', 'storm-control', 'stpx', 'sysmgr',
'system', 'upgrade', 'vtp']
try:
resource_table = body[0]['TABLE_snmp_trap']['ROW_snmp_trap']
for each_feature in ['aaa', 'bridge', 'callhome', 'cfs', 'config',
'entity', 'feature-control', 'hsrp', 'license',
'link', 'lldp', 'ospf', 'pim', 'rf', 'rmon',
'snmp', 'storm-control', 'stpx', 'sysmgr',
'system', 'upgrade', 'vtp']:
for each_feature in feature_list:
resource[each_feature] = []
for each_resource in resource_table:
@ -139,8 +143,23 @@ def get_snmp_traps(group, module):
if key != 'Generic':
resource[key].append(mapped_trap)
except KeyError:
try:
resource_table = body[0]['TABLE_mib']['ROW_mib']
except (KeyError, AttributeError):
for each_feature in feature_list:
resource[each_feature] = []
for each_resource in resource_table:
key = str(each_resource['mib'])
each_resource = each_resource['TABLE_trap']['ROW_trap']
mapped_trap = apply_key_map(trap_key_5k, each_resource)
if key != 'Generic':
resource[key].append(mapped_trap)
except (KeyError, AttributeError):
return resource
except AttributeError:
return resource
find = resource.get(group, None)
@ -221,7 +240,6 @@ def main():
existing = get_snmp_traps(group, module)
commands = get_trap_commands(group, state, existing, module)
cmds = flatten_list(commands)
if cmds:
results['changed'] = True