def _create_rdataset(rtype, ttl, values): rdataset = dns.rdataset.Rdataset(dns.rdataclass.IN, dns.rdatatype.from_text(rtype)) rdataset.ttl = ttl for value in values: rdtype = None if rtype == 'A': rdtype = dns.rdtypes.IN.A.A(dns.rdataclass.IN, dns.rdatatype.A, value) elif rtype == 'AAAA': rdtype = dns.rdtypes.IN.AAAA.AAAA(dns.rdataclass.IN, dns.rdatatype.AAAA, value) elif rtype == 'CNAME': rdtype = CNAME(dns.rdataclass.ANY, dns.rdatatype.CNAME, value.rstrip('.') + '.') elif rtype == 'SOA': mname, rname, serial, refresh, retry, expire, minimum = value.split( ) mname = dns.name.from_text(mname) rname = dns.name.from_text(rname) serial = int(serial) refresh = int(refresh) retry = int(retry) expire = int(expire) minimum = int(minimum) rdtype = dns.rdtypes.ANY.SOA.SOA(dns.rdataclass.ANY, dns.rdatatype.SOA, mname, rname, serial, refresh, retry, expire, minimum) elif rtype == 'NS': rdtype = NS(dns.rdataclass.ANY, dns.rdatatype.NS, value) elif rtype == 'MX': try: pref, ex = value.split() pref = int(pref) except ValueError: raise ValueError, 'mx records required two parts: priority name' rdtype = MX(dns.rdataclass.ANY, dns.rdatatype.MX, pref, ex) elif rtype == 'PTR': rdtype = PTR(dns.rdataclass.ANY, dns.rdatatype.PTR, value) elif rtype == 'SPF': rdtype = SPF(dns.rdataclass.ANY, dns.rdatatype.SPF, value) elif rtype == 'SRV': rdtype = SRV(dns.rdataclass.IN, dns.rdatatype.SRV, value) elif rtype == 'TXT': if re_quoted.match(value): value = unquote(value) rdtype = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.ANY, dns.rdatatype.TXT, [value]) else: raise ValueError, 'record type %s not handled' % rtype rdataset.items.append(rdtype) return rdataset
def _create_rdataset(rtype, ttl, values, weight, identifier, region): rdataset = dns.rdataset.Rdataset(dns.rdataclass.IN, dns.rdatatype.from_text(rtype)) rdataset.ttl = ttl for value in values: rdtype = None if rtype == 'A': if identifier is None: rdtype = dns.rdtypes.IN.A.A(dns.rdataclass.IN, dns.rdatatype.A, value) else: rdataset.rdclass = AWS.RDCLASS if weight is not None: rdtype = AWS.A(AWS.RDCLASS, dns.rdatatype.A, value, weight, identifier, None) elif region is not None: rdtype = AWS.A(AWS.RDCLASS, dns.rdatatype.A, value, None, identifier, region) elif rtype == 'AAAA': rdtype = AAAA(dns.rdataclass.IN, dns.rdatatype.AAAA, value) elif rtype == 'CNAME': if identifier is None: rdtype = CNAME(dns.rdataclass.ANY, dns.rdatatype.CNAME, value) else: rdataset.rdclass = AWS.RDCLASS rdtype = AWS.CNAME(AWS.RDCLASS, dns.rdatatype.CNAME, value, weight, identifier, region) elif rtype == 'SOA': mname, rname, serial, refresh, retry, expire, minimum = value.split( ) mname = dns.name.from_text(mname) rname = dns.name.from_text(rname) serial = int(serial) refresh = int(refresh) retry = int(retry) expire = int(expire) minimum = int(minimum) rdtype = dns.rdtypes.ANY.SOA.SOA(dns.rdataclass.ANY, dns.rdatatype.SOA, mname, rname, serial, refresh, retry, expire, minimum) elif rtype == 'NS': rdtype = NS(dns.rdataclass.ANY, dns.rdatatype.NS, value) elif rtype == 'MX': try: pref, ex = value.split() pref = int(pref) except ValueError: raise ValueError('mx records require two parts: priority name') rdtype = MX(dns.rdataclass.ANY, dns.rdatatype.MX, pref, ex) elif rtype == 'PTR': rdtype = PTR(dns.rdataclass.ANY, dns.rdatatype.PTR, value) elif rtype == 'SPF': rdtype = SPF(dns.rdataclass.ANY, dns.rdatatype.SPF, value) elif rtype == 'SRV': rdtype = SRV(dns.rdataclass.IN, dns.rdatatype.SRV, value) elif rtype == 'TXT': values = unquote_list(value) rdtype = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.ANY, dns.rdatatype.TXT, values) elif rtype == 'ALIAS': rdataset.rdclass = AWS.RDCLASS try: hosted_zone_id, dns_name = value.split() except ValueError: raise ValueError( 'ALIAS records require two parts: hosted zone id and dns name of ELB' ) if identifier is None: rdtype = AWS.ALIAS(AWS.RDCLASS, AWS.RDTYPE_ALIAS, hosted_zone_id, dns_name, None, identifier, None) else: if weight is not None: rdtype = AWS.ALIAS(AWS.RDCLASS, AWS.RDTYPE_ALIAS, hosted_zone_id, dns_name, weight, identifier, None) elif region is not None: rdtype = AWS.ALIAS(AWS.RDCLASS, AWS.RDTYPE_ALIAS, hosted_zone_id, dns_name, None, identifier, region) else: raise ValueError('record type %s not handled' % rtype) rdataset.items.append(rdtype) return rdataset