diff options
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py index 9cfb6d06d..adb1cf45c 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -861,6 +861,24 @@ def subset_dict(dict_, keys): return subset +def diff_dict(orig, new): + """ + Return a dict describing how to change orig to new. The keys + correspond to values that have changed; the value will be a list + of one or two elements. The first element of the list will be + either '+' or '-', indicating whether the key was updated or + deleted; if the key was updated, the list will contain a second + element, giving the updated value. + """ + # Figure out what keys went away + result = dict((k, ['-']) for k in set(orig.keys()) - set(new.keys())) + # Compute the updates + for key, value in new.items(): + if key not in orig or value != orig[key]: + result[key] = ['+', value] + return result + + def check_isinstance(obj, cls): """Checks that obj is of type cls, and lets PyLint infer types.""" if isinstance(obj, cls): |
