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

clean up generators (and avoid possible key errors)

parent 04babef5
No related branches found
No related tags found
1 merge request!1Feature/reporting 297 msr mdvpn endpoint
......@@ -1000,9 +1000,7 @@ def mdvpn():
return index
def _bgplu_peerings(asn, bgplu_index):
if asn not in bgplu_index:
yield False
for peering in bgplu_index[asn]:
for peering in bgplu_index.get(asn, []):
formatted_peering = {
"name": peering['description'],
"v4": peering['address'],
......@@ -1012,29 +1010,28 @@ def mdvpn():
yield formatted_peering
def _vpnrr_peerings(asn, vpnrr_index):
if asn not in vpnrr_index:
yield False
vrr_peering_group = vpnrr_index[asn]
# rearrange into index using ipv4 as key
# this will collect related entries under the same ipv4
ip_index = _make_group_index(vrr_peering_group, 'address')
for ip in ip_index:
ip_details = ip_index[ip] # a list of all info for given ipv4
hostnames = [item['hostname'] for item in ip_details]
description = ip_details[0]['description']
formatted_peering = {
"description": _get_consistent_description(description),
"v4": ip,
"hostname": hostnames
}
yield formatted_peering
if asn in vpnrr_index:
vrr_peering_group = vpnrr_index[asn]
# rearrange into index using ipv4 as key
# this will collect related entries under the same ipv4
ip_index = _make_group_index(vrr_peering_group, 'address')
for ip in ip_index:
ip_details = ip_index[ip] # a list of all info for given ipv4
hostnames = [item['hostname'] for item in ip_details]
description = ip_details[0]['description']
formatted_peering = {
"description": _get_consistent_description(description),
"v4": ip,
"hostname": hostnames
}
yield formatted_peering
def _peerings_for_nren(asn, bgplu_index, vpnrr_index):
return {
"asn": asn,
"AP": list(filter(None, _bgplu_peerings(asn, bgplu_index))),
"VRR": list(filter(None, _vpnrr_peerings(asn, vpnrr_index)))
"AP": list(_bgplu_peerings(asn, bgplu_index)),
"VRR": list(_vpnrr_peerings(asn, vpnrr_index))
}
r = common.get_current_redis()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment