summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-08-12 12:00:23 -0400
committerScott Moser <smoser@ubuntu.com>2010-08-12 12:00:23 -0400
commit1667516626339f4a7ea91b68696a67c0ea8b7b92 (patch)
treef5471acd72fd85b6c55e7e805679a6a9ec48ec45 /cloudinit
parent2d23c3a8f3d5111f5e940a9ab1435852ad2820f4 (diff)
downloadvyos-cloud-init-1667516626339f4a7ea91b68696a67c0ea8b7b92.tar.gz
vyos-cloud-init-1667516626339f4a7ea91b68696a67c0ea8b7b92.zip
util: add read_optional_seed function
read_optional_seed should return true or false based on whether or not the seed existed. It is useful to easily say read this if its there, but it might not be.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/util.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 137921ed..59eb2b9f 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -121,8 +121,24 @@ def render_to_file(template, outfile, searchList):
f.write(t.respond())
f.close()
+# read_optional_seed
+# returns boolean indicating success or failure (presense of files)
+# if files are present, populates 'fill' dictionary with 'user-data' and
+# 'meta-data' entries
+def read_optional_seed(fill,base="",ext="", timeout=2):
+ try:
+ (md,ud) = read_seeded(base,ext,timeout)
+ fill['user-data']= ud
+ fill['meta-data']= md
+ return True
+ except OSError, e:
+ if e.errno == errno.ENOENT:
+ return False
+ raise
+
+
# raise OSError with enoent if not found
-def read_seeded(base="", ext=".raw", timeout=2):
+def read_seeded(base="", ext="", timeout=2):
if base.startswith("/"):
base="file://%s" % base