summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
diff options
context:
space:
mode:
authorAmalaBasha <amala.alungal@RACKSPACE.COM>2014-07-01 14:45:12 +0530
committerAmalaBasha <amala.alungal@RACKSPACE.COM>2014-07-10 13:22:05 +0530
commitdbb242b776908ca50ed8557ebfe7cfcd879366c8 (patch)
tree597e583588dfb4313cf9d10bca34cc956c716e9f /glanceclient/common/utils.py
parent1db17aaad9a04cc98fc848b23a76db52a5f62965 (diff)
downloadpython-glanceclient-dbb242b776908ca50ed8557ebfe7cfcd879366c8.tar.gz
Replace old httpclient with requests
This review implements blueprint python-request and replaces the old http client implementation in favor of a new one based on python-requests. Major changes: * raw_request and json_request removed since everything is now being handled by the same method "_request" * New methods that match HTTP's methods were added: - get - put - post - head - patch - delete * Content-Type is now being "inferred" based on the data being sent: - if it is file-like object it chunks the request - if it is a python type not instance of basestring then it'll try to serialize it to json - Every other case will keep the incoming content-type and will send the data as is. * Glanceclient's HTTPSConnection implementation will be used if no-compression flag is set to True. Co-Author: Flavio Percoco<flaper87@gmail.com> Change-Id: I09f70eee3e2777f52ce040296015d41649c2586a
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r--glanceclient/common/utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 6cdc364..04f5add 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -16,6 +16,7 @@
from __future__ import print_function
import errno
+import hashlib
import os
import re
import sys
@@ -335,3 +336,22 @@ def print_image(image_obj, max_col_width=None):
print_dict(image, max_column_width=max_col_width)
else:
print_dict(image)
+
+
+def integrity_iter(iter, checksum):
+ """
+ Check image data integrity.
+
+ :raises: IOError
+ """
+ md5sum = hashlib.md5()
+ for chunk in iter:
+ yield chunk
+ if isinstance(chunk, six.string_types):
+ chunk = six.b(chunk)
+ md5sum.update(chunk)
+ md5sum = md5sum.hexdigest()
+ if md5sum != checksum:
+ raise IOError(errno.EPIPE,
+ 'Corrupt image download. Checksum was %s expected %s' %
+ (md5sum, checksum))