Skip to content
Snippets Groups Projects
Commit c4cc14ce authored by Sam Roberts's avatar Sam Roberts
Browse files

functionally complete, needs tests & docs

parent a1fdcd4f
No related branches found
No related tags found
1 merge request!2Feature/reporting 307 msr vpn proxy endpoint
......@@ -321,6 +321,31 @@ MDVPN_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/mdvpn_group'}
}
VPN_PROXY_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'vpn_proxy_peering': {
'type': 'object',
'properties': {
# TODO: THIS
},
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/vpn_proxy_peering'}
}
DOMAIN_TO_POP_MAPPING = {
"mad.es": "Madrid",
"bra.sk": "Bratislava",
"vie.at": "Vienna",
"gen.ch": "Geneva",
"fra.de": "Frankfurt",
"pra.cz": "Prague",
"ams.nl": "Amsterdam"
}
@routes.after_request
def after_request(resp):
......@@ -1068,8 +1093,49 @@ def vpn_proxy():
return False
return "L3VPN" in desc
def _look_up_city_from_hostname(hostname):
for snippet in DOMAIN_TO_POP_MAPPING:
if snippet in hostname:
return DOMAIN_TO_POP_MAPPING[snippet]
def _extract_nren_from_description(desc, group):
"""
Retrieve the relevant NREN from the peering description and group.
This approach is, by its nature, very fragile to any changes to
descriptions, and should be revisited when that happens.
:param desc: description of a VPN-Proxy peering
:param group: group of the same VPN-Proxy peering
:return: name of the NREN
"""
if group == "PRACE":
# common trait: the NREN is the first word in the description
return desc.split(' ')[0]
else:
# only other group is XiFi, and only CESNet is relevant
return 'CESNet'
def _format_peerings(vpnproxy):
for peering in vpnproxy:
if _is_relevant(peering):
desc = peering["description"]
group = peering["group"]
hostname = peering["hostname"]
formatted_peering = {
"pop": _look_up_city_from_hostname(hostname),
"nren": _extract_nren_from_description(desc, group),
"group": group,
"v4": peering.get("address")
}
yield formatted_peering
else:
yield False
r = common.get_current_redis()
vpnproxy = json.loads(r.get('juniper-peerings:logical-system:VPN-PROXY').decode('utf-8'))
test = [item for item in vpnproxy if _is_relevant(item)]
response = json.dumps(test)
cache_key = 'classifier-cache:msr:vpn-proxy'
response = _ignore_cache_or_retrieve(request, cache_key, r)
if not response:
vpnproxy = json.loads(r.get('juniper-peerings:logical-system:VPN-PROXY').decode('utf-8'))
peerings = list(filter(None, _format_peerings(vpnproxy)))
response = json.dumps(peerings)
return Response(response, mimetype='application/json')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment