Commits

George Notaras  committed 35784f5

Added SOA and RR models. Not all fields have been implemented yet.

  • Participants
  • Parent commits 32754ef

Comments (0)

Files changed (1)

File src/mydns_manager/models.py

 from django.db import models
 from django.db.models import signals
 from django.utils.translation import ugettext_lazy as _
+
+from mydns_manager import settings
+
+
+class SOA(models.Model):
+    """Model for MyDNS Start Of Authority records (SOA).
+    
+    Table schema:
+    
+        http://www.mydns.pl/docs/html/soa-table.html#soa-table
+    
+    """
+    origin = models.CharField(max_length=255, unique=True, verbose_name=_('origin'), help_text="""The name of this zone.""")
+    ns = models.CharField(max_length=255, verbose_name=_('primary nameserver'), help_text="""The name of the name server that was the original or primary source of data for this zone.""")
+    mbox = models.CharField(max_length=255, verbose_name=_('hostmaster mailbox'), help_text="""A name which specifies the mailbox of the person responsible for this zone. This should be specified in the mailbox-as-domain-name format where the `@' character is replaced with a dot.""")
+    serial = models.PositiveIntegerField(default=1, verbose_name=_('serial'), help_text="""A "version number" for this zone. DNS servers that rely on AXFR for zone transfers use this to determine when updates have occurred. Popular values to use are the Unix timestamp or a date in the form YYYYMMDD.""")
+
+    refresh = models.PositiveIntegerField(default=28800, verbose_name=_('refresh'), help_text="""The number of seconds after which slave nameservers should check to see if this zone has been changed. If the zone's serial number has changed, the slave nameserver initiates a zone transfer.""")
+    retry = models.PositiveIntegerField(default=7200, verbose_name=_('retry'), help_text="""This specifies the number of seconds a slave nameserver should wait before retrying if it attmepts to transfer this zone but fails.""")
+    expire = models.PositiveIntegerField(default=604800, verbose_name=_('expire'), help_text="""If for expire seconds the primary server cannot be reached, all information about the zone is invalidated on the secondary servers (i.e., they are no longer authoritative for that zone).""")
+    minimum = models.PositiveIntegerField(default=86400, verbose_name=_('minimum TTL'), help_text="""The minimum TTL field that should be exported with any RR from this zone. If any RR in the database has a lower TTL, this TTL is sent instead.""")
+    ttl = models.PositiveIntegerField(default=settings.MYDNS_DEFAULT_SOA_TTL, verbose_name=_('TTL'), help_text="""The number of seconds that this zone may be cached before the source of the information should again be consulted. Zero values are interpreted to mean that the zone should not be cached.""")
+
+    ACTIVE_CHOICES = (
+        ('Y', 'Yes'),
+        ('N', 'No'),
+    )
+    active = models.CharField(max_length=1, choices=ACTIVE_CHOICES, default='Y', verbose_name=_('active'), help_text="""Mark the zone as active or inactive.""")
+    
+    # MyDNS Manager internal fields
+    date_created = models.DateTimeField(auto_now_add=True, verbose_name=_('Created on'))
+    date_modified = models.DateTimeField(auto_now=True, verbose_name=_('Last Modified'))
+    created_by = models.ForeignKey('auth.User', related_name='%(app_label)s_%(class)s_created_by', null=True, verbose_name=_('created by'), help_text="""The Django user this zone belongs to.""")
+    
+    class Meta:
+        verbose_name = _('SOA Record')
+        verbose_name_plural = _('SOA Records')
+        get_latest_by = 'date_modified'
+        ordering = ['origin']
+
+    def __unicode__(self):
+        return self.origin
+
+#origin convert to lowercase
+# serial should be set on every save. use timestamp as serial. time.time()
+
+# Considerations:
+# db_index=True  to  origin,
+
+
+
+class RR(models.Model):
+    """Model for MyDNS resource record.
+    
+    Table schema:
+    
+        http://www.mydns.pl/docs/html/rr-table.html#rr-table
+    
+    Supported record types:
+    
+        http://www.mydns.pl/docs/html/Supported-RR-types.html#Supported-RR-types
+    
+    """
+    RECORD_TYPE_CHOICES = (
+        ('A', 'A'),
+        ('AAAA', 'AAAA'),
+        ('ALIAS', 'ALIAS'),
+        ('CNAME', 'CNAME'),
+        ('HINFO', 'HINFO'),
+        ('MX', 'MX'),
+        ('NAPTR', 'NAPTR'),
+        ('NS', 'NS'),
+        ('PTR', 'PTR'),
+        ('RP', 'RP'),
+        ('SRV', 'SRV'),
+        ('TXT', 'TXT'),
+    )
+    zone = models.ForeignKey('mydns_manager.SOA', related_name='%(app_label)s_%(class)s_zone', db_column='zone', verbose_name=_('zone'), help_text=_("""Select the zone this record belongs to."""))
+    name = models.CharField(max_length=64, verbose_name=_('name'), help_text="""The name that this RR describes. Wildcard values such as `*' or `*.sub' are supported, and this field can contain a FQDN or just a hostname. It may contain out-of-zone data if this is a glue record. Examples: foo | foo.example.com.""")
+    type = models.CharField(max_length=10, choices=RECORD_TYPE_CHOICES, verbose_name=_('type'), help_text="""Select the type of the resource record.""")
+    data = models.CharField(max_length=255, verbose_name=_('data'), help_text="""The data associated with this resource record.""")
+    aux = models.PositiveIntegerField(default=0, verbose_name=_('priority'), help_text="""An auxillary numeric value in addition to data. For `MX' records, this field specifies the preference. For `SRV' records, this field specifies the priority.""")
+    ttl = models.PositiveIntegerField(default=settings.MYDNS_DEFAULT_RR_TTL, verbose_name=_('TTL'), help_text="""The time interval that this resource record may be cached before the source of the information should again be consulted. Zero values are interpreted to mean that the RR can only be used for the transaction in progress, and should not be cached. """)
+    
+    ACTIVE_CHOICES = (
+        ('Y', 'Yes'),
+        ('N', 'No'),
+    )
+    active = models.CharField(max_length=1, choices=ACTIVE_CHOICES, default='Y', verbose_name=_('active'), help_text="""Mark the resource record as active or inactive.""")
+
+    # For IXFR
+    #stamp = models.DateTimeField(auto_now=True, verbose_name=_('Last Modified'), help_text="""Utilised in IXFR processing.""")
+    #serial = models.PositiveIntegerField(blank=True, null=True, verbose_name=_('serial'), help_text="""contain the serial number of the zone when the record was created. Utilised in IXFR processing.""")
+
+    # MyDNS Manager internal fields
+    date_created = models.DateTimeField(auto_now_add=True, verbose_name=_('Created on'))
+    date_modified = models.DateTimeField(auto_now=True, verbose_name=_('Last Modified'))
+
+    class Meta:
+        verbose_name = _('resource record')
+        verbose_name_plural = _('resource records')
+        get_latest_by = 'date_modified'
+        ordering = ['type']
+        order_with_respect_to = 'zone'
+    
+    def __unicode__(self):
+        return self.name
+
+#name convert to lowercase
+# change_date This should be set on every save  manually
+# should be set automatically on every save
+# No more than one SOA for a domain
+
+# Add note about trailing dot
+
+# Considerations:
+# db_index=True  to  name, type
+