Exemple #1
0
    def __add_uri_records(self,
                          zone_obj,
                          hostname,
                          rname_uri_map,
                          weight=100,
                          priority=0,
                          location=None):
        assert isinstance(hostname, DNSName)
        assert isinstance(priority, int)
        assert isinstance(weight, int)

        if location:
            suffix = self.__get_location_suffix(location)
        else:
            suffix = self.domain_abs

        for name, uri_template in rname_uri_map:
            uri = uri_template.format(hostname=hostname.make_absolute())
            rd = rdata.from_text(rdataclass.IN, rdatatype.URI,
                                 '{0} {1} {2}'.format(priority, weight, uri))

            r_name = name.derelativize(suffix)

            rdataset = zone_obj.get_rdataset(r_name,
                                             rdatatype.URI,
                                             create=True)
            rdataset.add(rd, ttl=self.TTL)
    def __add_srv_records(
        self, zone_obj, hostname, rname_port_map,
        weight=100, priority=0, location=None
    ):
        assert isinstance(hostname, DNSName)
        assert isinstance(priority, int)
        assert isinstance(weight, int)

        if location:
            suffix = self.__get_location_suffix(location)
        else:
            suffix = self.domain_abs

        for name, port in rname_port_map:
            rd = rdata.from_text(
                rdataclass.IN, rdatatype.SRV,
                '{0} {1} {2} {3}'.format(
                    priority, weight, port, hostname.make_absolute()
                )
            )

            r_name = name.derelativize(suffix)

            rdataset = zone_obj.get_rdataset(
                r_name, rdatatype.SRV, create=True)
            rdataset.add(rd, ttl=86400)  # FIXME: use TTL from config
Exemple #3
0
 def __add_kerberos_txt_rec(self, zone_obj):
     # FIXME: with external DNS, this should generate records for all
     # realmdomains
     r_name = DNSName('_kerberos') + self.domain_abs
     rd = rdata.from_text(rdataclass.IN, rdatatype.TXT,
                          self.api_instance.env.realm)
     rdataset = zone_obj.get_rdataset(r_name, rdatatype.TXT, create=True)
     rdataset.add(rd, ttl=self.TTL)
 def __add_kerberos_txt_rec(self, zone_obj):
     # FIXME: with external DNS, this should generate records for all
     # realmdomains
     r_name = DNSName('_kerberos') + self.domain_abs
     rd = rdata.from_text(rdataclass.IN, rdatatype.TXT,
                          self.api_instance.env.realm)
     rdataset = zone_obj.get_rdataset(
         r_name, rdatatype.TXT, create=True
     )
     rdataset.add(rd, ttl=86400)  # FIXME: use TTL from config
Exemple #5
0
def add_srv_records(qname, port_map, priority=0, weight=100):
    rdlist = []
    for name, port in port_map:
        answerlist = []
        for host in qname:
            hostname = DNSName(host)
            rd = rdata.from_text(
                rdataclass.IN, rdatatype.SRV,
                '{0} {1} {2} {3}'.format(priority, weight, port,
                                         hostname.make_absolute()))
            answerlist.append(rd)
        rdlist.append(answerlist)
    return rdlist
Exemple #6
0
def WriteToZoneFile(zone_file, record_sets, domain):
    """Writes the given record-sets in zone file format to the given file.

  Args:
    zone_file: file, File into which the records should be written.
    record_sets: list, ResourceRecordSets to be written out.
    domain: str, The origin domain for the zone file.
  """
    zone_contents = zone.Zone(name.from_text(domain))
    for record_set in record_sets:
        rdset = zone_contents.get_rdataset(record_set.name,
                                           record_set.type,
                                           create=True)
        for rrdata in record_set.rrdatas:
            rdset.add(rdata.from_text(rdataclass.IN,
                                      rdatatype.from_text(record_set.type),
                                      str(rrdata),
                                      origin=zone_contents.origin),
                      ttl=record_set.ttl)
    zone_contents.to_file(zone_file, relativize=False)
def WriteToZoneFile(zone_file, record_sets, domain):
  """Writes the given record-sets in zone file format to the given file.

  Args:
    zone_file: file, File into which the records should be written.
    record_sets: list, ResourceRecordSets to be written out.
    domain: str, The origin domain for the zone file.
  """
  zone_contents = zone.Zone(name.from_text(domain))
  for record_set in record_sets:
    rdset = zone_contents.get_rdataset(record_set.name,
                                       record_set.type,
                                       create=True)
    for rrdata in record_set.rrdatas:
      rdset.add(rdata.from_text(rdataclass.IN,
                                rdatatype.from_text(record_set.type),
                                str(rrdata),
                                origin=zone_contents.origin),
                ttl=record_set.ttl)
  zone_contents.to_file(zone_file, relativize=False)