diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cloud-init | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/bin/cloud-init b/bin/cloud-init index 78f8600d..479d715d 100755 --- a/bin/cloud-init +++ b/bin/cloud-init @@ -419,6 +419,10 @@ def main_single(name, args): return 0 +def write_json(path, data): + util.write_file(path, json.dumps(data, indent=1) + "\n") + + def status_wrapper(name, args, data_d=None, link_d=None): if data_d is None: data_d = os.path.normpath("/var/lib/cloud/data") @@ -472,7 +476,7 @@ def status_wrapper(name, args, data_d=None, link_d=None): v1['stage'] = mode v1[mode]['start'] = time.time() - util.write_file(status_path, json.dumps(status)) + write_json(status, status_path) util.sym_link(os.path.relpath(status_path, link_d), status_link, force=True) @@ -481,11 +485,11 @@ def status_wrapper(name, args, data_d=None, link_d=None): if mode in ('init', 'init-local'): (datasource, errors) = ret if datasource is not None: - v1['datasource'] = datasource - v1[mode]['errors'] = errors + v1['datasource'] = str(datasource) else: errors = ret - v1[mode]['errors'] = ret + + v1[mode]['errors'] = [str(e) for e in errors] except Exception as e: v1[mode]['errors'] = [str(e)] @@ -493,7 +497,7 @@ def status_wrapper(name, args, data_d=None, link_d=None): v1[mode]['finished'] = time.time() v1['stage'] = None - util.write_file(status_path, json.dumps(status)) + write_json(status_path, status) if mode == "modules-final": # write the 'finished' file @@ -502,9 +506,8 @@ def status_wrapper(name, args, data_d=None, link_d=None): if v1[m]['errors']: errors.extend(v1[m].get('errors', [])) - finished = {'datasource': v1['datasource'], - 'errors': errors} - util.write_file(result_path, json.dumps(finished)) + write_json(result_path, + {'datasource': v1['datasource'], 'errors': errors}) util.sym_link(os.path.relpath(result_path, link_d), result_link, force=True) |