How to use the peeringdb.models.NetworkIXLAN.objects.get function in peeringdb

To help you get started, we’ve selected a few peeringdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github respawner / peering-manager / peeringdb / http.py View on Github external
def get_ix_network(self, ix_network_id):
        """
        Return an IX network (and its details) given an IP address. The result
        can come from the local database (cache built with the peeringdb_sync
        command). If the IX network is not found in the local database, it will
        be fetched online which will take more time.
        """
        try:
            # Try to get from cached data
            network_ixlan = NetworkIXLAN.objects.get(id=ix_network_id)
        except NetworkIXLAN.DoesNotExist:
            # If no cached data found, query the API
            search = {"id": ix_network_id}
            result = self.lookup(NAMESPACES["network_internet_exchange_lan"], search)

            if not result or not result["data"]:
                return None

            network_ixlan = Object(result["data"][0])

        return network_ixlan
github respawner / peering-manager / peering / models.py View on Github external
def get_ix_list_for_peer_record(peer_record):
        ix_list = []
        # Find the Internet exchange given a NetworkIXLAN ID
        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)
github respawner / peering-manager / peeringdb / http.py View on Github external
come from the local database (cache built with the peeringdb_sync
        command). If the IX network is not found in the local database, it will
        be fetched online which will take more time.
        """
        if not ipv6_address and not ipv4_address:
            return None

        search = {}
        if ipv6_address:
            search.update({"ipaddr6": ipv6_address})
        if ipv4_address:
            search.update({"ipaddr4": ipv4_address})

        try:
            # Try to get from cached data
            network_ixlan = NetworkIXLAN.objects.get(**search)
        except NetworkIXLAN.DoesNotExist:
            # If no cached data found, query the API
            result = self.lookup(NAMESPACES["network_internet_exchange_lan"], search)

            if not result or not result["data"]:
                return None

            network_ixlan = Object(result["data"][0])

        return network_ixlan