diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-20 06:41:01 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-20 06:41:01 -0500 |
commit | fe3ece415c5c6d815bd0a88f86a92627e9baae6a (patch) | |
tree | 6847560dca66fb75e72a3fc1247f4369bcfc1e01 /cloudinit | |
parent | 2c3a585d334fd03d10490e61abf814cec131c83c (diff) | |
download | vyos-cloud-init-fe3ece415c5c6d815bd0a88f86a92627e9baae6a.tar.gz vyos-cloud-init-fe3ece415c5c6d815bd0a88f86a92627e9baae6a.zip |
add caching of parsed configs to util.get_base_cfg
add caching of the parsed config, this will allow re-use in cloudinit
so that we don't have to load the default config more than once in
a program.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/util.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index a2291164..f8c847aa 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -42,9 +42,12 @@ def read_conf(fname): return { } raise -def get_base_cfg(cfgfile,cfg_builtin=""): +def get_base_cfg(cfgfile,cfg_builtin="", parsed_cfgs=None): kerncfg = { } syscfg = { } + if parsed_cfgs and cfgfile in parsed_cfgs: + return(parsed_cfgs[cfgfile]) + contents = read_file_with_includes(cfgfile) if contents: syscfg = yaml.load(contents) @@ -58,9 +61,13 @@ def get_base_cfg(cfgfile,cfg_builtin=""): if cfg_builtin: builtin = yaml.load(cfg_builtin) + fin = mergedict(combined,builtin) else: - return(combined) - return(mergedict(combined,builtin)) + fin = combined + + if parsed_cfgs != None: + parsed_cfgs[cfgfile] = fin + return(fin) def get_cfg_option_bool(yobj, key, default=False): if not yobj.has_key(key): return default |