1. George Notaras
  2. django-powerdns-manager


George Notaras  committed ee4f662

Support for setting the TTL automatically on RRs (SOA is excluded).

It is now possible to leave RR's TTL blank in the ModelAdmin (not for SOA RRs) and the default TTL is set, as defined by the SOA record or the PDNS_DEFAULT_RR_TTL (if SOA is missing).

  • Participants
  • Parent commits 5a2740b
  • Branches default

Comments (0)

Files changed (2)

File src/powerdns_manager/models.py

View file
     # See section 8.5 about why the type field allows NULL. (PowerDNS 3.2 and above)
     type = models.CharField(max_length=10, null=True, db_index=True, choices=RECORD_TYPE_CHOICES, verbose_name=_('type'), help_text="""Select the type of the resource record.""")
     content = models.CharField(max_length=255, null=True, verbose_name=_('content'), help_text="""This is the 'right hand side' of a DNS record. For an A record, this is the IP address for example.""")
-    ttl = models.PositiveIntegerField(max_length=11, null=True, default=settings.PDNS_DEFAULT_RR_TTL, verbose_name=_('TTL'), help_text="""How long the DNS-client are allowed to remember this record. Also known as Time To Live(TTL) This value is in seconds.""")
+    ttl = models.PositiveIntegerField(max_length=11, blank=True, null=True, verbose_name=_('TTL'), help_text="""How long the DNS-client are allowed to remember this record. Also known as Time To Live(TTL) This value is in seconds.""")
     prio = models.PositiveIntegerField(max_length=11, null=True, verbose_name=_('priority'), help_text="""For MX records, this should be the priority of the mail exchanger specified.""")
     # Extra fields for DNSSEC (http://doc.powerdns.com/dnssec-modes.html#dnssec-direct-database)
     auth = models.NullBooleanField(verbose_name=_('authoritative'), help_text="""The 'auth' field should be set to '1' for data for which the zone itself is authoritative, which includes the SOA record and its own NS records. The 'auth' field should be 0 however for NS records which are used for delegation, and also for any glue (A, AAAA) records present for this purpose. Do note that the DS record for a secure delegation should be authoritative!""")
 signals.pre_save.connect(signal_cb.set_soa_rr_name, sender=Record)
 # Update ``change_date``
 signals.pre_save.connect(signal_cb.update_rr_change_date, sender=Record)
-# Set missing TTL information
-signals.pre_save.connect(signal_cb.set_missing_rr_ttl, sender=Record)
+# Set TTL information for the record
+signals.pre_save.connect(signal_cb.set_rr_ttl, sender=Record)
 # Set ``auth`` field
 signals.pre_save.connect(signal_cb.set_rr_authoritative, sender=Record)
 # Set ``ordername`` field

File src/powerdns_manager/signal_cb.py

View file
     instance.change_date = int(time.time())
-def set_missing_rr_ttl(sender, **kwargs):
+def set_rr_ttl(sender, **kwargs):
+    """Sets the TTL of the resource record(s).
+    This is done according to the following rules:
+    1) TTL of SOA RRs is not modified. The TTL field is mandatory on SOA
+    records (see forms.SoaRecordModelForm) and also defines the minimum TTL
+    get_minimum_ttl() retrieves.
+    2) If the RR is not a SOA and if TTL is missing, the minimum TTL of
+    the zone (as defined in the SOA record) will be used. If a SOA record
+    is missing, PDNS_DEFAULT_RR_TTL is returned by Domain.get.minimum_ttl().
+    """
     instance = kwargs['instance']   # powerdns_manager.Record instance
-    instance.ttl = settings.PDNS_DEFAULT_RR_TTL
-    # TODO: consider checking the minimum TTL from the SOA record.
+    if not instance.ttl and instance.type != 'SOA':
+        instance.ttl = instance.domain.get_minimum_ttl()
 def set_rr_authoritative(sender, **kwargs):