Revert "Change patched glance client to fit glance-client code change"

This reverts commit 20152f86f9.

Change-Id: Idd5bce85e39f213cc27bbb35a028df24d84840c9
This commit is contained in:
Zhao_Jian 2014-08-04 16:45:24 +08:00
parent 23c3ea994e
commit 001d845aa1
1 changed files with 15 additions and 9 deletions

View File

@ -9,7 +9,7 @@ def patch_client(service_wrapper, client):
if hasattr(client, 'http_client'):
http_client = client.http_client
org_http_request = http_client._request
org_http_request = http_client._http_request
"""
Patch the _http_request method of glance client and inject
@ -19,10 +19,16 @@ def patch_client(service_wrapper, client):
"""
def _patched_http_request(url, method, **kwargs):
# patch glance HTTPClient to use our keystone for tokens
# and support for non standard URLs
if http_client.endpoint_path and\
not http_client.endpoint_path.endswith('/'):
http_client.endpoint_path += '/'
http_client.auth_token = service_wrapper.keystone.auth_token
if url.startswith('/'):
url = url[1:]
return org_http_request(method, url, **kwargs)
return org_http_request(url, method, **kwargs)
http_client._http_request = _patched_http_request
def _patched_raw_request(method, url, **kwargs):
'''
@ -31,24 +37,24 @@ def patch_client(service_wrapper, client):
Failure to do so can lead to errors during image updates and creates.
'''
kwargs.setdefault('headers', {})
if 'data' in kwargs:
if kwargs['data'] is None:
if 'body' in kwargs:
if kwargs['body'] is None:
kwargs['headers'].setdefault('Content-Type',
'application/json')
else:
kwargs['headers'].setdefault('Content-Type',
'application/octet-stream')
if (hasattr(kwargs['data'], 'read')
if (hasattr(kwargs['body'], 'read')
and method.lower() in ('post', 'put')):
# We use 'Transfer-Encoding: chunked' because
# data size may not always be known in advance.
# body size may not always be known in advance.
kwargs['headers']['Transfer-Encoding'] = 'chunked'
else:
kwargs['headers'].setdefault('Content-Type',
'application/json')
return _patched_http_request(url, method, **kwargs)
http_client._request = _patched_raw_request
http_client.raw_request = _patched_raw_request
"""
Patch v2 glanceclient controller for update image
@ -91,9 +97,9 @@ def patch_client(service_wrapper, client):
url = '/v2/images/%s' % image_id
hdrs = {'Content-Type': 'application/openstack-images-v2.1-json-patch'}
http_client._request('PATCH', url,
http_client.raw_request('PATCH', url,
headers=hdrs,
data=image.patch)
body=image.patch)
#NOTE(bcwaldon): calling image.patch doesn't clear the changes, so
# we need to fetch the image again to get a clean history. This is