from django.db import models from django.db.models import Q # Create your models here. MODE_CHOICES = ( ('master', 'master'), ('managed','managed'), ) PORT_CHOICES = ( ('vr0','vr0'), ('vr1','vr1'), ('vr2','vr2'), ('ue0','ue0'), ('ue1','ue1'), ('sis0','sis0'), ('sis1','sis1'), ) MODEL_CHOICES = ( ('Ethernet', 'Ethernet'), ('Bullet2', 'NanoStation2'), ('NanoStation2', 'NanoStation2'), ('NanoStationM2', 'NanoStationM2'), ('NanoStation5', 'NanoStation5'), ('NanoStationM5', 'NanoStationM5'), ) NETMASK_CHOICES = zip(range(12,31),range(12,31)) class IPBlock(models.Model): network = models.IPAddressField(default="172.16.",unique=True) netmask = models.IntegerField(choices=NETMASK_CHOICES,default=29) def __unicode__(self): return "%s/%s" % (self.network, self.netmask) DEFAULT_IPBLOCK = lambda: IPBlock.objects.get_or_create(network='0.0.0.0',netmask=0)[0].id class Node(models.Model): name = models.CharField(max_length="100") def __unicode__(self): return self.name class Interface(models.Model): node = models.ForeignKey(Node) port = models.CharField(max_length="100", choices=PORT_CHOICES, default="vr0") model = models.CharField(max_length="100", choices=MODEL_CHOICES, default="Ethernet") mode = models.CharField(max_length="100", choices=MODE_CHOICES, default="master") def __unicode__(self): return "%s - %s - %s - %s" % (self.node, self.port, self.model, self.mode) class Link(models.Model): ip_block = models.ForeignKey(IPBlock,unique=True,default=DEFAULT_IPBLOCK) interfaces = models.ManyToManyField(Interface) def __unicode__(self): return "%s : %s" % (self.ip_block, '|'.join(map(str,self.interfaces.all())))