1 # -*- coding: utf-8 -*- vim:fileencoding=utf-8:
2 # vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
4 # Copyright (C) 2010-2014 GRNET S.A.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from django.db import models
21 from utils.whois import *
22 from django.contrib.auth.models import User
23 from django.conf import settings
25 class PeerRange(models.Model):
26 network = models.CharField(max_length=128)
27 def __unicode__(self):
30 db_table = u'peer_range'
31 ordering = ['network']
32 managed = settings.PEER_RANGE_MANAGED_TABLE
34 class TechcEmail(models.Model):
35 email = models.CharField(max_length=352, db_column="email")
36 def __unicode__(self):
39 db_table="techc_email"
40 managed = settings.PEER_TECHC_MANAGED_TABLE
42 class Peer(models.Model):
43 peer_id = models.AutoField(primary_key=True)
44 peer_name = models.CharField(max_length=128)
45 peer_as = models.IntegerField()
46 # This needs to be converted to slug and an info message needs to be added.
47 peer_tag = models.CharField(max_length=64)
48 domain_name = models.CharField(max_length=128, null=True, blank=True)
49 networks = models.ManyToManyField(PeerRange, null=True, blank=True)
50 techc_emails = models.ManyToManyField(TechcEmail, null=True, blank=True)
52 def __unicode__(self):
56 ordering = ['peer_name']
57 managed = settings.PEER_MANAGED_TABLE
60 def fill_networks(self):
63 peer_as = "AS%s" %self.peer_as
64 network_range = whois(peer_as)
66 for network_item in network_range:
67 range, created = PeerRange.objects.get_or_create(network=network_item.compressed)
68 networks_list.append(range)
69 self.networks = networks_list