Пример #1
0
    def test_time_last_sync(self):
        api = PeeringDB()

        # Test when no sync has been done
        self.assertEqual(api.get_last_sync_time(), 0)

        # Test of sync record with no objects
        time_of_sync = timezone.now()
        api.record_last_sync(time_of_sync, {"added": 0, "updated": 0, "deleted": 0})
        self.assertEqual(api.get_last_sync_time(), 0)

        # Test of sync record with one object
        time_of_sync = timezone.now()
        api.record_last_sync(time_of_sync, {"added": 1, "updated": 0, "deleted": 0})
        self.assertEqual(api.get_last_sync_time(), int(time_of_sync.timestamp()))
Пример #2
0
    def update_local(self, request):
        api = PeeringDB()
        synchronization = api.update_local_database(api.get_last_sync_time())

        return Response(
            {"synchronization": SynchronizationSerializer(synchronization).data}
        )
    def handle(self, *args, **options):
        self.logger.info("Syncing networks with PeeringDB...")

        api = PeeringDB()
        api.update_local_database(api.get_last_sync_time())

        self.logger.info("Syncing AS details with PeeringDB...")

        autonomous_systems = AutonomousSystem.objects.all()
        for autonomous_system in autonomous_systems:
            autonomous_system.synchronize_with_peeringdb()