rax-dns-backup: fix parsing
It looks like at some point the RAX bind output changed format slightly, which messed up our backup script. Rework it to parse the current output. This parsing is obviously a little fragile ... it is nice to have the output sorted and lined up nicely (like our manually maintained opendev.org bind files...). If the format changes again and this becomes a problem, maybe we switch to dumping the RAX output directly and forget about formatting it nicely. Change-Id: I742dd6ef9ffdb377274b384b847625c98dd5ff16
This commit is contained in:
parent
95c9cf6ec6
commit
7146cdebaf
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user