Skip to content
Snippets Groups Projects
Select Git revision
  • ce47f00e1ec46b801b231adee116eee63bb87c0d
  • python3 default protected
  • feature/exabgp_support2
  • feature/exabgp_support2.bgpextcommunity
  • feature/exabgp_support2.django4.2
  • fix/existingcheck_honor_fragtype
  • feature/python3-authz_netmask
  • feature/authz_netmask
  • fix/wrong_ratelimit_stats
  • feature/requirements_version_update2024-01
  • feature/split_celery
  • feature/improved-warning-mails
  • fix/reenable_expireset_via_restapi
  • feature/admin_user_delete_with_owned_rule_reassigning1
  • feature/admin_user_delete_with_owned_rule_reassigning
  • feature/branded_doc
  • fix/forked_snmp_polling_worker_exit_issue
  • fix/false_user_activation_error
  • feature/exabgp_with_docker-compose
  • fix/prefix_overlap_handling
  • fix/js_security_issues-a
  • save1
  • rpm-1.5-7
  • working1
  • myv1.6
  • t12b1
  • v1.5_newnew2
  • merged_final
  • v1.5_newnew
  • startstop_old
  • myadd2
  • tomas3
  • merge_jra2t6_and_RESTAPI
  • mytomas2
  • mynew1
  • new_jra2t6
  • v1.5_final
  • fod16_ruleroutes-merged_old
  • merged_new
  • v1.6_new_old
  • v1.5_new_old_follower
41 results

models.py

Blame
  • models.py 2.89 KiB
    # -*- coding: utf-8 -*- vim:fileencoding=utf-8:
    # vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
    
    # Copyright (C) 2010-2014 GRNET S.A.
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    
    from django.contrib.auth.models import User
    from django.db import models
    from utils.whois import *
    from django.conf import settings
    
    
    class PeerRange(models.Model):
        network = models.CharField(max_length=128)
    
        def __unicode__(self):
            return self.network
        def __str__(self):
            return self.__unicode__()
    
        class Meta:
            db_table = u'peer_range'
            ordering = ['network']
            managed = settings.PEER_RANGE_MANAGED_TABLE
    
    
    class TechcEmail(models.Model):
        email = models.CharField(max_length=352, db_column="email")
    
        def __unicode__(self):
            return self.email
        def __str__(self):
            return self.__unicode__()
    
        class Meta:
            db_table = "techc_email"
            managed = settings.PEER_TECHC_MANAGED_TABLE
    
    
    class Peer(models.Model):
        peer_id = models.AutoField(primary_key=True)
        peer_name = models.CharField(max_length=128)
        peer_as = models.IntegerField(null=True, blank=True)
        # This needs to be converted to slug and an info message needs to be added.
        peer_tag = models.CharField(max_length=64)
        domain_name = models.CharField(max_length=128, null=True, blank=True)
        networks = models.ManyToManyField(PeerRange, blank=True)
        techc_emails = models.ManyToManyField(TechcEmail, blank=True)
    
        def __unicode__(self):
            return self.peer_name
        def __str__(self):
            return self.__unicode__()
    
        class Meta:
            db_table = u'peer'
            ordering = ['peer_name']
            managed = settings.PEER_MANAGED_TABLE
    
        def fill_networks(self):
            network_range = []
            networks_list = []
            peer_as = "AS%s" % self.peer_as
            network_range = whois(peer_as)
            if network_range:
                for network_item in network_range:
                    range, created = PeerRange.objects.get_or_create(network=network_item.compressed)
                    networks_list.append(range)
                self.networks = networks_list
                self.save()
    
    
    class PeerNotify(models.Model):
        peer = models.ForeignKey(Peer, on_delete=models.CASCADE)
        user = models.ForeignKey(User, on_delete=models.CASCADE)
        peer_activation_notified = models.BooleanField(default=True)