diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-18 13:29:39 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-18 13:29:39 -0700 |
commit | 0eabf9cdc2870982bcabc6e5d05c80078fa100cb (patch) | |
tree | caa3882e07efbebf2e8407bdbe3a5a890c841bb4 /cloudinit/mergers | |
parent | 6ad068d1ae175d784481fe8f8e190b2721a221f5 (diff) | |
download | vyos-cloud-init-0eabf9cdc2870982bcabc6e5d05c80078fa100cb.tar.gz vyos-cloud-init-0eabf9cdc2870982bcabc6e5d05c80078fa100cb.zip |
Adjust how merging is done.
Diffstat (limited to 'cloudinit/mergers')
-rw-r--r-- | cloudinit/mergers/dict.py | 5 | ||||
-rw-r--r-- | cloudinit/mergers/list.py | 18 |
2 files changed, 6 insertions, 17 deletions
diff --git a/cloudinit/mergers/dict.py b/cloudinit/mergers/dict.py index 45a7d3a5..929d3865 100644 --- a/cloudinit/mergers/dict.py +++ b/cloudinit/mergers/dict.py @@ -20,7 +20,7 @@ class Merger(object): def __init__(self, merger, opts): self._merger = merger - self._overwrite = 'overwrite' in opts + self._not_overwrite = 'not_overwrite' in opts # This merging algorithm will attempt to merge with # another dictionary, on encountering any other type of object @@ -39,7 +39,8 @@ class Merger(object): merged = dict(value) for (k, v) in merge_with.items(): if k in merged: - if not self._overwrite: + if self._not_overwrite: + # Attempt to merge them.... merged[k] = self._merger.merge(merged[k], v) else: merged[k] = v diff --git a/cloudinit/mergers/list.py b/cloudinit/mergers/list.py index a56ff007..7c8b2e2a 100644 --- a/cloudinit/mergers/list.py +++ b/cloudinit/mergers/list.py @@ -20,7 +20,6 @@ class Merger(object): def __init__(self, merger, opts): self._merger = merger - self._discard_non = 'discard_non_list' in opts self._extend = 'extend' in opts def _on_tuple(self, value, merge_with): @@ -33,18 +32,7 @@ class Merger(object): # attempt to merge instead, which means that values from the list # to merge with will replace values in te original list (they will # also be merged recursively). - # - # If the value to merge with is not a list, and we are set to discared - # then no modifications will take place, otherwise we will just append - # the value to merge with onto the end of our own list. def _on_list(self, value, merge_with): - new_value = list(value) - if isinstance(merge_with, (tuple, list)): - if self._extend: - new_value.extend(merge_with) - else: - return new_value - else: - if not self._discard_non: - new_value.append(merge_with) - return new_value + if not self._extend or not isinstance(merge_with, (tuple, list)): + return merge_with + return list(value).extend(merge_with) |