Skip to content
Snippets Groups Projects
Commit c9fa189a authored by Erik Reid's avatar Erik Reid
Browse files

added interfaces to peer-info result

parent a5dd6ba4
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment