Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def statistics(self, request):
return Response(
{
"contact-count": Contact.objects.count(),
"network-count": Network.objects.count(),
"network-ixlan-count": NetworkIXLAN.objects.count(),
"peer-record-count": PeerRecord.objects.count(),
}
for ix in InternetExchange.objects.exclude(peeringdb_id__isnull=True).exclude(
peeringdb_id=0
):
# Get the IXLAN corresponding to our network
try:
ixlan = NetworkIXLAN.objects.get(id=ix.peeringdb_id)
except NetworkIXLAN.DoesNotExist:
InternetExchangePeeringSession.logger.debug(
"NetworkIXLAN with ID {} not found, ignoring IX {}".format(
ix.peeringdb_id, ix.name
)
)
continue
# Get a potentially matching IXLAN
peer_ixlan = NetworkIXLAN.objects.filter(
id=peer_record.network_ixlan.id, ix_id=ixlan.ix_id
)
# IXLAN found lets get out
if peer_ixlan:
ix_list.append(ix)
return ix_list
def get_ix_networks_for_asn(self, asn):
"""
Returns a list of all IX networks an AS is connected to.
"""
# Try to get from cached data
network_ixlans = NetworkIXLAN.objects.filter(asn=asn)
# If nothing found in cache, try to fetch data online
if not network_ixlans:
search = {"asn": asn}
result = self.lookup(NAMESPACES["network_internet_exchange_lan"], search)
if not result or not result["data"]:
return None
network_ixlans = []
for ix_network in result["data"]:
network_ixlans.append(Object(ix_network))
return network_ixlans
def get(self, request):
if not request.user.is_staff and not request.user.is_superuser:
messages.error(request, "You do not have the rights to index peer records.")
return redirect(reverse("home"))
last_synchronization = PeeringDB().get_last_synchronization()
sync_time = last_synchronization.time if last_synchronization else 0
context = {
"last_sync_time": sync_time,
"peeringdb_contact_count": Contact.objects.count(),
"peeringdb_network_count": Network.objects.count(),
"peeringdb_networkixlan_count": NetworkIXLAN.objects.count(),
"peer_record_count": PeerRecord.objects.count(),
}
return render(request, "peeringdb/cache.html", context)