How to use the peeringdb.models.PeerRecord 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 / peering / models.py View on Github external
def exists_in_peeringdb(self):
        """
        Returns True if a PeerRecord exists for this session's IP.
        """
        lookup = {
            "network_ixlan__ipaddr{}".format(self.ip_address.version): str(
                self.ip_address
            )
        }
        try:
            PeerRecord.objects.get(**lookup)
            return True
        except PeerRecord.DoesNotExist:
            pass
        return False
github respawner / peering-manager / peeringdb / models.py View on Github external
# Try finding if the PeerRecord already exists
            PeerRecord.objects.get(network=network, network_ixlan=self)
        except Network.DoesNotExist:
            # The network does not exist, well not much to do
            self.logger.debug(
                "network with as%s does not exist, required for "
                "peer record creation",
                self.asn,
            )
        except PeerRecord.DoesNotExist:
            # But if the exception is raised, it does not
            peer_record_exists = False

        # If the PeerRecord does not exist, create it
        if not peer_record_exists:
            PeerRecord.objects.create(network=network, network_ixlan=self)
            self.logger.debug(
                "peer record created with as%s and ixlan id %s", self.asn, self.ixlan_id
            )
        else:
            self.logger.debug(
                "peer record with as%s and ixlan id %s exists", self.asn, self.ixlan_id
            )
github respawner / peering-manager / peeringdb / http.py View on Github external
self.logger.debug(
                        "network ixlan with as%s and ixlan id %s"
                        " ignored, no ipv6 and no ipv4",
                        network_ixlan.asn,
                        network_ixlan.ixlan_id,
                    )
                    continue

                network = None
                try:
                    network = Network.objects.get(asn=network_ixlan.asn)
                except Network.DoesNotExist:
                    self.logger.debug("unable to find network as%s", network_ixlan.asn)

                if network:
                    PeerRecord.objects.create(
                        network=network, network_ixlan=network_ixlan
                    )
                    self.logger.debug(
                        "peer record with network as%s and ixlan" "id %s created",
                        network_ixlan.asn,
                        network_ixlan.ixlan_id,
                    )
                    indexed += 1
                else:
                    self.logger.debug(
                        "network ixlan with as%s and ixlan id %s" " ignored",
                        network_ixlan.asn,
                        network_ixlan.ixlan_id,
                    )

            return indexed
github respawner / peering-manager / peeringdb / views.py View on Github external
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)
github respawner / peering-manager / peeringdb / http.py View on Github external
def clear_local_database(self):
        """
        Delete all data related to the local database. This can be used to get a
        fresh start.
        """
        for model in [Contact, Network, NetworkIXLAN, PeerRecord, Synchronization]:
            model.objects.all().delete()
github respawner / peering-manager / peeringdb / models.py View on Github external
network = None
        peer_record_exists = True

        try:
            # Try guessing the Network given its ASN
            network = Network.objects.get(asn=self.asn)
            # Try finding if the PeerRecord already exists
            PeerRecord.objects.get(network=network, network_ixlan=self)
        except Network.DoesNotExist:
            # The network does not exist, well not much to do
            self.logger.debug(
                "network with as%s does not exist, required for "
                "peer record creation",
                self.asn,
            )
        except PeerRecord.DoesNotExist:
            # But if the exception is raised, it does not
            peer_record_exists = False

        # If the PeerRecord does not exist, create it
        if not peer_record_exists:
            PeerRecord.objects.create(network=network, network_ixlan=self)
            self.logger.debug(
                "peer record created with as%s and ixlan id %s", self.asn, self.ixlan_id
            )
        else:
            self.logger.debug(
                "peer record with as%s and ixlan id %s exists", self.asn, self.ixlan_id
            )
github respawner / peering-manager / peeringdb / admin.py View on Github external
from django.contrib import admin
from .models import Network, NetworkIXLAN, PeerRecord, Prefix, Synchronization

admin.site.register(Network)
admin.site.register(NetworkIXLAN)
admin.site.register(PeerRecord)
admin.site.register(Prefix)
admin.site.register(Synchronization)
github respawner / peering-manager / peering / models.py View on Github external
def exists_in_peeringdb(self):
        """
        Returns True if a PeerRecord exists for this session's IP.
        """
        lookup = {
            "network_ixlan__ipaddr{}".format(self.ip_address.version): str(
                self.ip_address
            )
        }
        try:
            PeerRecord.objects.get(**lookup)
            return True
        except PeerRecord.DoesNotExist:
            pass
        return False