62
62
IOError.__init__(self, message)
65
class Error(Exception):
69
class EC2APIError(Error):
70
def __init__(self, message='Unknown', code=None):
74
outstr = '%s: %s' % (code, message)
76
outstr = '%s' % message
77
super(EC2APIError, self).__init__(outstr)
81
"""Wraps an implementation specific exception."""
82
def __init__(self, inner_exception=None):
83
self.inner_exception = inner_exception
84
super(DBError, self).__init__(str(inner_exception))
87
65
def wrap_db_error(f):
88
66
def _wrap(*args, **kwargs):
114
92
return f(*args, **kw)
115
93
except Exception, e:
116
# Save exception since it can be clobbered during processing
117
# below before we can re-raise
118
exc_info = sys.exc_info()
121
payload = dict(args=args, exception=e)
124
# Use a temp vars so we don't shadow
125
# our outer definitions.
128
temp_level = notifier.ERROR
130
temp_type = event_type
132
# If f has multiple decorators, they must use
133
# functools.wraps to ensure the name is
135
temp_type = f.__name__
137
notifier.notify(publisher_id, temp_type, temp_level,
140
# re-raise original exception since it may have been clobbered
141
raise exc_info[0], exc_info[1], exc_info[2]
94
with excutils.save_and_reraise_exception():
96
payload = dict(args=args, exception=e)
99
# Use a temp vars so we don't shadow
100
# our outer definitions.
103
temp_level = notifier.ERROR
105
temp_type = event_type
107
# If f has multiple decorators, they must use
108
# functools.wraps to ensure the name is
110
temp_type = f.__name__
112
context = get_context_from_function_and_args(f,
116
notifier.notify(context, publisher_id, temp_type,
143
119
return functools.wraps(f)(wrapped)
168
144
message = self.message % kwargs
170
146
except Exception as e:
147
# kwargs doesn't match a variable in the message
148
# log the issue and the kwargs
149
LOG.exception(_('Exception in string format operation'))
150
for name, value in kwargs.iteritems():
151
LOG.error("%s: %s" % (name, value))
171
152
# at least get the core message out if something happened
172
153
message = self.message
174
155
super(NovaException, self).__init__(message)
158
class EC2APIError(NovaException):
159
message = _("Unknown")
161
def __init__(self, message=None, code=None):
165
outstr = '%s: %s' % (code, message)
167
outstr = '%s' % message
168
super(EC2APIError, self).__init__(outstr)
171
class DBError(NovaException):
172
"""Wraps an implementation specific exception."""
173
def __init__(self, inner_exception=None):
174
self.inner_exception = inner_exception
175
super(DBError, self).__init__(str(inner_exception))
177
178
class DecryptionFailure(NovaException):
178
179
message = _("Failed to decrypt text")
261
262
message = _("Invalid volume") + ": %(reason)s"
265
class InvalidMetadata(Invalid):
266
message = _("Invalid metadata") + ": %(reason)s"
264
269
class InvalidPortRange(Invalid):
265
270
message = _("Invalid port range %(from_port)s:%(to_port)s. %(msg)s")
277
282
message = _("Invalid cidr %(cidr)s.")
280
class InvalidRPCConnectionReuse(Invalid):
281
message = _("Invalid reuse of an RPC connection.")
284
285
class InvalidUnicodeParameter(Invalid):
285
286
message = _("Invalid Parameter: "
286
287
"Unicode is not supported by the current database.")
338
339
message = _("Service is unavailable at this time.")
341
class VolumeServiceUnavailable(ServiceUnavailable):
342
message = _("Volume service is unavailable at this time.")
345
342
class ComputeServiceUnavailable(ServiceUnavailable):
346
343
message = _("Compute service is unavailable at this time.")
418
415
message = _("Ec2 id %(ec2_id)s is unacceptable.")
418
class InvalidUUID(Invalid):
419
message = _("Expected a uuid but received %(uuid).")
421
422
class NotFound(NovaException):
422
423
message = _("Resource could not be found.")
495
496
class ListingImageRefsNotSupported(Invalid):
496
497
message = _("Some images have been stored via hrefs."
497
+ " This version of the api does not support displaying image hrefs.")
498
" This version of the api does not support displaying image hrefs.")
500
501
class ImageNotFound(NotFound):
525
526
message = _("Cannot find SR to read/write VDI.")
529
class NetworkInUse(NovaException):
530
message = _("Network %(network_id)s is still in use.")
528
533
class NetworkNotCreated(NovaException):
529
534
message = _("%(req)s is required to create a network.")
684
689
message = _("Access Key %(access_key)s could not be found.")
692
class InvalidReservationExpiration(Invalid):
693
message = _("Invalid reservation expiration %(expire)s.")
696
class InvalidQuotaValue(Invalid):
697
message = _("Change would make usage less than 0 for the following "
698
"resources: %(unders)s")
687
701
class QuotaNotFound(NotFound):
688
702
message = _("Quota could not be found")
705
class QuotaResourceUnknown(QuotaNotFound):
706
message = _("Unknown quota resources %(unknown)s.")
691
709
class ProjectQuotaNotFound(QuotaNotFound):
692
710
message = _("Quota for project %(project_id)s could not be found.")
713
class QuotaClassNotFound(QuotaNotFound):
714
message = _("Quota class %(class_name)s could not be found.")
717
class QuotaUsageNotFound(QuotaNotFound):
718
message = _("Quota usage for project %(project_id)s could not be found.")
721
class ReservationNotFound(QuotaNotFound):
722
message = _("Quota reservation %(uuid)s could not be found.")
725
class OverQuota(NovaException):
726
message = _("Quota exceeded for resources: %(overs)s")
695
729
class SecurityGroupNotFound(NotFound):
696
730
message = _("Security group %(security_group_id)s not found.")
790
824
"key %(metadata_key)s.")
827
class InstanceSystemMetadataNotFound(NotFound):
828
message = _("Instance %(instance_uuid)s has no system metadata with "
829
"key %(metadata_key)s.")
793
832
class InstanceTypeExtraSpecsNotFound(NotFound):
794
833
message = _("Instance Type %(instance_type_id)s has no extra specs with "
795
834
"key %(extra_specs_key)s.")
950
989
message = _("Quota exceeded") + ": code=%(code)s"
992
class TooManyInstances(QuotaError):
993
message = _("Quota exceeded: already used %(used)d of %(allowed)d"
997
class VolumeSizeTooLarge(QuotaError):
998
message = _("Maximum volume size exceeded")
1001
class MetadataLimitExceeded(QuotaError):
1002
message = _("Maximum number of metadata items exceeds %(allowed)d")
1005
class OnsetFileLimitExceeded(QuotaError):
1006
message = _("Personality file limit exceeded")
1009
class OnsetFilePathLimitExceeded(QuotaError):
1010
message = _("Personality file path too long")
1013
class OnsetFileContentLimitExceeded(QuotaError):
1014
message = _("Personality file content too long")
1017
class KeypairLimitExceeded(QuotaError):
1018
message = _("Maximum number of key pairs exceeded")
953
1021
class AggregateError(NovaException):
954
1022
message = _("Aggregate %(aggregate_id)s: action '%(action)s' "
955
1023
"caused an error: %(reason)s.")
1020
1088
class CouldNotFetchImage(NovaException):
1021
1089
message = _("Could not fetch image %(image)s")
1092
def get_context_from_function_and_args(function, args, kwargs):
1093
"""Find an arg of type RequestContext and return it.
1095
This is useful in a couple of decorators where we don't
1096
know much about the function we're wrapping.
1099
# import here to avoid circularity:
1100
from nova import context
1102
for arg in itertools.chain(kwargs.values(), args):
1103
if isinstance(arg, context.RequestContext):