catching authorization failure (x-server-management-url KeyError)

This commit is contained in:
Brian Waldon 2011-08-10 13:25:17 -04:00
parent c8b3b13615
commit 1f7605cb7e
3 changed files with 11 additions and 1 deletions

View File

@ -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:

View File

@ -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.

View File

@ -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)