Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 228 lines (149 sloc) 6.262 kB
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
caeece6 Updated licenses
Devin Carlen authored
2
3 # Copyright 2010 United States Government as represented by the
4ba6802 @vishvananda Removed trailing whitespace from header
vishvananda authored
4 # Administrator of the National Aeronautics and Space Administration.
caeece6 Updated licenses
Devin Carlen authored
5 # All Rights Reserved.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
10 #
caeece6 Updated licenses
Devin Carlen authored
11 # http://www.apache.org/licenses/LICENSE-2.0
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
12 #
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
13 # Unless required by applicable law or agreed to in writing, software
caeece6 Updated licenses
Devin Carlen authored
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
18
19 """
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
20 Nova base exception handling, including decorator for re-raising
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
21 Nova-type exceptions. SHOULD include dedicated exception logging.
22 """
23
c7305af @xtoddx Apply logging changes as a giant patch to work around the cloudpipe d…
xtoddx authored
24 from nova import log as logging
25 LOG = logging.getLogger('nova.exception')
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
26
d508418 @termie rather comprehensive style fixes
termie authored
27
fc5e1c6 @vishvananda a few formatting fixes and moved exception
vishvananda authored
28 class ProcessExecutionError(IOError):
fa7d288 @SandyWalsh pep8
SandyWalsh authored
29
fc5e1c6 @vishvananda a few formatting fixes and moved exception
vishvananda authored
30 def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
31 description=None):
32 if description is None:
12802a7 First round of i18n-ifying strings in Nova
jaypipes@gmail.com authored
33 description = _("Unexpected error while running command.")
fc5e1c6 @vishvananda a few formatting fixes and moved exception
vishvananda authored
34 if exit_code is None:
35 exit_code = '-'
68c9c89 @EdLeafe Completed first pass at converting all localized strings with multipl…
EdLeafe authored
36 message = _("%(description)s\nCommand: %(cmd)s\n"
37 "Exit code: %(exit_code)s\nStdout: %(stdout)r\n"
38 "Stderr: %(stderr)r") % locals()
fc5e1c6 @vishvananda a few formatting fixes and moved exception
vishvananda authored
39 IOError.__init__(self, message)
40
41
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
42 class Error(Exception):
fa7d288 @SandyWalsh pep8
SandyWalsh authored
43
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
44 def __init__(self, message=None):
45 super(Error, self).__init__(message)
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
46
d508418 @termie rather comprehensive style fixes
termie authored
47
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
48 class ApiError(Error):
e2d66aa @sleepsonthefloor fix for lp712982, and likely a variety of other dashboard error handling
sleepsonthefloor authored
49 def __init__(self, message='Unknown', code='ApiError'):
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
50 self.message = message
51 self.code = code
e012a2b PEP8 and pylint cleanup. There should be no functional changes here, …
Eric Day authored
52 super(ApiError, self).__init__('%s: %s' % (code, message))
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
53
d508418 @termie rather comprehensive style fixes
termie authored
54
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
55 class NotFound(Error):
56 pass
57
d508418 @termie rather comprehensive style fixes
termie authored
58
9c35a9a @vishvananda Fixes NotFound messages in api to show the ec2_id.
vishvananda authored
59 class InstanceNotFound(NotFound):
60 def __init__(self, message, instance_id):
61 self.instance_id = instance_id
62 super(InstanceNotFound, self).__init__(message)
63
64
65 class VolumeNotFound(NotFound):
66 def __init__(self, message, volume_id):
67 self.volume_id = volume_id
68 super(VolumeNotFound, self).__init__(message)
69
70
9451872 @anotherjesse Merged Vish's work on adding projects to nova
anotherjesse authored
71 class Duplicate(Error):
72 pass
73
d508418 @termie rather comprehensive style fixes
termie authored
74
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
75 class NotAuthorized(Error):
76 pass
77
d508418 @termie rather comprehensive style fixes
termie authored
78
302afc1 Fixes up Bucket to throw proper NotFound and NotEmpty exceptions
jaypipes@gmail.com authored
79 class NotEmpty(Error):
80 pass
81
d508418 @termie rather comprehensive style fixes
termie authored
82
28336ed Address a couple of the TODO's: We now have half-decent input validat…
Soren Hansen authored
83 class InvalidInputException(Error):
848aced Refactor wsgi.Serializer away from handling Requests directly; now re…
Brian Waldon authored
84 pass
85
86
87 class InvalidContentType(Error):
28336ed Address a couple of the TODO's: We now have half-decent input validat…
Soren Hansen authored
88 pass
89
d508418 @termie rather comprehensive style fixes
termie authored
90
e66f301 @EdLeafe Got the basic 'set admin password' stuff working
EdLeafe authored
91 class TimeoutException(Error):
92 pass
93
94
9bdcc71 @vishvananda wrap sqlalchemy exceptions in a generic error
vishvananda authored
95 class DBError(Error):
96 """Wraps an implementation specific exception"""
97 def __init__(self, inner_exception):
98 self.inner_exception = inner_exception
99 super(DBError, self).__init__(str(inner_exception))
100
101
102 def wrap_db_error(f):
103 def _wrap(*args, **kwargs):
104 try:
105 return f(*args, **kwargs)
106 except Exception, e:
107 LOG.exception(_('DB exception wrapped'))
108 raise DBError(e)
109 return _wrap
110 _wrap.func_name = f.func_name
111
112
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
113 def wrap_exception(f):
114 def _wrap(*args, **kw):
115 try:
116 return f(*args, **kw)
117 except Exception, e:
118 if not isinstance(e, Error):
3c8efde @vishvananda trackback formatting isn't logging correctly
vishvananda authored
119 #exc_type, exc_value, exc_traceback = sys.exc_info()
c7305af @xtoddx Apply logging changes as a giant patch to work around the cloudpipe d…
xtoddx authored
120 LOG.exception(_('Uncaught exception'))
3c8efde @vishvananda trackback formatting isn't logging correctly
vishvananda authored
121 #logging.error(traceback.extract_stack(exc_traceback))
bf6e6e7 @anotherjesse initial commit
anotherjesse authored
122 raise Error(str(e))
123 raise
124 _wrap.func_name = f.func_name
125 return _wrap
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
126
127
128 class NovaException(Exception):
8762168 adding documentation & error handling
Brian Waldon authored
129 """Base Nova Exception
130
131 To correctly use this class, inherit from it and define
132 a 'message' property. That message will get printf'd
133 with the keyword arguments provided to the constructor.
134
135 """
136 message = "An unknown exception occurred."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
137
138 def __init__(self, **kwargs):
8762168 adding documentation & error handling
Brian Waldon authored
139 try:
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
140 self._error_string = self.message % kwargs
8762168 adding documentation & error handling
Brian Waldon authored
141
142 except Exception:
143 # at least get the core message out if something happened
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
144 self._error_string = self.message
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
145
146 def __str__(self):
147 return self._error_string
148
149
8762168 adding documentation & error handling
Brian Waldon authored
150 #TODO(bcwaldon): EOL this exception!
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
151 class Invalid(NovaException):
152 pass
153
154
155 class InstanceNotRunning(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
156 message = _("Instance %(instance_id)s is not running.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
157
158
159 class InstanceNotSuspended(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
160 message = _("Instance %(instance_id)s is not suspended.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
161
162
163 class InstanceSuspendFailure(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
164 message = _("Failed to suspend instance") + ": %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
165
166
167 class InstanceResumeFailure(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
168 message = _("Failed to resume server") + ": %(reason)s."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
169
170
171 class InstanceRebootFailure(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
172 message = _("Failed to reboot instance") + ": %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
173
174
175 class ServiceUnavailable(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
176 message = _("Service is unavailable at this time.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
177
178
179 class VolumeServiceUnavailable(ServiceUnavailable):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
180 message = _("Volume service is unavailable at this time.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
181
182
183 class ComputeServiceUnavailable(ServiceUnavailable):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
184 message = _("Compute service is unavailable at this time.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
185
186
187 class UnableToMigrateToSelf(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
188 message = _("Unable to migrate instance (%(instance_id)s) "
189 "to current host (%(host)s).")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
190
191
192 class SourceHostUnavailable(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
193 message = _("Original compute host is unavailable at this time.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
194
195
196 class InvalidHypervisorType(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
197 message = _("The supplied hypervisor type of is invalid.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
198
199
200 class DestinationHypervisorTooOld(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
201 message = _("The instance requires a newer hypervisor version than "
202 "has been provided.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
203
204
205 class InvalidDevicePath(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
206 message = _("The supplied device path (%(path)s) is invalid.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
207
208
209 class InvalidCPUInfo(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
210 message = _("Unacceptable CPU info") + ": %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
211
212
213 class InvalidVLANTag(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
214 message = _("VLAN tag is not appropriate for the port group "
215 "%(bridge)s. Expected VLAN tag is %(tag)s, "
216 "but the one associated with the port group is %(pgroup)s.")
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
217
218
219 class InvalidVLANPortGroup(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
220 message = _("vSwitch which contains the port group %(bridge)s is "
221 "not associated with the desired physical adapter. "
222 "Expected vSwitch is %(expected)s, but the one associated "
223 "is %(actual)s.")
ad138a5 correcting tests; pep8
Brian Waldon authored
224
225
226 class ImageUnacceptable(Invalid):
9c6cbd4 moving dynamic i18n to static
Brian Waldon authored
227 message = _("Image %(image_id)s is unacceptable") + ": %(reason)s"
Something went wrong with that request. Please try again.