From 1cdbe4934864fa43fc603a21ab6ebeb4ce392b97 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Thu, 17 Oct 2013 12:23:35 +0400 Subject: [PATCH] Change client to return both response code and response body. Add an ability to pass hash_sum parameter. --- metadataclient/common/exceptions.py | 4 ---- metadataclient/common/http.py | 2 +- metadataclient/v1/metadata_client.py | 27 +++++++++++++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/metadataclient/common/exceptions.py b/metadataclient/common/exceptions.py index 31fa931..a8e2fef 100644 --- a/metadataclient/common/exceptions.py +++ b/metadataclient/common/exceptions.py @@ -62,10 +62,6 @@ class HTTPMultipleChoices(HTTPException): self.details) -class HTTPNotModified(HTTPException): - code = 304 - - class BadRequest(HTTPException): """DEPRECATED!""" code = 400 diff --git a/metadataclient/common/http.py b/metadataclient/common/http.py index 242a8f7..a62c2af 100644 --- a/metadataclient/common/http.py +++ b/metadataclient/common/http.py @@ -235,7 +235,7 @@ class HTTPClient(object): elif resp.status in (301, 302, 305): # Redirected. Reissue the request to the new location. return self._http_request(resp['location'], method, **kwargs) - elif resp.status in (300, 304): + elif resp.status == 300: raise exc.from_response(resp) return resp, body_iter diff --git a/metadataclient/v1/metadata_client.py b/metadataclient/v1/metadata_client.py index ab29971..6037115 100644 --- a/metadataclient/v1/metadata_client.py +++ b/metadataclient/v1/metadata_client.py @@ -33,20 +33,27 @@ class Controller(object): def __init__(self, http_client): self.http_client = http_client - def get_ui_data(self): + def _get_data(self, endpoint_type, hash_sum=None): + if hash_sum: + url = '/v1/client/{0}?hash={1}'.format(endpoint_type, hash_sum) + else: + url = '/v1/client/{0}'.format(endpoint_type) + return self.http_client.raw_request('GET', url) + + def get_ui_data(self, hash_sum=None): """ - Download tar.gz with + Download tar.gz with ui metadata. Returns a tuple + (status, body_iterator) where status can be either 200 or 304. In the + 304 case there is no sense in iterating with body_iterator. """ - url = '/v1/client/ui' - resp, body = self.http_client.raw_request('GET', url) - return body + return self._get_data('ui', hash_sum=hash_sum) - def get_conductor_data(self): + def get_conductor_data(self, hash_sum=None): """ - Download tar.gz with + Download tar.gz with conductor metadata. Returns a tuple + (status, body_iterator) where status can be either 200 or 304. In the + 304 case there is no sense in iterating with body_iterator. """ - url = '/v1/client/conductor' - resp, body = self.http_client.raw_request('GET', url) - return body \ No newline at end of file + return self._get_data('conductor', hash_sum=hash_sum)