Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 216 lines (140 sloc) 5.788 kb
bf6e6e7 Jesse Andrews 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 Vish Ishaya 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 Jesse Andrews 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 Jesse Andrews Merged Vish's work on adding projects to nova
anotherjesse authored
12 #
bf6e6e7 Jesse Andrews 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 Jesse Andrews initial commit
anotherjesse authored
18
19 """
9451872 Jesse Andrews Merged Vish's work on adding projects to nova
anotherjesse authored
20 Nova base exception handling, including decorator for re-raising
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
21 Nova-type exceptions. SHOULD include dedicated exception logging.
22 """
23
c7305af Todd Willey Apply logging changes as a giant patch to work around the cloudpipe dele...
xtoddx authored
24 from nova import log as logging
25 LOG = logging.getLogger('nova.exception')
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
26
d508418 Andy Smith rather comprehensive style fixes
termie authored
27
fc5e1c6 Vish Ishaya a few formatting fixes and moved exception
vishvananda authored
28 class ProcessExecutionError(IOError):
fa7d288 Sandy Walsh pep8
SandyWalsh authored
29
fc5e1c6 Vish Ishaya 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 Vish Ishaya a few formatting fixes and moved exception
vishvananda authored
34 if exit_code is None:
35 exit_code = '-'
68c9c89 Ed Leafe Completed first pass at converting all localized strings with multiple f...
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 Vish Ishaya a few formatting fixes and moved exception
vishvananda authored
39 IOError.__init__(self, message)
40
41
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
42 class Error(Exception):
fa7d288 Sandy Walsh pep8
SandyWalsh authored
43
9451872 Jesse Andrews Merged Vish's work on adding projects to nova
anotherjesse authored
44 def __init__(self, message=None):
45 super(Error, self).__init__(message)
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
46
d508418 Andy Smith rather comprehensive style fixes
termie authored
47
9451872 Jesse Andrews 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 Jesse Andrews initial commit
anotherjesse authored
50 self.message = message
51 self.code = code
e012a2b PEP8 and pylint cleanup. There should be no functional changes here, jus...
Eric Day authored
52 super(ApiError, self).__init__('%s: %s' % (code, message))
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
53
d508418 Andy Smith rather comprehensive style fixes
termie authored
54
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
55 class NotFound(Error):
56 pass
57
d508418 Andy Smith rather comprehensive style fixes
termie authored
58
9c35a9a Vish Ishaya 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 Jesse Andrews Merged Vish's work on adding projects to nova
anotherjesse authored
71 class Duplicate(Error):
72 pass
73
d508418 Andy Smith rather comprehensive style fixes
termie authored
74
bf6e6e7 Jesse Andrews initial commit
anotherjesse authored
75 class NotAuthorized(Error):
76 pass
77
d508418 Andy Smith 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 Andy Smith rather comprehensive style fixes
termie authored
82
28336ed Address a couple of the TODO's: We now have half-decent input validation...
Soren Hansen authored
83 class InvalidInputException(Error):
848aced Refactor wsgi.Serializer away from handling Requests directly; now requi...
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 validation...
Soren Hansen authored
88 pass
89
d508418 Andy Smith rather comprehensive style fixes
termie authored
90
e66f301 Ed Leafe Got the basic 'set admin password' stuff working
EdLeafe authored
91 class TimeoutException(Error):
92 pass
93
94
9bdcc71 Vish Ishaya 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 Jesse Andrews 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 Vish Ishaya trackback formatting isn't logging correctly
vishvananda authored
119 #exc_type, exc_value, exc_traceback = sys.exc_info()
c7305af Todd Willey Apply logging changes as a giant patch to work around the cloudpipe dele...
xtoddx authored
120 LOG.exception(_('Uncaught exception'))
3c8efde Vish Ishaya trackback formatting isn't logging correctly
vishvananda authored
121 #logging.error(traceback.extract_stack(exc_traceback))
bf6e6e7 Jesse Andrews 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):
129 message = ""
130
131 def __init__(self, **kwargs):
132 self._error_string = _(self.message) % kwargs
133
134 def __str__(self):
135 return self._error_string
136
137
138 #TODO: EOL this exception!
139 class Invalid(NovaException):
140 pass
141
142
143 class InstanceNotRunning(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
144 message = "Instance %(instance_id)s is not running."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
145
146
147 class InstanceNotSuspended(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
148 message = "Instance %(instance_id)s is not suspended."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
149
150
151 class InstanceSuspendFailure(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
152 message = "Failed to suspend instance: %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
153
154
155 class InstanceResumeFailure(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
156 message = "Failed to resume server: %(reason)s."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
157
158
159 class InstanceRebootFailure(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
160 message = "Failed to reboot instance: %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
161
162
163 class ServiceUnavailable(Invalid):
164 message = "Service is unavailable at this time."
165
166
167 class VolumeServiceUnavailable(ServiceUnavailable):
168 message = "Volume service is unavailable at this time."
169
170
171 class ComputeServiceUnavailable(ServiceUnavailable):
ad138a5 correcting tests; pep8
Brian Waldon authored
172 message = "Compute service is unavailable at this time."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
173
174
175 class UnableToMigrateToSelf(Invalid):
176 message = "Unable to migrate instance (%(instance_id)s) " \
177 "to current host (%(host)s."
178
179
180 class SourceHostUnavailable(Invalid):
181 message = "Original compute host is unavailable at this time."
182
183
184 class InvalidHypervisorType(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
185 message = "The supplied hypervisor type of is invalid."
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
186
187
188 class DestinationHypervisorTooOld(Invalid):
189 message = "The instance requires a newer hypervisor version than " \
190 "has been provided."
191
192
193 class InvalidDevicePath(Invalid):
194 message = "The supplied device path (%(path)s) is invalid."
195
196
197 class InvalidCPUInfo(Invalid):
ad138a5 correcting tests; pep8
Brian Waldon authored
198 message = "Unacceptable CPU info: %(reason)s"
4b07856 initial roundup of all 'exception.Invalid' cases
Brian Waldon authored
199
200
201 class InvalidVLANTag(Invalid):
202 message = "VLAN tag is not appropriate for the port group " \
203 "%(bridge)s. Expected VLAN tag is %(tag)s, " \
204 "but the one associated with the port group is %(pgroup)s."
205
206
207 class InvalidVLANPortGroup(Invalid):
208 message = "vSwitch which contains the port group %(bridge)s is " \
209 "not associated with the desired physical adapter. " \
210 "Expected vSwitch is %(expected)s, but the one associated " \
211 "is %(actual)s."
ad138a5 correcting tests; pep8
Brian Waldon authored
212
213
214 class ImageUnacceptable(Invalid):
215 message = "Image %(image_id)s is unacceptable: %(reason)s"
Something went wrong with that request. Please try again.