31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
|
from rest_framework import viewsets
|
||
|
|
||
|
from apiv2.serializers import CrawlRunSerializer, ASLastSeenSerializer
|
||
|
from backend import crawler
|
||
|
from bgpdata.models import CrawlRun, ASLastSeen
|
||
|
|
||
|
|
||
|
class CrawlRunViewSet(viewsets.ReadOnlyModelViewSet):
|
||
|
"""Represents a CrawlRun.
|
||
|
|
||
|
Graph is shown if with_graph is passed as query arg.
|
||
|
With /live/ the current network is shown (internally, a crawl is triggered for each request)"""
|
||
|
queryset = CrawlRun.objects.all()
|
||
|
serializer_class = CrawlRunSerializer
|
||
|
|
||
|
def get_object(self):
|
||
|
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
||
|
if self.kwargs.get(lookup_url_kwarg) == "live":
|
||
|
net = crawler.get_current_network()
|
||
|
obj = crawler.make_crawl_from_net(net)
|
||
|
self.check_object_permissions(self.request, obj)
|
||
|
else:
|
||
|
obj = super().get_object()
|
||
|
|
||
|
return obj
|
||
|
|
||
|
|
||
|
class ASLastSeenViewSet(viewsets.ReadOnlyModelViewSet):
|
||
|
queryset = ASLastSeen.objects.all()
|
||
|
serializer_class = ASLastSeenSerializer
|