summaryrefslogtreecommitdiff
path: root/cloudinit/mergers/dict.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2012-11-22 19:45:43 -0800
committerJoshua Harlow <harlowja@gmail.com>2012-11-22 19:45:43 -0800
commit3941466b3e065c9ce7bb7500e41f464993861672 (patch)
tree152ff7635217238d1ee562fd72df688c4c924599 /cloudinit/mergers/dict.py
parent180e83b20aa02dc9df903fa7e31121dd49a49b3a (diff)
downloadvyos-cloud-init-3941466b3e065c9ce7bb7500e41f464993861672.tar.gz
vyos-cloud-init-3941466b3e065c9ce7bb7500e41f464993861672.zip
Allow mergers to take options.
Diffstat (limited to 'cloudinit/mergers/dict.py')
-rw-r--r--cloudinit/mergers/dict.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/cloudinit/mergers/dict.py b/cloudinit/mergers/dict.py
index a0ffaa33..e7073bd9 100644
--- a/cloudinit/mergers/dict.py
+++ b/cloudinit/mergers/dict.py
@@ -18,8 +18,12 @@
class Merger(object):
- def __init__(self, merger):
+ def __init__(self, merger, opts):
self._merger = merger
+ self._overwrite = 'overwrite' in opts
+
+ if opts and opts.lower().find("overwrite") != -1:
+ self._overwrite = True
def _on_dict(self, value, merge_with):
if not isinstance(merge_with, (dict)):
@@ -27,7 +31,10 @@ class Merger(object):
merged = dict(value)
for (k, v) in merge_with.items():
if k in merged:
- merged[k] = self._merger.merge(merged[k], v)
+ if not self._overwrite:
+ merged[k] = self._merger.merge(merged[k], v)
+ else:
+ merged[k] = v
else:
merged[k] = v
return merged