From a27423a91d6c2e10240a4573650bfea6785cd9da Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Wed, 10 Feb 2021 14:37:31 +0000 Subject: [PATCH] schema compliance; corrected snmp look-up --- inventory_provider/routes/ims_classifier.py | 24 ++++++++------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/inventory_provider/routes/ims_classifier.py b/inventory_provider/routes/ims_classifier.py index c55a784a..00e90c1d 100644 --- a/inventory_provider/routes/ims_classifier.py +++ b/inventory_provider/routes/ims_classifier.py @@ -371,8 +371,8 @@ def peer_info(address_str: str) -> Response: # canonicalize the input address first ... try: - obj = ipaddress.ip_address(address_str) - address_str = obj.exploded + address = ipaddress.ip_address(address_str) + address_str = address.exploded except ValueError: raise ClassifierProcessingError( f'unable to parse {address_str} as an ip address') @@ -419,12 +419,6 @@ def peer_info(address_str: str) -> Response: if asn_group_info: result['asn'] = asn_group_info - try: - address = ipaddress.ip_address(address_str) - except ValueError: - raise ClassifierProcessingError( - f'unable to parse {address_str} as an ip address') - for interface in find_interfaces(address): ims_equipment = get_ims_equipment_name(interface["router"]) ims_interface = get_ims_interface(interface["interface name"]) @@ -435,16 +429,14 @@ def peer_info(address_str: str) -> Response: r ) - result['interfaces'].append( - { - 'interface': interface, - 'services': services_and_locs['services'] - } - ) + t = {'interface': interface} + if services_and_locs.get('services', None): + t['services'] = services_and_locs['services'] + result['interfaces'].append(t) result['locations'].extend(services_and_locs['locations']) snmp_info = r.get( - f'snmp-peerings:remote:{address}') + f'snmp-peerings:remote:{address_str}') if snmp_info: snmp_info = json.loads(snmp_info.decode('utf-8')) result['snmp'] = [ @@ -455,6 +447,8 @@ def peer_info(address_str: str) -> Response: } for h in snmp_info] result['locations'] = _remove_duplicates_from_list(result['locations']) + if not result.get('interfaces', None): + result.pop('interfaces', None) result = json.dumps(result) # cache this data for the next call r.set(cache_key, result.encode('utf-8')) -- GitLab