summaryrefslogtreecommitdiff
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2012-01-09 18:21:57 +1100
committerMichael Still <mikal@stillhq.com>2012-02-03 09:53:15 +1100
commit3141ca776267d11a71c0144a0d92651ac8d8ba9e (patch)
tree23397bdf85be3fb0e352313f6baf0aaec6c9d180 /nova/utils.py
parent6990b93ee6d8e0b239d1338242c111bbc3d7563d (diff)
downloadnova-3141ca776267d11a71c0144a0d92651ac8d8ba9e.tar.gz
blueprint nova-image-cache-management phase1
Phase 1 of the image-cache-management blueprint. Implement checksumming and verification of base images, as well as removal of base images which are not in use. Removal is enabled with a flag. Change-Id: Ib04a02075a103c2fef6716fd0ac87c41a3535d37
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index d1968ac4d0..f86b4ff1f4 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -22,6 +22,7 @@
import contextlib
import datetime
import functools
+import hashlib
import inspect
import json
import lockfile
@@ -1194,6 +1195,13 @@ def read_cached_file(filename, cache_info, reload_func=None):
return cache_info['data']
+def hash_file(file_like_object):
+ """Generate a hash for the contents of a file."""
+ checksum = hashlib.sha1()
+ any(map(checksum.update, iter(lambda: file_like_object.read(32768), '')))
+ return checksum.hexdigest()
+
+
@contextlib.contextmanager
def temporary_mutation(obj, **kwargs):
"""Temporarily set the attr on a particular object to a given value then