diff --git a/novaclient/client.py b/novaclient/client.py index 874c3484a..c49f079b2 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -141,7 +141,10 @@ class HTTPClient(httplib2.Http): headers['X-Auth-Project-Id'] = self.projectid resp, body = self.request(self.auth_url, 'GET', headers=headers) - self.management_url = resp['x-server-management-url'] + try: + self.management_url = resp['x-server-management-url'] + except KeyError: + raise exceptions.AuthorizationFailure() self.auth_token = resp['x-auth-token'] else: diff --git a/novaclient/exceptions.py b/novaclient/exceptions.py index ae456decd..cfbb0d4d5 100644 --- a/novaclient/exceptions.py +++ b/novaclient/exceptions.py @@ -8,6 +8,10 @@ class CommandError(Exception): pass +class AuthorizationFailure(Exception): + pass + + class ClientException(Exception): """ The base exception class for all exceptions this library raises. @@ -29,6 +33,7 @@ class BadRequest(ClientException): message = "Bad request" + class Unauthorized(ClientException): """ HTTP 401 - Unauthorized: bad credentials. diff --git a/novaclient/shell.py b/novaclient/shell.py index c2f94164e..869b8c842 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -166,6 +166,8 @@ class OpenStackComputeShell(object): self.cs.authenticate() except exc.Unauthorized: raise exc.CommandError("Invalid OpenStack Nova credentials.") + except exc.AuthorizationFailure: + raise exc.CommandError("Unable to authorize user") args.func(self.cs, args)