23
23
import boto.exception
24
24
from django.shortcuts import redirect
25
from django.utils.http import urlquote
28
class NovaResponseError(Exception):
25
from django.core import exceptions as core_exceptions
28
class NovaServerError(Exception):
30
30
Consumes a BotoServerError and gives more meaningful errors.
32
32
def __init__(self, ec2error):
33
self.code = ec2error.reason
34
if ec2error.reason == 'Unauthorized':
35
self.message = 'You do not have the necessary privileges to ' \
36
'perform the requested action.'
38
self.message = 'An unexpected error occurred. ' \
39
'Please try your request again.'
45
class NovaUnavailableError(Exception):
33
self.status = ec2error.status
34
self.message = ec2error.reason
40
class NovaApiError(Exception):
42
Used when Nova returns a 400 Bad Request status.
44
def __init__(self, ec2error):
45
self.message = ec2error.error_message
51
class NovaUnavailableError(NovaServerError):
47
53
Used when Nova returns a 503 Service Unavailable status.
58
class NovaUnauthorizedError(core_exceptions.PermissionDenied):
60
Used when Nova returns a 401 Not Authorized status.
52
65
def wrap_nova_error(func):
54
67
Used to decorate a function that interacts with boto. It will catch
59
72
return func(*args, **kwargs)
60
73
except boto.exception.BotoServerError, e:
74
if e.status == 400 and e.error_code == 'ApiError':
77
raise NovaUnauthorizedError()
62
79
raise NovaUnavailableError(e)
63
raise NovaResponseError(e)
80
raise NovaServerError(e)