diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-08-12 12:00:23 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-08-12 12:00:23 -0400 |
commit | 1667516626339f4a7ea91b68696a67c0ea8b7b92 (patch) | |
tree | f5471acd72fd85b6c55e7e805679a6a9ec48ec45 | |
parent | 2d23c3a8f3d5111f5e940a9ab1435852ad2820f4 (diff) | |
download | vyos-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.
-rw-r--r-- | cloudinit/util.py | 18 |
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 |