Files @ 7b9708f0eeda
Branch filter:

Location: conntrackt/conntrackt/models.py

branko
Recreated the initial migration.
from django.db import models
from django.core.exceptions import ValidationError

# Create your models here.
class Project(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)

    def __unicode__(self):
        return self.name

class Location(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)

    def __unicode__(self):
        return self.name

class Entity(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)
    project = models.ForeignKey(Project)
    location = models.ForeignKey(Location)

    class Meta:
        verbose_name_plural = 'entities'

    def __unicode__(self):
        return "%s (%s - %s)" % (self.name, self.project, self.location)

class Interface(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)
    entity = models.ForeignKey(Entity)
    address = models.IPAddressField()
    netmask = models.IPAddressField(default='255.255.255.255')

    def __unicode__(self):
        return "%s (%s = %s/%s)" % (self.entity.name, self.name, self.address, self.netmask)

class Communication(models.Model):
    source = models.ForeignKey(Interface, related_name = 'source_set')
    destination = models.ForeignKey(Interface, related_name = 'destination_set')
    protocol = models.CharField(max_length = 10)
    port = models.IntegerField(default = 0)
    description = models.TextField(blank = True)

    def __unicode__(self):
        return "%s (%s/%s) -> %s (%s/%s)" % (self.source.entity.name, self.source.address, self.source.netmask,
                                             self.destination.entity.name, self.destination.address, self.destination.netmask)

    def clean(self):
        if self.source == self.destination:
            raise ValidationError('Source and destination must differ.')
        if self.protocol.lower() not in ('udp', 'tcp', 'icmp'):
            raise ValidationError('%s is not a supported protocol.' % self.protocol)