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

move nested function to global

parent 2fe76e87
No related branches found
No related tags found
No related merge requests found
......@@ -46,36 +46,39 @@ def get_trap_metadata(source_equipment, interface):
return Response(result, mimetype="application/json")
@routes.route("/peer-info/<address>", methods=['GET', 'POST'])
@common.require_accepts_json
def peer_info(address):
def ix_peering_group(ix_public_peer_info):
"""
TODO: this is probably the least efficient way of doing this
(if it's a problem, pre-compute these lists)
def _related_ix_peers(ix_public_peer_info):
"""
TODO: this is probably the least efficient way of doing this
(if it's a problem, pre-compute these lists)
:param ix_public_peer_info: ix public peer info loaded for address
:return:
"""
:param ix_public_peer_info: ix public peer info loaded for address
:return:
"""
address = ix_public_peer_info['name']
protocol = type(ipaddress.ip_address(address)).__name__
protocol = type(ipaddress.ip_address(address)).__name__
description = ix_public_peer_info['description']
assert description is not None # sanity: at least empty string
keyword = description.split(' ')[0] # regex needed??? (e.g. tabs???)
r = common.get_redis()
description = ix_public_peer_info['description']
assert description is not None # sanity: at least empty string
keyword = description.split(' ')[0] # regex needed??? (e.g. tabs???)
for k in r.keys('ix_public_peer:*'):
peer = r.get(k.decode('utf-8')).decode('utf-8')
peer = json.loads(peer)
assert peer['description'] is not None # sanity: as above...
if not peer['description'].startswith(keyword):
continue
peer_address = ipaddress.ip_address(peer['name'])
if protocol == type(peer_address).__name__:
yield peer['name']
r = common.get_redis()
for k in r.keys('ix_public_peer:*'):
peer = r.get(k.decode('utf-8')).decode('utf-8')
peer = json.loads(peer)
assert peer['description'] is not None # sanity: as above...
if not peer['description'].startswith(keyword):
continue
peer_address = ipaddress.ip_address(peer['name'])
if protocol == type(peer_address).__name__:
yield peer['name']
@routes.route("/peer-info/<address>", methods=['GET', 'POST'])
@common.require_accepts_json
def peer_info(address):
r = common.get_redis()
......@@ -86,7 +89,7 @@ def peer_info(address):
info = info.decode('utf-8')
result['ix-public-peer-info'] = json.loads(info)
result['ix-public-peer-group'] = list(
_related_ix_peers(result['ix-public-peer-info']))
ix_peering_group(result['ix-public-peer-info']))
info = r.get('vpn_rr_peer:%s' % address)
if info:
......
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