Merge "rax-dns-backup: fix parsing"

This commit is contained in:
Zuul 2022-11-21 20:46:58 +00:00 committed by Gerrit Code Review
commit 37ff268a74

View File

@ -124,16 +124,20 @@ def do_bind_export(session, token, domain_id, outfile):
query = {'showDetails': 'true'}
final_response = session.get(callback_url, params=query, headers=headers)
bind_output = final_response.json()['response']['contents']
bind_output = final_response.json()['response']['contents'].split('\n')
output = []
for line in bind_output.split('\n'):
# Read and parse the record lines for sorting; the skip is because
# the first 3 lines are comments and the rest are SOA records
# (written separately below).
for line in bind_output[10:]:
if line == '':
continue
fields = line.split(' ')
output.append(fields)
# find padding space for the first column
# find padding space for the first column so everything lines up nice
max_first = max([len(x[0]) for x in output])
# create a dict keyed by domain with each record
@ -143,10 +147,10 @@ def do_bind_export(session, token, domain_id, outfile):
outstr = ''
# first output SOA then get rid of it
outstr += ("%-*s\t%s\n\n" %
(max_first+1, '@', '\t'.join(out_dict['@'][0]) ))
del(out_dict['@'])
# first output comments and SOA from original
for line in bind_output[:10]:
outstr += "%s\n" % line
outstr += '\n'
# print out the rest of the entries, with individual records
# sorted and grouped