summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-01-20 16:38:49 -0500
committerScott Moser <smoser@ubuntu.com>2010-01-20 16:38:49 -0500
commit8ac737948622d97f43877dbc1c78707eb82fb273 (patch)
tree7789203d91e632c7d5bd735c3792957e21c68f47
parent272bdb4ad359f2f7b8a809ec16b1e5df90695a66 (diff)
downloadvyos-cloud-init-8ac737948622d97f43877dbc1c78707eb82fb273.tar.gz
vyos-cloud-init-8ac737948622d97f43877dbc1c78707eb82fb273.zip
add util library
-rw-r--r--ec2init/util.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/ec2init/util.py b/ec2init/util.py
new file mode 100644
index 00000000..8b36274e
--- /dev/null
+++ b/ec2init/util.py
@@ -0,0 +1,29 @@
+import yaml
+
+def read_conf(fname):
+ stream = file(fname)
+ conf = yaml.load(stream)
+ stream.close()
+ return conf
+
+def get_cfg_option_bool(yobj, key, default=False):
+ if not yobj.has_key(key): return default
+ val = yobj[key]
+ if yobj[key] in [ True, '1', 'on', 'yes', 'true']:
+ return True
+ return False
+
+def get_cfg_option_str(yobj, key, default=None):
+ if not yobj.has_key(key): return default
+ return yobj[key]
+
+# merge values from src into cand.
+# if src has a key, cand will not override
+def mergedict(src,cand):
+ if isinstance(src,dict) and isinstance(cand,dict):
+ for k,v in cand.iteritems():
+ if k not in src:
+ src[k] = v
+ else:
+ src[k] = merge(src[k],v)
+ return src