~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to nova/api/__init__.py

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import routes
24
24
import webob.dec
25
25
 
 
26
from nova import flags
26
27
from nova import wsgi
 
28
from nova.api import cloudpipe
27
29
from nova.api import ec2
28
30
from nova.api import rackspace
 
31
from nova.api.ec2 import metadatarequesthandler
 
32
 
 
33
 
 
34
flags.DEFINE_string('rsapi_subdomain', 'rs', 
 
35
                    'subdomain running the RS API')
 
36
flags.DEFINE_string('ec2api_subdomain', 'ec2', 
 
37
                    'subdomain running the EC2 API')
 
38
flags.DEFINE_string('FAKE_subdomain', None, 
 
39
                    'set to rs or ec2 to fake the subdomain of the host for testing')
 
40
FLAGS = flags.FLAGS
29
41
 
30
42
 
31
43
class API(wsgi.Router):
32
44
    """Routes top-level requests to the appropriate controller."""
33
45
 
34
46
    def __init__(self):
 
47
        rsdomain =  {'sub_domain': [FLAGS.rsapi_subdomain]}
 
48
        ec2domain = {'sub_domain': [FLAGS.ec2api_subdomain]}
 
49
        # If someone wants to pretend they're hitting the RS subdomain
 
50
        # on their local box, they can set FAKE_subdomain to 'rs', which
 
51
        # removes subdomain restrictions from the RS routes below.
 
52
        if FLAGS.FAKE_subdomain == 'rs':
 
53
            rsdomain = {}
 
54
        elif FLAGS.FAKE_subdomain == 'ec2':
 
55
            ec2domain = {}
35
56
        mapper = routes.Mapper()
36
 
        mapper.connect("/", controller=self.versions)
37
 
        mapper.connect("/v1.0/{path_info:.*}", controller=rackspace.API())
38
 
        mapper.connect("/services/{path_info:.*}", controller=ec2.API())
 
57
        mapper.sub_domains = True
 
58
        mapper.connect("/", controller=self.rsapi_versions, 
 
59
                            conditions=rsdomain)
 
60
        mapper.connect("/v1.0/{path_info:.*}", controller=rackspace.API(),
 
61
                            conditions=rsdomain)
 
62
 
 
63
        mapper.connect("/", controller=self.ec2api_versions,
 
64
                            conditions=ec2domain)
 
65
        mapper.connect("/services/{path_info:.*}", controller=ec2.API(),
 
66
                            conditions=ec2domain)
 
67
        mapper.connect("/cloudpipe/{path_info:.*}", controller=cloudpipe.API())
 
68
        mrh = metadatarequesthandler.MetadataRequestHandler()
 
69
        for s in ['/latest',
 
70
                  '/2009-04-04',
 
71
                  '/2008-09-01',
 
72
                  '/2008-02-01',
 
73
                  '/2007-12-15',
 
74
                  '/2007-10-10',
 
75
                  '/2007-08-29',
 
76
                  '/2007-03-01',
 
77
                  '/2007-01-19',
 
78
                  '/1.0']:
 
79
            mapper.connect('%s/{path_info:.*}' % s, controller=mrh,
 
80
                           conditions=ec2domain)
39
81
        super(API, self).__init__(mapper)
40
82
 
41
83
    @webob.dec.wsgify
42
 
    def versions(self, req):
 
84
    def rsapi_versions(self, req):
43
85
        """Respond to a request for all OpenStack API versions."""
44
86
        response = {
45
87
                "versions": [
48
90
            "application/xml": {
49
91
                "attributes": dict(version=["status", "id"])}}
50
92
        return wsgi.Serializer(req.environ, metadata).to_content_type(response)
 
93
 
 
94
    @webob.dec.wsgify
 
95
    def ec2api_versions(self, req):
 
96
        """Respond to a request for all EC2 versions."""
 
97
        # available api versions
 
98
        versions = [
 
99
            '1.0',
 
100
            '2007-01-19',
 
101
            '2007-03-01',
 
102
            '2007-08-29',
 
103
            '2007-10-10',
 
104
            '2007-12-15',
 
105
            '2008-02-01',
 
106
            '2008-09-01',
 
107
            '2009-04-04',
 
108
        ]
 
109
        return ''.join('%s\n' % v for v in versions)
 
110
 
 
111