summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2013-03-06 19:24:05 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2013-03-06 19:24:05 -0800
commitfc6aa5aa54ee35ff0a3eff823bae0d3cf9b34bc1 (patch)
treebaf2534ea20b011e2b9d68ffdd5385ecba2dc31f /cloudinit/util.py
parent2653a9172e375484b4d0a88c3de56334136fa134 (diff)
downloadvyos-cloud-init-fc6aa5aa54ee35ff0a3eff823bae0d3cf9b34bc1.tar.gz
vyos-cloud-init-fc6aa5aa54ee35ff0a3eff823bae0d3cf9b34bc1.zip
Continue working on merging code.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py33
1 files changed, 11 insertions, 22 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index ab918433..73bf6304 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -43,14 +43,15 @@ import subprocess
import sys
import tempfile
import time
-import types
import urlparse
import yaml
from cloudinit import importer
from cloudinit import log as logging
+from cloudinit import mergers
from cloudinit import safeyaml
+from cloudinit import type_utils
from cloudinit import url_helper as uhelp
from cloudinit import version
@@ -194,11 +195,12 @@ def fork_cb(child_cb, *args):
os._exit(0) # pylint: disable=W0212
except:
logexc(LOG, ("Failed forking and"
- " calling callback %s"), obj_name(child_cb))
+ " calling callback %s"),
+ type_utils.obj_name(child_cb))
os._exit(1) # pylint: disable=W0212
else:
LOG.debug("Forked child %s who will run callback %s",
- fid, obj_name(child_cb))
+ fid, type_utils.obj_name(child_cb))
def is_true(val, addons=None):
@@ -513,15 +515,6 @@ def make_url(scheme, host, port=None,
return urlparse.urlunparse(pieces)
-def obj_name(obj):
- if isinstance(obj, (types.TypeType,
- types.ModuleType,
- types.FunctionType,
- types.LambdaType)):
- return str(obj.__name__)
- return obj_name(obj.__class__)
-
-
def mergemanydict(srcs, reverse=False):
if reverse:
srcs = reversed(srcs)
@@ -538,13 +531,9 @@ def mergedict(src, cand):
If C{src} has a key C{cand} will not override.
Nested dictionaries are merged recursively.
"""
- 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] = mergedict(src[k], v)
- return src
+ raw_mergers = mergers.default_mergers()
+ merger = mergers.construct(raw_mergers)
+ return merger.merge(src, cand)
@contextlib.contextmanager
@@ -645,7 +634,7 @@ def load_yaml(blob, default=None, allowed=(dict,)):
# Yes this will just be caught, but thats ok for now...
raise TypeError(("Yaml load allows %s root types,"
" but got %s instead") %
- (allowed, obj_name(converted)))
+ (allowed, type_utils.obj_name(converted)))
loaded = converted
except (yaml.YAMLError, TypeError, ValueError):
if len(blob) == 0:
@@ -714,7 +703,7 @@ def read_conf_with_confd(cfgfile):
if not isinstance(confd, (str, basestring)):
raise TypeError(("Config file %s contains 'conf_d' "
"with non-string type %s") %
- (cfgfile, obj_name(confd)))
+ (cfgfile, type_utils.obj_name(confd)))
else:
confd = str(confd).strip()
elif os.path.isdir("%s.d" % cfgfile):
@@ -1472,7 +1461,7 @@ def shellify(cmdlist, add_header=True):
else:
raise RuntimeError(("Unable to shellify type %s"
" which is not a list or string")
- % (obj_name(args)))
+ % (type_utils.obj_name(args)))
LOG.debug("Shellified %s commands.", cmds_made)
return content