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 headers['X-Auth-Project-Id'] = self.projectid
resp, body = self.request(self.auth_url, 'GET', headers=headers) 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'] self.auth_token = resp['x-auth-token']
else: else:

View File

@ -8,6 +8,10 @@ class CommandError(Exception):
pass pass
class AuthorizationFailure(Exception):
pass
class ClientException(Exception): class ClientException(Exception):
""" """
The base exception class for all exceptions this library raises. The base exception class for all exceptions this library raises.
@ -29,6 +33,7 @@ class BadRequest(ClientException):
message = "Bad request" message = "Bad request"
class Unauthorized(ClientException): class Unauthorized(ClientException):
""" """
HTTP 401 - Unauthorized: bad credentials. HTTP 401 - Unauthorized: bad credentials.

View File

@ -166,6 +166,8 @@ class OpenStackComputeShell(object):
self.cs.authenticate() self.cs.authenticate()
except exc.Unauthorized: except exc.Unauthorized:
raise exc.CommandError("Invalid OpenStack Nova credentials.") raise exc.CommandError("Invalid OpenStack Nova credentials.")
except exc.AuthorizationFailure:
raise exc.CommandError("Unable to authorize user")
args.func(self.cs, args) args.func(self.cs, args)