From c9fa189a18e68bf2d6d1a15e299a79f202b3ae8a Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Fri, 1 Mar 2019 13:19:48 +0100 Subject: [PATCH] added interfaces to peer-info result --- inventory_provider/routes/classifier.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index c98f7068..9f0f372a 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -75,6 +75,24 @@ def ix_peering_group(ix_public_peer_info): yield peer['name'] +def find_interfaces(address_string): + """ + TODO: this is probably the least efficient way of doing this + (if it's a problem, pre-compute these lists) + + :param address: string representation of an address + :return: + """ + address = ipaddress.ip_address(address_string) + r = common.get_redis() + for k in r.keys('reverse_interface_addresses:*'): + info = r.get(k.decode('utf-8')).decode('utf-8') + info = json.loads(info) + interface = ipaddress.ip_interface(info['interface address']) + if address in interface.network: + yield info + + @routes.route("/peer-info/<address>", methods=['GET', 'POST']) @common.require_accepts_json def peer_info(address): @@ -96,6 +114,10 @@ def peer_info(address): info = info.decode('utf-8') result['vpn-rr-peer-info'] = json.loads(info) + interfaces = list(find_interfaces(address)) + if interfaces: + result['interfaces'] = interfaces + if not result: return Response( response='no peering info found for %s' % address, -- GitLab