Skip to content

Commit

Permalink
added zone type and more dns info in dump - mainly for documentation …
Browse files Browse the repository at this point in the history
…reasons
  • Loading branch information
mahtin committed Jun 23, 2020
1 parent b74a781 commit 4262a2b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions examples/example_zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,41 @@ def main():
for zone in sorted(zones, key=lambda v: v['name']):
zone_name = zone['name']
zone_id = zone['id']
zone_type = zone['type']
if 'email' in zone['owner']:
zone_owner = zone['owner']['email']
else:
zone_owner = '"' + zone['owner']['name'] + '"'
zone_plan = zone['plan']['name']

print('%s %-35s %-30s %-20s %s' % (zone_id, zone_name, zone_type, zone_owner, zone_plan))

try:
dns_records = cf.zones.dns_records.get(zone_id)
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('/zones/dns_records %d %s - api call failed' % (e, e))

print(zone_id, zone_name, zone_owner, zone_plan)
sys.stderr.write('/zones/dns_records %d %s - api call failed\n' % (e, e))
continue

prog = re.compile('\.*'+zone_name+'$')
dns_records = sorted(dns_records, key=lambda v: prog.sub('', v['name']) + '_' + v['type'])
for dns_record in dns_records:
r_name = dns_record['name']
r_type = dns_record['type']
r_value = dns_record['content']
r_ttl = dns_record['ttl']
r_id = dns_record['id']
print('\t%s %60s %6d %-5s %s' % (r_id, r_name, r_ttl, r_type, r_value))
r_name = dns_record['name']
r_type = dns_record['type']
if 'content' in dns_record:
r_value = dns_record['content']
else:
# should not happen
r_value = ''
if 'priority' in dns_record:
r_priority = dns_record['priority']
else:
r_priority = ''
r_ttl = dns_record['ttl']
if zone_type == 'secondary':
r_id = 'secondary'
else:
r_id = dns_record['id']
print('\t%s %60s %6d %-5s %4s %s' % (r_id, r_name, r_ttl, r_type, r_priority, r_value))

print('')

Expand Down

0 comments on commit 4262a2b

Please sign in to comment.