diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-02-07 13:04:40 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-02-07 13:04:40 -0500 |
commit | c0e2f8d39e2581335390561e7d8a4d8deefd7e56 (patch) | |
tree | dfdebfff4c6ce7bad99d422acf83f3cd83cf2064 /cloudinit/util.py | |
parent | 8ba08be9c27852aa2a40f1c6fbd497d95443eb3e (diff) | |
download | vyos-cloud-init-c0e2f8d39e2581335390561e7d8a4d8deefd7e56.tar.gz vyos-cloud-init-c0e2f8d39e2581335390561e7d8a4d8deefd7e56.zip |
add utility function get_cfg_by_path
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index d6b1860b..40925b94 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -82,6 +82,15 @@ def get_cfg_option_list_or_str(yobj, key, default=None): if isinstance(yobj[key],list): return yobj[key] return([yobj[key]]) +# get a cfg entry by its path array +# for f['a']['b']: get_cfg_by_path(mycfg,('a','b')) +def get_cfg_by_path(yobj,keyp,default=None): + cur = yobj + for tok in keyp: + if tok not in cur: return(default) + cur = cur[tok] + return(cur) + # merge values from src into cand. # if src has a key, cand will not override def mergedict(src,cand): |