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
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')
31
43
class API(wsgi.Router):
32
44
"""Routes top-level requests to the appropriate controller."""
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':
54
elif FLAGS.FAKE_subdomain == 'ec2':
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,
60
mapper.connect("/v1.0/{path_info:.*}", controller=rackspace.API(),
63
mapper.connect("/", controller=self.ec2api_versions,
65
mapper.connect("/services/{path_info:.*}", controller=ec2.API(),
67
mapper.connect("/cloudpipe/{path_info:.*}", controller=cloudpipe.API())
68
mrh = metadatarequesthandler.MetadataRequestHandler()
79
mapper.connect('%s/{path_info:.*}' % s, controller=mrh,
39
81
super(API, self).__init__(mapper)
42
def versions(self, req):
84
def rsapi_versions(self, req):
43
85
"""Respond to a request for all OpenStack API versions."""
48
90
"application/xml": {
49
91
"attributes": dict(version=["status", "id"])}}
50
92
return wsgi.Serializer(req.environ, metadata).to_content_type(response)
95
def ec2api_versions(self, req):
96
"""Respond to a request for all EC2 versions."""
97
# available api versions
109
return ''.join('%s\n' % v for v in versions)