~rackspace-ozone/rackspace-nova/development

« back to all changes in this revision

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

  • Committer: paul at openstack
  • Date: 2011-09-26 18:57:03 UTC
  • mfrom: (1098.1.519 nova)
  • Revision ID: paul@openstack.org-20110926185703-ad3bthrj309itbrw
merging Diablo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
1
17
 
2
18
import json
3
19
from lxml import etree
19
35
 
20
36
LOG = logging.getLogger('nova.api.openstack.wsgi')
21
37
 
 
38
# The vendor content types should serialize identically to the non-vendor
 
39
# content types. So to avoid littering the code with both options, we
 
40
# map the vendor to the other when looking up the type
 
41
_CONTENT_TYPE_MAP = {
 
42
    'application/vnd.openstack.compute+json': 'application/json',
 
43
    'application/vnd.openstack.compute+xml': 'application/xml',
 
44
}
 
45
 
 
46
_SUPPORTED_CONTENT_TYPES = (
 
47
    'application/json',
 
48
    'application/vnd.openstack.compute+json',
 
49
    'application/xml',
 
50
    'application/vnd.openstack.compute+xml',
 
51
)
 
52
 
22
53
 
23
54
class Request(webob.Request):
24
55
    """Add some Openstack API-specific logic to the base webob.Request."""
30
61
 
31
62
        """
32
63
        supported_content_types = supported_content_types or \
33
 
            ('application/json', 'application/xml')
 
64
            _SUPPORTED_CONTENT_TYPES
34
65
 
35
66
        parts = self.path.rsplit('.', 1)
36
67
        if len(parts) > 1:
52
83
        if not "Content-Type" in self.headers:
53
84
            return None
54
85
 
55
 
        allowed_types = ("application/xml", "application/json")
 
86
        allowed_types = _SUPPORTED_CONTENT_TYPES
56
87
        content_type = self.content_type
57
88
 
58
89
        if content_type not in allowed_types:
192
223
                 supported_content_types=None):
193
224
 
194
225
        self.supported_content_types = supported_content_types or \
195
 
                ('application/json', 'application/xml')
 
226
                _SUPPORTED_CONTENT_TYPES
196
227
 
197
228
        self.body_deserializers = {
198
229
            'application/xml': XMLDeserializer(),
250
281
 
251
282
    def get_body_deserializer(self, content_type):
252
283
        try:
253
 
            return self.body_deserializers[content_type]
 
284
            ctype = _CONTENT_TYPE_MAP.get(content_type, content_type)
 
285
            return self.body_deserializers[ctype]
254
286
        except (KeyError, TypeError):
255
287
            raise exception.InvalidContentType(content_type=content_type)
256
288
 
316
348
 
317
349
    def to_xml_string(self, node, has_atom=False):
318
350
        self._add_xmlns(node, has_atom)
319
 
        return node.toprettyxml(indent='    ', encoding='UTF-8')
 
351
        return node.toxml('UTF-8')
320
352
 
321
353
    #NOTE (ameade): the has_atom should be removed after all of the
322
354
    # xml serializers and view builders have been updated to the current
444
476
 
445
477
    def get_body_serializer(self, content_type):
446
478
        try:
447
 
            return self.body_serializers[content_type]
 
479
            ctype = _CONTENT_TYPE_MAP.get(content_type, content_type)
 
480
            return self.body_serializers[ctype]
448
481
        except (KeyError, TypeError):
449
482
            raise exception.InvalidContentType(content_type=content_type)
450
483