From 1667516626339f4a7ea91b68696a67c0ea8b7b92 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 12 Aug 2010 12:00:23 -0400 Subject: 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. --- cloudinit/util.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3