1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Citrix Systems.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
22
from quantum.api import api_common as common
23
from quantum.common import wsgi
26
class Fault(webob.exc.HTTPException):
27
"""Error codes for API faults"""
30
400: "malformedRequest",
32
420: "networkNotFound",
35
431: "requestedStateInvalid",
37
440: "alreadyAttached",
38
470: "serviceUnavailable",
42
def __init__(self, exception):
43
"""Create a Fault for the given webob.exc.exception."""
44
self.wrapped_exc = exception
46
@webob.dec.wsgify(RequestClass=wsgi.Request)
47
def __call__(self, req):
48
"""Generate a WSGI response based on the exception passed to ctor."""
49
# Replace the body with fault details.
50
code = self.wrapped_exc.status_int
51
fault_name = self._fault_names.get(code, "quantumServiceFault")
55
'message': self.wrapped_exc.explanation,
56
'detail': self.wrapped_exc.detail}}
57
# 'code' is an attribute on the fault tag itself
58
metadata = {'application/xml': {'attributes': {fault_name: 'code'}}}
59
default_xmlns = common.XML_NS_V10
60
serializer = wsgi.Serializer(metadata, default_xmlns)
61
content_type = req.best_match_content_type()
62
self.wrapped_exc.body = serializer.serialize(fault_data, content_type)
63
self.wrapped_exc.content_type = content_type
64
return self.wrapped_exc
67
class NetworkNotFound(webob.exc.HTTPClientError):
69
subclass of :class:`~HTTPClientError`
71
This indicates that the server did not find the network specified
74
code: 420, title: Network not Found
77
title = 'Network not Found'
78
explanation = ('Unable to find a network with the specified identifier.')
81
class NetworkInUse(webob.exc.HTTPClientError):
83
subclass of :class:`~HTTPClientError`
85
This indicates that the server could not delete the network as there is
86
at least an attachment plugged into its ports
88
code: 421, title: Network In Use
91
title = 'Network in Use'
92
explanation = ('Unable to remove the network: attachments still plugged.')
95
class PortNotFound(webob.exc.HTTPClientError):
97
subclass of :class:`~HTTPClientError`
99
This indicates that the server did not find the port specified
100
in the HTTP request for a given network
102
code: 430, title: Port not Found
105
title = 'Port not Found'
106
explanation = ('Unable to find a port with the specified identifier.')
109
class RequestedStateInvalid(webob.exc.HTTPClientError):
111
subclass of :class:`~HTTPClientError`
113
This indicates that the server could not update the port state to
116
code: 431, title: Requested State Invalid
119
title = 'Requested State Invalid'
120
explanation = ('Unable to update port state with specified value.')
123
class PortInUse(webob.exc.HTTPClientError):
125
subclass of :class:`~HTTPClientError`
127
This indicates that the server could not remove o port or attach
128
a resource to it because there is an attachment plugged into the port
130
code: 432, title: PortInUse
133
title = 'Port in Use'
134
explanation = ('A resource is currently attached to the logical port')
137
class AlreadyAttached(webob.exc.HTTPClientError):
139
subclass of :class:`~HTTPClientError`
141
This indicates that the server refused an attempt to re-attach a resource
142
already attached to the network
144
code: 440, title: AlreadyAttached
147
title = 'Already Attached'
148
explanation = ('The resource is already attached to another port')