summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-03-22 20:26:45 +0000
committerRick Harris <rick.harris@rackspace.com>2011-03-22 20:26:45 +0000
commit789fcb46915dce5fa533357ac462040ec6aa8968 (patch)
tree9bc78d0a53a718e8f1a837d3e94939c0d74c67b4 /nova/utils.py
parent3f637a9325ffa7b0cc8a2369576b9fc4f2ebf0f5 (diff)
downloadnova-789fcb46915dce5fa533357ac462040ec6aa8968.tar.gz
nova-789fcb46915dce5fa533357ac462040ec6aa8968.tar.xz
nova-789fcb46915dce5fa533357ac462040ec6aa8968.zip
Adding BASE_IMAGE_ATTRS to ImageService
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 199ee8701..96a51b425 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -597,3 +597,39 @@ def get_from_path(items, path):
return results
else:
return get_from_path(results, remainder)
+
+
+def flatten_dict(dict_, flattened=None):
+ """Recursively flatten a nested dictionary"""
+ flattened = flattened or {}
+ for key, value in dict_.iteritems():
+ if hasattr(value, 'iteritems'):
+ flatten_dict(value, flattened)
+ else:
+ flattened[key] = value
+ return flattened
+
+
+def partition_dict(dict_, keys):
+ """Return two dicts, one containing only `keys` the other containing
+ everything but `keys`
+ """
+ intersection = {}
+ difference = {}
+ for key, value in dict_.iteritems():
+ if key in keys:
+ intersection[key] = value
+ else:
+ difference[key] = value
+ return intersection, difference
+
+
+def map_dict_keys(dict_, key_map):
+ """Return a dictionary in which the dictionaries keys are mapped to
+ new keys.
+ """
+ mapped = {}
+ for key, value in dict_.iteritems():
+ mapped_key = key_map[key] if key in key_map else key
+ mapped[mapped_key] = value
+ return mapped