~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to nova/api/openstack/wsgi.py

  • Committer: Lvov Maxim
  • Date: 2011-07-26 05:50:05 UTC
  • mfrom: (1320 nova)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: usrleon@gmail.com-20110726055005-7olsp0giqup3pao7
merge with trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
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'
16
17
 
17
18
LOG = logging.getLogger('nova.api.openstack.wsgi')
18
19
 
135
136
                                                                 listnames)
136
137
            return result
137
138
 
 
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:
 
143
                return node
 
144
        return None
 
145
 
 
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:
 
150
                yield node
 
151
 
 
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
 
158
        return ""
 
159
 
138
160
    def default(self, datastring):
139
161
        return {'body': self._from_xml(datastring)}
140
162
 
141
163
 
 
164
class MetadataXMLDeserializer(XMLDeserializer):
 
165
 
 
166
    def extract_metadata(self, metadata_node):
 
167
        """Marshal the metadata attribute of a parsed request"""
 
168
        if metadata_node is None:
 
169
            return None
 
170
        metadata = {}
 
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)
 
174
        return metadata
 
175
 
 
176
 
142
177
class RequestHeadersDeserializer(ActionDispatcher):
143
178
    """Default request headers deserializer"""
144
179
 
396
431
 
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)
 
434
        if data is not None:
 
435
            serializer = self.get_body_serializer(content_type)
 
436
            response.body = serializer.serialize(data, action)
401
437
 
402
438
    def get_body_serializer(self, content_type):
403
439
        try:
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)
456
492
 
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,
460
495
                                                 accept,