コード例 #1
0
ファイル: models.py プロジェクト: petterreinholdtsen/mreg
 def zf_string(self, zone, subzone=None):
     """String representation for zonefile export."""
     if subzone:
         subzone = idna_encode(qualify(subzone, zone))
     data = {
         'subzone': clear_none(subzone),
         'ttl': clear_none(self.ttl),
         'record_type': 'NS',
         'record_data': idna_encode(qualify(self.name, zone))
     }
     return '{subzone:24} {ttl:5} IN {record_type:6} {record_data}\n'.format_map(
         data)
コード例 #2
0
ファイル: zonefile.py プロジェクト: tanzr/mreg
    def host_data(self, host):
        data = ""
        first = True
        name_idna = idna_encode(qualify(host.name, self.zone.name))
        ttl = clear_none(host.ttl)
        for values, func in (
            (self.ipaddresses, self.ip_zf_string),
            (self.mxs, self.mx_zf_string),
            (self.txts, self.txt_zf_string),
            (self.naptrs, self.naptr_zf_string),
        ):
            if host.name in values:
                for i in values[host.name]:
                    if first:
                        first = False
                        name = name_idna
                    else:
                        name = ""
                    data += func(name, ttl, *i)

        # XXX: add caching for this one, if we populate it..
        if host.hinfo is not None:
            data += host.hinfo.zf_string
        if host.loc:
            data += host.loc_string(self.zone.name)
        # For entries where the host is the resource record
        if host.name in self.host_cnames:
            for alias, ttl in self.host_cnames[host.name]:
                data += self.cname_zf_string(alias, ttl, name_idna)
        return data
コード例 #3
0
 def get_glue(self, ns):
     """Returns glue for a nameserver. If already used return blank"""
     if ns in self.glue_done:
         return ""
     else:
         self.glue_done.add(ns)
     if not ns.endswith("." + self.zone.name):
         return ""
     try:
         host = Host.objects.get(name=ns)
     except Host.DoesNotExist:
         #XXX: signal hostmaster?
         return f"OPS: missing glue for {ns}\n"
     if not host.ipaddresses.exists():
         #XXX: signal hostmaster?
         return f"OPS: no ipaddress for name server {ns}\n"
     # self's name servers do not need glue, as they will come later
     # in the zonefile.
     if host.zone == self.zone:
         return ""
     data = ""
     name_idna = idna_encode(qualify(host.name, self.zone.name))
     ttl = clear_none(host.ttl)
     for ip in host.ipaddresses.all():
         data += self.ip_zf_string(name_idna, ttl, ipaddress.ip_address(ip.ipaddress))
     return data
コード例 #4
0
 def cname_zf_string(self, alias, ttl, target):
     """String representation for zonefile export."""
     data = {
         'alias': idna_encode(qualify(alias, self.zone.name)),
         'ttl': clear_none(ttl),
         'record_type': 'CNAME',
         'record_data': target,
     }
     return '{alias:24} {ttl:5} IN {record_type:6} {record_data:39}\n'.format_map(data)
コード例 #5
0
ファイル: models.py プロジェクト: petterreinholdtsen/mreg
 def zf_string(self, zone):
     """String representation for zonefile export."""
     data = {
         'name': idna_encode(qualify(self.name, zone)),
         'ttl': clear_none(self.ttl),
         'record_type': 'SRV',
         'priority': self.priority,
         'weight': self.weight,
         'port': self.port,
         'target': idna_encode(qualify(self.target, zone))
     }
     return '{name:24} {ttl:5} IN {record_type:6} {priority} {weight} {port} {target}\n'.format_map(
         data)