summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-18 19:55:53 -0400
committerScott Moser <smoser@ubuntu.com>2016-03-18 19:55:53 -0400
commit5916180c5ecb2ef74c1c993dcd32f95cb4581172 (patch)
tree3b2d5ef649e5df0058013ed2ef0e3d3d8f100296
parent1dd9102afda920d486a144b3153d6c9951f45cf9 (diff)
downloadvyos-cloud-init-5916180c5ecb2ef74c1c993dcd32f95cb4581172.tar.gz
vyos-cloud-init-5916180c5ecb2ef74c1c993dcd32f95cb4581172.zip
add atomic_write_file and use it from atomic_write_json
atomic_write_file just does less and easily utilized for the same purpose that atomic_write_json served.
-rwxr-xr-xbin/cloud-init12
1 files changed, 8 insertions, 4 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index 7f665e7e..42166580 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -435,20 +435,24 @@ def main_single(name, args):
return 0
-def atomic_write_json(path, data):
+def atomic_write_file(path, content, mode='w'):
tf = None
try:
tf = tempfile.NamedTemporaryFile(dir=os.path.dirname(path),
- delete=False)
- tf.write(util.encode_text(json.dumps(data, indent=1) + "\n"))
+ delete=False, mode=mode)
+ tf.write(content)u
tf.close()
os.rename(tf.name, path)
except Exception as e:
if tf is not None:
- util.del_file(tf.name)
+ os.unlink(tf.name)
raise e
+def atomic_write_json(path, data):
+ return atomic_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")