From 5acd5a6a4adc430989ae05c434d0ac5a9a448b84 Mon Sep 17 00:00:00 2001 From: isethi Date: Fri, 7 Sep 2012 20:54:09 +0000 Subject: [PATCH] Catches HTTP 300 while printing responses If glance v1 api is not enabled, and a request is made to it, it gives a KeyError. This patch catches the 300 error and displays error message. Fixes bug 1046607 Change-Id: I0009a5deca3b5dd5ccaeaea90feee21274bfe090 --- glanceclient/common/http.py | 2 ++ glanceclient/exc.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 6464ee99..d81ac9ab 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -159,6 +159,8 @@ 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 == 300: + raise exc.from_response(resp) return resp, body_iter diff --git a/glanceclient/exc.py b/glanceclient/exc.py index 78ca4f73..771d0e32 100644 --- a/glanceclient/exc.py +++ b/glanceclient/exc.py @@ -52,6 +52,16 @@ class HTTPException(ClientException): return "%s (HTTP %s)" % (self.__class__.__name__, self.code) +class HTTPMultipleChoices(HTTPException): + code = 300 + + def __str__(self): + self.details = ("Requested version of OpenStack Images API is not" + "available.") + return "%s (HTTP %s) %s" % (self.__class__.__name__, self.code, + self.details) + + class BadRequest(HTTPException): """DEPRECATED""" code = 400