14
14
XMLNS_V10 = 'http://docs.rackspacecloud.com/servers/api/v1.0'
15
15
XMLNS_V11 = 'http://docs.openstack.org/compute/api/v1.1'
16
XMLNS_ATOM = 'http://www.w3.org/2005/Atom'
17
18
LOG = logging.getLogger('nova.api.openstack.wsgi')
139
def find_first_child_named(self, parent, name):
140
"""Search a nodes children for the first child with a given name"""
141
for node in parent.childNodes:
142
if node.nodeName == name:
146
def find_children_named(self, parent, name):
147
"""Return all of a nodes children who have the given name"""
148
for node in parent.childNodes:
149
if node.nodeName == name:
152
def extract_text(self, node):
153
"""Get the text field contained by the given node"""
154
if len(node.childNodes) == 1:
155
child = node.childNodes[0]
156
if child.nodeType == child.TEXT_NODE:
157
return child.nodeValue
138
160
def default(self, datastring):
139
161
return {'body': self._from_xml(datastring)}
164
class MetadataXMLDeserializer(XMLDeserializer):
166
def extract_metadata(self, metadata_node):
167
"""Marshal the metadata attribute of a parsed request"""
168
if metadata_node is None:
171
for meta_node in self.find_children_named(metadata_node, "meta"):
172
key = meta_node.getAttribute("key")
173
metadata[key] = self.extract_text(meta_node)
142
177
class RequestHeadersDeserializer(ActionDispatcher):
143
178
"""Default request headers deserializer"""
397
432
def serialize_body(self, response, data, content_type, action):
398
433
response.headers['Content-Type'] = content_type
399
serializer = self.get_body_serializer(content_type)
400
response.body = serializer.serialize(data, action)
435
serializer = self.get_body_serializer(content_type)
436
response.body = serializer.serialize(data, action)
402
438
def get_body_serializer(self, content_type):
443
479
action, args, accept = self.deserializer.deserialize(request)
444
480
except exception.InvalidContentType:
445
481
msg = _("Unsupported Content-Type")
446
return webob.exc.HTTPBadRequest(explanation=msg)
482
return faults.Fault(webob.exc.HTTPBadRequest(explanation=msg))
447
483
except exception.MalformedRequestBody:
448
484
msg = _("Malformed request body")
449
485
return faults.Fault(webob.exc.HTTPBadRequest(explanation=msg))
454
490
LOG.info(_("HTTP exception thrown: %s"), unicode(ex))
455
491
action_result = faults.Fault(ex)
457
#TODO(bcwaldon): find a more elegant way to pass through non-dict types
458
493
if type(action_result) is dict or action_result is None:
459
494
response = self.serializer.serialize(action_result,