summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2012-10-23 18:58:32 +0200
committerScott Moser <smoser@brickies.net>2012-10-23 18:58:32 +0200
commit71b4108d029fff61ff8183ffbd77917569bea2cd (patch)
tree6564cd3f5faa26fb1c843b14d27ca6eaa23164f0 /cloudinit/util.py
parentcb5893c3e3f635de4fef86f0a19be0ada0054930 (diff)
parente8a10a41d22876d555084def823817337d9c2a80 (diff)
downloadvyos-cloud-init-71b4108d029fff61ff8183ffbd77917569bea2cd.tar.gz
vyos-cloud-init-71b4108d029fff61ff8183ffbd77917569bea2cd.zip
use only util methods for reading/loading/appending/peeking
Use only util methods for reading/loading/appending/peeking at files since it is likely soon that we will add a new way of adjusting the root of files read, also it is useful for debugging to track what is being read/written in a central fashion.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index f5a7ac12..7890a3d6 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -983,6 +983,12 @@ def find_devs_with(criteria=None, oformat='device',
return entries
+def peek_file(fname, max_bytes):
+ LOG.debug("Peeking at %s (max_bytes=%s)", fname, max_bytes)
+ with open(fname, 'rb') as ifh:
+ return ifh.read(max_bytes)
+
+
def load_file(fname, read_cb=None, quiet=False):
LOG.debug("Reading from %s (quiet=%s)", fname, quiet)
ofh = StringIO()
@@ -1328,6 +1334,10 @@ def uptime():
return uptime_str
+def append_file(path, content):
+ write_file(path, content, omode="ab", mode=None)
+
+
def ensure_file(path, mode=0644):
write_file(path, content='', omode="ab", mode=mode)