Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | import dns.rdataset |
||
7 | class GetDnsZone(BaseAction): |
||
8 | def run(self, domain, record_type=None, name=None, nameserver=None, content=None, tags=None, |
||
9 | tags_and=None): |
||
10 | response = self.getAPI("/api/1.0/dns/records/", { |
||
11 | "domain": domain, |
||
12 | "type": record_type, |
||
13 | "name": name, |
||
14 | "nameserver": nameserver, |
||
15 | "content": content, |
||
16 | "tags": tags, |
||
17 | "tags_and": tags_and |
||
18 | }) |
||
19 | |||
20 | result = "" |
||
21 | if len(response["records"]) > 0: |
||
22 | zone = dns.zone.Zone(dns.name.from_text(response["records"][0]["dns_zone"])) |
||
23 | for record in response["records"]: |
||
24 | try: |
||
25 | rdtype = dns.rdatatype.from_text(record["type"]) |
||
26 | rdata = dns.rdata.from_text(dns.rdataclass.IN, rdtype, record["content"]) |
||
27 | n = zone.get_rdataset(record["name"], rdtype, create=True) |
||
28 | n.add(rdata, record["ttl"]) |
||
29 | except Exception, e: |
||
30 | print "Error: %s" % e.message |
||
31 | print "Record Name: %s" % record["name"] |
||
32 | print "Record Type: %s" % record["type"] |
||
33 | print "Record Content: %s" % record["content"] |
||
34 | print "Record TTL: %d" % record["ttl"] |
||
35 | print "---" |
||
36 | result = zone.to_text() |
||
37 | return result |
||
38 |