~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/api/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-01-21 11:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110121114806-v8fvnnl6az4m4ohv
Tags: upstream-2011.1~bzr597
ImportĀ upstreamĀ versionĀ 2011.1~bzr597

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
16
#    License for the specific language governing permissions and limitations
17
17
#    under the License.
18
 
"""
19
 
Root WSGI middleware for all API controllers.
20
 
 
21
 
**Related Flags**
22
 
 
23
 
:osapi_subdomain:  subdomain running the OpenStack API (default: api)
24
 
:ec2api_subdomain:  subdomain running the EC2 API (default: ec2)
25
 
 
26
 
"""
27
 
 
28
 
import routes
29
 
import webob.dec
30
 
 
31
 
from nova import flags
32
 
from nova import utils
33
 
from nova import wsgi
34
 
from nova.api import cloudpipe
35
 
from nova.api import ec2
36
 
from nova.api import openstack
37
 
from nova.api.ec2 import metadatarequesthandler
38
 
 
39
 
 
40
 
flags.DEFINE_string('osapi_subdomain', 'api',
41
 
                    'subdomain running the OpenStack API')
42
 
flags.DEFINE_string('ec2api_subdomain', 'ec2',
43
 
                    'subdomain running the EC2 API')
44
 
FLAGS = flags.FLAGS
45
 
 
46
 
 
47
 
class API(wsgi.Router):
48
 
    """Routes top-level requests to the appropriate controller."""
49
 
 
50
 
    def __init__(self, default_api):
51
 
        osapi_subdomain = {'sub_domain': [FLAGS.osapi_subdomain]}
52
 
        ec2api_subdomain = {'sub_domain': [FLAGS.ec2api_subdomain]}
53
 
        if default_api == 'os':
54
 
            osapi_subdomain = {}
55
 
        elif default_api == 'ec2':
56
 
            ec2api_subdomain = {}
57
 
        mapper = routes.Mapper()
58
 
        mapper.sub_domains = True
59
 
 
60
 
        mapper.connect("/", controller=self.osapi_versions,
61
 
                       conditions=osapi_subdomain)
62
 
        mapper.connect("/v1.0/{path_info:.*}", controller=openstack.API(),
63
 
                       conditions=osapi_subdomain)
64
 
 
65
 
        mapper.connect("/", controller=self.ec2api_versions,
66
 
                       conditions=ec2api_subdomain)
67
 
        mapper.connect("/services/{path_info:.*}", controller=ec2.API(),
68
 
                       conditions=ec2api_subdomain)
69
 
        mrh = metadatarequesthandler.MetadataRequestHandler()
70
 
        for s in ['/latest',
71
 
                  '/2009-04-04',
72
 
                  '/2008-09-01',
73
 
                  '/2008-02-01',
74
 
                  '/2007-12-15',
75
 
                  '/2007-10-10',
76
 
                  '/2007-08-29',
77
 
                  '/2007-03-01',
78
 
                  '/2007-01-19',
79
 
                  '/1.0']:
80
 
            mapper.connect('%s/{path_info:.*}' % s, controller=mrh,
81
 
                           conditions=ec2api_subdomain)
82
 
 
83
 
        mapper.connect("/cloudpipe/{path_info:.*}", controller=cloudpipe.API())
84
 
        super(API, self).__init__(mapper)
85
 
 
86
 
    @webob.dec.wsgify
87
 
    def osapi_versions(self, req):
88
 
        """Respond to a request for all OpenStack API versions."""
89
 
        response = {
90
 
                "versions": [
91
 
                    dict(status="CURRENT", id="v1.0")]}
92
 
        metadata = {
93
 
            "application/xml": {
94
 
                "attributes": dict(version=["status", "id"])}}
95
 
        return wsgi.Serializer(req.environ, metadata).to_content_type(response)
96
 
 
97
 
    @webob.dec.wsgify
98
 
    def ec2api_versions(self, req):
99
 
        """Respond to a request for all EC2 versions."""
100
 
        # available api versions
101
 
        versions = [
102
 
            '1.0',
103
 
            '2007-01-19',
104
 
            '2007-03-01',
105
 
            '2007-08-29',
106
 
            '2007-10-10',
107
 
            '2007-12-15',
108
 
            '2008-02-01',
109
 
            '2008-09-01',
110
 
            '2009-04-04',
111
 
        ]
112
 
        return ''.join('%s\n' % v for v in versions)
 
18
 
 
19
"""No-op __init__ for directory full of api goodies."""