~ubuntu-branches/ubuntu/trusty/heat/trusty

« back to all changes in this revision

Viewing changes to heat/common/exception.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2013-09-08 21:51:19 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130908215119-r939tu4aumqgdrkx
Tags: 2013.2~b3-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/control: Add python-netaddr as build-dep.
* debian/heat-common.install: Remove heat-boto and associated man-page
* debian/heat-common.install: Remove heat-cfn and associated man-page
* debian/heat-common.install: Remove heat-watch and associated man-page
* debian/patches/fix-sqlalchemy-0.8.patch: Dropped

[ Adam Gandelman ]
* debian/patches/default-kombu.patch: Dropped.
* debian/patches/default-sqlite.patch: Refreshed.
* debian/*.install, rules: Install heat.conf.sample as common
  config file in heat-common. Drop other per-package configs, they
  are no longer used.
* debian/rules: Clean pbr .egg from build dir if it exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import functools
21
21
import urlparse
22
22
import sys
23
 
from heat.openstack.common import exception
24
 
from heat.openstack.common.gettextutils import _
25
 
 
26
 
 
27
 
OpenstackException = exception.OpenstackException
28
 
NotFound = exception.NotFound
29
 
Error = exception.Error
30
 
InvalidContentType = exception.InvalidContentType
 
23
 
 
24
from heat.openstack.common import log as logging
 
25
 
 
26
 
 
27
_FATAL_EXCEPTION_FORMAT_ERRORS = False
 
28
 
 
29
 
 
30
logger = logging.getLogger(__name__)
31
31
 
32
32
 
33
33
class RedirectException(Exception):
91
91
    return inner
92
92
 
93
93
 
94
 
class MissingCredentialError(OpenstackException):
 
94
class HeatException(Exception):
 
95
    """Base Heat Exception
 
96
 
 
97
    To correctly use this class, inherit from it and define
 
98
    a 'msg_fmt' property. That msg_fmt will get printf'd
 
99
    with the keyword arguments provided to the constructor.
 
100
 
 
101
    """
 
102
    message = _("An unknown exception occurred.")
 
103
 
 
104
    def __init__(self, **kwargs):
 
105
        self.kwargs = kwargs
 
106
 
 
107
        try:
 
108
            self.message = self.message % kwargs
 
109
        except KeyError:
 
110
            exc_info = sys.exc_info()
 
111
            #kwargs doesn't match a variable in the message
 
112
            #log the issue and the kwargs
 
113
            logger.exception(_('Exception in string format operation'))
 
114
            for name, value in kwargs.iteritems():
 
115
                logger.error("%s: %s" % (name, value))
 
116
 
 
117
            if _FATAL_EXCEPTION_FORMAT_ERRORS:
 
118
                raise exc_info[0], exc_info[1], exc_info[2]
 
119
 
 
120
    def __str__(self):
 
121
        return str(self.message)
 
122
 
 
123
 
 
124
class MissingCredentialError(HeatException):
95
125
    message = _("Missing required credential: %(required)s")
96
126
 
97
127
 
98
 
class BadAuthStrategy(OpenstackException):
 
128
class BadAuthStrategy(HeatException):
99
129
    message = _("Incorrect auth strategy, expected \"%(expected)s\" but "
100
130
                "received \"%(received)s\"")
101
131
 
102
132
 
103
 
class AuthBadRequest(OpenstackException):
 
133
class AuthBadRequest(HeatException):
104
134
    message = _("Connect error/bad request to Auth service at URL %(url)s.")
105
135
 
106
136
 
107
 
class AuthUrlNotFound(OpenstackException):
 
137
class AuthUrlNotFound(HeatException):
108
138
    message = _("Auth service at URL %(url)s not found.")
109
139
 
110
140
 
111
 
class AuthorizationFailure(OpenstackException):
 
141
class AuthorizationFailure(HeatException):
112
142
    message = _("Authorization failed.")
113
143
 
114
144
 
115
 
class NotAuthenticated(OpenstackException):
 
145
class NotAuthenticated(HeatException):
116
146
    message = _("You are not authenticated.")
117
147
 
118
148
 
119
 
class Forbidden(OpenstackException):
 
149
class Forbidden(HeatException):
120
150
    message = _("You are not authorized to complete this action.")
121
151
 
122
152
 
125
155
    message = _("You are not authorized to complete this action.")
126
156
 
127
157
 
128
 
class Invalid(OpenstackException):
 
158
class Invalid(HeatException):
129
159
    message = _("Data supplied was not valid: %(reason)s")
130
160
 
131
161
 
132
 
class AuthorizationRedirect(OpenstackException):
 
162
class AuthorizationRedirect(HeatException):
133
163
    message = _("Redirecting to %(uri)s for authorization.")
134
164
 
135
165
 
136
 
class ClientConfigurationError(OpenstackException):
 
166
class ClientConfigurationError(HeatException):
137
167
    message = _("There was an error configuring the client.")
138
168
 
139
169
 
140
 
class MultipleChoices(OpenstackException):
141
 
    message = _("The request returned a 302 Multiple Choices. This generally "
142
 
                "means that you have not included a version indicator in a "
143
 
                "request URI.\n\nThe body of response returned:\n%(body)s")
144
 
 
145
 
 
146
 
class LimitExceeded(OpenstackException):
147
 
    message = _("The request returned a 413 Request Entity Too Large. This "
148
 
                "generally means that rate limiting or a quota threshold was "
149
 
                "breached.\n\nThe response body:\n%(body)s")
150
 
 
151
 
    def __init__(self, *args, **kwargs):
152
 
        self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
153
 
                            else None)
154
 
        super(LimitExceeded, self).__init__(*args, **kwargs)
155
 
 
156
 
 
157
 
class ServiceUnavailable(OpenstackException):
158
 
    message = _("The request returned a 503 ServiceUnavilable. This "
159
 
                "generally occurs on service overload or other transient "
160
 
                "outage.")
161
 
 
162
 
    def __init__(self, *args, **kwargs):
163
 
        self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
164
 
                            else None)
165
 
        super(ServiceUnavailable, self).__init__(*args, **kwargs)
166
 
 
167
 
 
168
 
class RequestUriTooLong(OpenstackException):
 
170
class RequestUriTooLong(HeatException):
169
171
    message = _("The URI was too long.")
170
172
 
171
173
 
172
 
class ServerError(OpenstackException):
 
174
class ServerError(HeatException):
173
175
    message = _("The request returned 500 Internal Server Error"
174
176
                "\n\nThe response body:\n%(body)s")
175
177
 
176
178
 
177
 
class MaxRedirectsExceeded(OpenstackException):
 
179
class MaxRedirectsExceeded(HeatException):
178
180
    message = _("Maximum redirects (%(redirects)s) was exceeded.")
179
181
 
180
182
 
181
 
class InvalidRedirect(OpenstackException):
 
183
class InvalidRedirect(HeatException):
182
184
    message = _("Received invalid HTTP redirect.")
183
185
 
184
186
 
185
 
class NoServiceEndpoint(OpenstackException):
 
187
class NoServiceEndpoint(HeatException):
186
188
    message = _("Response from Keystone does not contain a Heat endpoint.")
187
189
 
188
190
 
189
 
class RegionAmbiguity(OpenstackException):
 
191
class RegionAmbiguity(HeatException):
190
192
    message = _("Multiple 'image' service matches for region %(region)s. This "
191
193
                "generally means that a region is required and you have not "
192
194
                "supplied one.")
193
195
 
194
196
 
195
 
class UserParameterMissing(OpenstackException):
 
197
class UserParameterMissing(HeatException):
196
198
    message = _("The Parameter (%(key)s) was not provided.")
197
199
 
198
200
 
199
 
class UnknownUserParameter(OpenstackException):
 
201
class UnknownUserParameter(HeatException):
200
202
    message = _("The Parameter (%(key)s) was not defined in template.")
201
203
 
202
204
 
203
 
class InvalidTemplateAttribute(OpenstackException):
 
205
class InvalidTemplateAttribute(HeatException):
204
206
    message = _("The Referenced Attribute (%(resource)s %(key)s)"
205
207
                " is incorrect.")
206
208
 
207
209
 
208
 
class InvalidTemplateReference(OpenstackException):
209
 
    message = _("The specified reference (%(resource)s %(key)s)"
 
210
class InvalidTemplateReference(HeatException):
 
211
    message = _("The specified reference \"%(resource)s\" (in %(key)s)"
210
212
                " is incorrect.")
211
213
 
212
214
 
213
 
class UserKeyPairMissing(OpenstackException):
 
215
class UserKeyPairMissing(HeatException):
214
216
    message = _("The Key (%(key_name)s) could not be found.")
215
217
 
216
218
 
217
 
class FlavorMissing(OpenstackException):
 
219
class FlavorMissing(HeatException):
218
220
    message = _("The Flavor ID (%(flavor_id)s) could not be found.")
219
221
 
220
222
 
221
 
class ImageNotFound(OpenstackException):
 
223
class ImageNotFound(HeatException):
222
224
    message = _("The Image (%(image_name)s) could not be found.")
223
225
 
224
226
 
225
 
class NoUniqueImageFound(OpenstackException):
 
227
class NoUniqueImageFound(HeatException):
226
228
    message = _("Multiple images were found with name (%(image_name)s).")
227
229
 
228
230
 
229
 
class InvalidTenant(OpenstackException):
 
231
class InvalidTenant(HeatException):
230
232
    message = _("Searching Tenant %(target)s "
231
233
                "from Tenant %(actual)s forbidden.")
232
234
 
233
235
 
234
 
class StackNotFound(OpenstackException):
 
236
class StackNotFound(HeatException):
235
237
    message = _("The Stack (%(stack_name)s) could not be found.")
236
238
 
237
239
 
238
 
class StackExists(OpenstackException):
 
240
class StackExists(HeatException):
239
241
    message = _("The Stack (%(stack_name)s) already exists.")
240
242
 
241
243
 
242
 
class StackValidationFailed(OpenstackException):
 
244
class StackValidationFailed(HeatException):
243
245
    message = _("%(message)s")
244
246
 
245
247
 
246
 
class ResourceNotFound(OpenstackException):
 
248
class ResourceNotFound(HeatException):
247
249
    message = _("The Resource (%(resource_name)s) could not be found "
248
250
                "in Stack %(stack_name)s.")
249
251
 
250
252
 
251
 
class ResourceTypeNotFound(OpenstackException):
 
253
class ResourceTypeNotFound(HeatException):
252
254
    message = _("The Resource Type (%(type_name)s) could not be found.")
253
255
 
254
256
 
255
 
class ResourceNotAvailable(OpenstackException):
 
257
class ResourceNotAvailable(HeatException):
256
258
    message = _("The Resource (%(resource_name)s) is not available.")
257
259
 
258
260
 
259
 
class PhysicalResourceNotFound(OpenstackException):
 
261
class PhysicalResourceNotFound(HeatException):
260
262
    message = _("The Resource (%(resource_id)s) could not be found.")
261
263
 
262
264
 
263
 
class WatchRuleNotFound(OpenstackException):
 
265
class WatchRuleNotFound(HeatException):
264
266
    message = _("The Watch Rule (%(watch_name)s) could not be found.")
265
267
 
266
268
 
267
 
class ActionInProgress(OpenstackException):
268
 
    message = _("Stack %(stack_name)s already has an action (%(action)s) "
269
 
                "in progress")
270
 
 
271
 
 
272
 
class ResourceFailure(OpenstackException):
 
269
class ResourceFailure(HeatException):
273
270
    message = _("%(exc_type)s: %(message)s")
274
271
 
275
272
    def __init__(self, exception, resource, action=None):
283
280
                                              message=str(exception))
284
281
 
285
282
 
286
 
class NotSupported(OpenstackException):
 
283
class NotSupported(HeatException):
287
284
    message = _("%(feature)s is not supported.")
288
285
 
289
286
 
290
 
class ResourcePropertyConflict(OpenstackException):
 
287
class ResourcePropertyConflict(HeatException):
291
288
    message = _('Cannot define the following properties at the same time: %s.')
292
289
 
293
290
    def __init__(self, *args):
294
291
        self.message = self.message % ", ".join(args)
295
292
        super(ResourcePropertyConflict, self).__init__()
 
293
 
 
294
 
 
295
class HTTPExceptionDisguise(Exception):
 
296
    """Disguises HTTP exceptions so they can be handled by the webob fault
 
297
    application in the wsgi pipeline.
 
298
    """
 
299
 
 
300
    def __init__(self, exception):
 
301
        self.exc = exception
 
302
        self.tb = sys.exc_info()[2]
 
303
 
 
304
 
 
305
class TemplateTooBig(HeatException):
 
306
    message = _('Template exceeds maximum allowed size.')
 
307
 
 
308
 
 
309
class EgressRuleNotAllowed(HeatException):
 
310
    message = _("Egress rules are only allowed when "
 
311
                "Neutron is used and the 'VpcId' property is set.")
 
312
 
 
313
 
 
314
class Error(Exception):
 
315
    def __init__(self, message=None):
 
316
        super(Error, self).__init__(message)
 
317
 
 
318
 
 
319
class NotFound(Error):
 
320
    pass
 
321
 
 
322
 
 
323
class InvalidContentType(HeatException):
 
324
    message = "Invalid content type %(content_type)s"
 
325
 
 
326
 
 
327
class StackRecursionLimitReached(HeatException):
 
328
    message = _("Recursion depth exceeds %d.")
 
329
 
 
330
    def __init__(self, recursion_depth):
 
331
        self.message = self.message % recursion_depth
 
332
        super(StackRecursionLimitReached, self).__init__()