Skip to content
Snippets Groups Projects
Commit 4fdd1e16 authored by Robert Latta's avatar Robert Latta
Browse files

used existing code to ix and vpnrr info

parent 04b67088
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ from redis import Redis
from inventory_provider.db.ims import IMS_SERVICE_NAMES
from inventory_provider.routes import common
from inventory_provider.routes.classifier import _asn_group_info, \
_link_interface_info
_link_interface_info, _ix_peering_info, _vpn_rr_peering_info
routes = Blueprint("ims-inventory-data-classifier-support-routes", __name__)
......@@ -341,48 +341,6 @@ def get_juniper_link_info(source_equipment: str, interface: str) -> Response:
return Response(result, mimetype="application/json")
def ix_peering_info(peer_info: dict) -> dict:
"""
TODO: this is probably the least efficient way of doing this
(if it's a problem, pre-compute these lists)
:param peer_info: an element from ix_public_peer:address
:return:
"""
result = {
'peer': peer_info,
'group': [],
'router': []
}
try:
ipaddress.ip_address(peer_info['name'])
except ValueError:
raise ClassifierProcessingError(
f'unable to parse {peer_info["name"]} as an ip address')
description = peer_info['description']
assert description is not None # sanity
keyword = description.split(' ')[0] # regex needed??? (e.g. tabs???)
for doc in common.load_json_docs(
config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'],
key_pattern='ix_public_peer:*',
num_threads=10):
other = doc['value']
if other['router'] == peer_info['router']:
result['router'].append(other['name'])
assert other['description'] is not None # sanity: as above...
if other['description'].startswith(keyword):
result['group'].append(other['name'])
return result
def find_interfaces(address) -> Iterator:
"""
TODO: this is probably the least efficient way of doing this
......@@ -439,23 +397,20 @@ def peer_info(address_str: str) -> Response:
'locations': [],
}
info = r.get(f'ix_public_peer:{address_str}')
if info:
info = info.decode('utf-8')
info = json.loads(info)
result['ix-public-peer-info'] = ix_peering_info(info)
ix_peering_info = _ix_peering_info(r, address_str)
if ix_peering_info:
result['ix-public-peer-info'] = ix_peering_info
result['locations'].append(build_locations(
_location_from_equipment(
get_ims_equipment_name(info['router']), r)))
get_ims_equipment_name(
ix_peering_info['peer']['router']), r)))
info = r.get(f'vpn_rr_peer:{address_str}')
if info:
info = info.decode('utf-8')
info = json.loads(info)
result['vpn-rr-peer-info'] = info
vpn_rr_peering_info = _vpn_rr_peering_info(r, address_str)
if vpn_rr_peering_info:
result['vpn-rr-peer-info'] = vpn_rr_peering_info
result['locations'].append(build_locations(
_location_from_equipment(
get_ims_equipment_name(info['router']), r)))
get_ims_equipment_name(vpn_rr_peering_info['router']), r)))
asn_group_info = _asn_group_info(r, address_str)
if asn_group_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