From: Mike Perez Date: Fri, 9 Nov 2012 09:57:44 +0000 (-0800) Subject: Moving api v1 implementation into v1 directory X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9009948b43109632bbeb0bcf234d6c48d005e926;p=openstack-build%2Fcinder-build.git Moving api v1 implementation into v1 directory Adjusts paste to use composite factory for routing properly to v1 and future api versions. Tests have been adjusted to match directory structure. progress on blueprint apiv2 Change-Id: I2cd3908705d224872b2d615cabe210fb1c453232 --- diff --git a/cinder/api/__init__.py b/cinder/api/__init__.py index 747015af5..fc348ac56 100644 --- a/cinder/api/__init__.py +++ b/cinder/api/__init__.py @@ -15,3 +15,18 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +import paste.urlmap + +from cinder import flags + + +FLAGS = flags.FLAGS + + +def root_app_factory(loader, global_conf, **local_conf): + if not FLAGS.enable_v1_api: + del local_conf['/v1'] + if not FLAGS.enable_v2_api: + del local_conf['/v2'] + return paste.urlmap.urlmap_factory(loader, global_conf, **local_conf) diff --git a/cinder/api/openstack/volume/__init__.py b/cinder/api/openstack/volume/__init__.py index b82fb8aba..747015af5 100644 --- a/cinder/api/openstack/volume/__init__.py +++ b/cinder/api/openstack/volume/__init__.py @@ -15,55 +15,3 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - -""" -WSGI middleware for OpenStack Volume API. -""" - -from cinder.api import extensions -import cinder.api.openstack -from cinder.api.openstack.volume import limits -from cinder.api.openstack.volume import snapshots -from cinder.api.openstack.volume import types -from cinder.api.openstack.volume import volumes -from cinder.api import versions -from cinder.openstack.common import log as logging - - -LOG = logging.getLogger(__name__) - - -class APIRouter(cinder.api.openstack.APIRouter): - """ - Routes requests on the OpenStack API to the appropriate controller - and method. - """ - ExtensionManager = extensions.ExtensionManager - - def _setup_routes(self, mapper, ext_mgr): - self.resources['versions'] = versions.create_resource() - mapper.connect("versions", "/", - controller=self.resources['versions'], - action='show') - - mapper.redirect("", "/") - - self.resources['volumes'] = volumes.create_resource(ext_mgr) - mapper.resource("volume", "volumes", - controller=self.resources['volumes'], - collection={'detail': 'GET'}, - member={'action': 'POST'}) - - self.resources['types'] = types.create_resource() - mapper.resource("type", "types", - controller=self.resources['types']) - - self.resources['snapshots'] = snapshots.create_resource(ext_mgr) - mapper.resource("snapshot", "snapshots", - controller=self.resources['snapshots'], - collection={'detail': 'GET'}, - member={'action': 'POST'}) - - self.resources['limits'] = limits.create_resource() - mapper.resource("limit", "limits", - controller=self.resources['limits']) diff --git a/cinder/api/openstack/volume/contrib/types_manage.py b/cinder/api/openstack/volume/contrib/types_manage.py index 4b0dabc03..2e67c3539 100644 --- a/cinder/api/openstack/volume/contrib/types_manage.py +++ b/cinder/api/openstack/volume/contrib/types_manage.py @@ -20,8 +20,8 @@ import webob from cinder.api import extensions -from cinder.api.openstack.volume import types from cinder.api.openstack import wsgi +from cinder.api.v1 import types from cinder.api.views import types as views_types from cinder import exception from cinder.volume import volume_types diff --git a/cinder/api/v1/__init__.py b/cinder/api/v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cinder/api/openstack/volume/limits.py b/cinder/api/v1/limits.py similarity index 100% rename from cinder/api/openstack/volume/limits.py rename to cinder/api/v1/limits.py diff --git a/cinder/api/v1/router.py b/cinder/api/v1/router.py new file mode 100644 index 000000000..bd56fb2f6 --- /dev/null +++ b/cinder/api/v1/router.py @@ -0,0 +1,70 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# Copyright 2011 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +WSGI middleware for OpenStack Volume API. +""" + +from cinder.api import extensions +import cinder.api.openstack +from cinder.api.v1 import limits +from cinder.api.v1 import snapshots +from cinder.api.v1 import types +from cinder.api.v1 import volumes +from cinder.api import versions +from cinder.openstack.common import log as logging + + +LOG = logging.getLogger(__name__) + + +class APIRouter(cinder.api.openstack.APIRouter): + """ + Routes requests on the OpenStack API to the appropriate controller + and method. + """ + ExtensionManager = extensions.ExtensionManager + + def _setup_routes(self, mapper, ext_mgr): + self.resources['versions'] = versions.create_resource() + mapper.connect("versions", "/", + controller=self.resources['versions'], + action='show') + + mapper.redirect("", "/") + + self.resources['volumes'] = volumes.create_resource(ext_mgr) + mapper.resource("volume", "volumes", + controller=self.resources['volumes'], + collection={'detail': 'GET'}, + member={'action': 'POST'}) + + self.resources['types'] = types.create_resource() + mapper.resource("type", "types", + controller=self.resources['types']) + + self.resources['snapshots'] = snapshots.create_resource(ext_mgr) + mapper.resource("snapshot", "snapshots", + controller=self.resources['snapshots'], + collection={'detail': 'GET'}, + member={'action': 'POST'}) + + self.resources['limits'] = limits.create_resource() + mapper.resource("limit", "limits", + controller=self.resources['limits']) diff --git a/cinder/api/openstack/volume/snapshots.py b/cinder/api/v1/snapshots.py similarity index 99% rename from cinder/api/openstack/volume/snapshots.py rename to cinder/api/v1/snapshots.py index 114b4e58c..c44d63718 100644 --- a/cinder/api/openstack/volume/snapshots.py +++ b/cinder/api/v1/snapshots.py @@ -19,8 +19,8 @@ import webob from webob import exc from cinder.api import common -from cinder.api.openstack.volume import volumes from cinder.api.openstack import wsgi +from cinder.api.v1 import volumes from cinder.api import xmlutil from cinder import exception from cinder import flags diff --git a/cinder/api/openstack/volume/types.py b/cinder/api/v1/types.py similarity index 100% rename from cinder/api/openstack/volume/types.py rename to cinder/api/v1/types.py diff --git a/cinder/api/openstack/volume/volumes.py b/cinder/api/v1/volumes.py similarity index 100% rename from cinder/api/openstack/volume/volumes.py rename to cinder/api/v1/volumes.py diff --git a/cinder/flags.py b/cinder/flags.py index b1a37b2ab..4b013c650 100644 --- a/cinder/flags.py +++ b/cinder/flags.py @@ -130,6 +130,10 @@ global_opts = [ cfg.StrOpt('volume_topic', default='cinder-volume', help='the topic volume nodes listen on'), + cfg.BoolOpt('enable_v1_api', default=True, + help=_("Deploy v1 of the Cinder API")), + cfg.BoolOpt('enable_v2_api', default=True, + help=_("Deploy v2 of the Cinder API")), cfg.BoolOpt('api_rate_limit', default=True, help='whether to rate limit the api'), diff --git a/cinder/tests/api/openstack/fakes.py b/cinder/tests/api/openstack/fakes.py index 87c2a61d3..f415c70cc 100644 --- a/cinder/tests/api/openstack/fakes.py +++ b/cinder/tests/api/openstack/fakes.py @@ -25,10 +25,10 @@ import webob.request from cinder.api.middleware import auth from cinder.api.middleware import fault -from cinder.api.openstack import volume -from cinder.api.openstack.volume import limits from cinder.api.openstack import wsgi as os_wsgi from cinder.api import urlmap +from cinder.api.v1 import limits +from cinder.api.v1 import router from cinder.api import versions from cinder import context from cinder import exception as exc @@ -64,7 +64,7 @@ def fake_wsgi(self, req): def wsgi_app(inner_app_v1=None, fake_auth=True, fake_auth_context=None, use_no_auth=False, ext_mgr=None): if not inner_app_v1: - inner_app_v1 = volume.APIRouter(ext_mgr) + inner_app_v1 = router.APIRouter(ext_mgr) if fake_auth: if fake_auth_context is not None: diff --git a/cinder/tests/api/openstack/volume/contrib/test_admin_actions.py b/cinder/tests/api/openstack/volume/contrib/test_admin_actions.py index 3494e62cf..56c628b2a 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_admin_actions.py +++ b/cinder/tests/api/openstack/volume/contrib/test_admin_actions.py @@ -11,7 +11,7 @@ from cinder.volume import api as volume_api def app(): # no auth, just let environ['cinder.context'] pass through - api = fakes.volume.APIRouter() + api = fakes.router.APIRouter() mapper = fakes.urlmap.URLMap() mapper['/v1'] = api return mapper diff --git a/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py b/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py index d32076ecc..61e4cfe89 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py +++ b/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py @@ -50,7 +50,7 @@ def fake_volume_get_all(*args, **kwargs): def app(): # no auth, just let environ['cinder.context'] pass through - api = fakes.volume.APIRouter() + api = fakes.router.APIRouter() mapper = fakes.urlmap.URLMap() mapper['/v1'] = api return mapper diff --git a/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py b/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py index 65a17d73d..300ccaf3a 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py +++ b/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py @@ -53,7 +53,7 @@ def fake_volume_get_all(*args, **kwargs): def app(): # no auth, just let environ['cinder.context'] pass through - api = fakes.volume.APIRouter() + api = fakes.router.APIRouter() mapper = fakes.urlmap.URLMap() mapper['/v1'] = api return mapper diff --git a/cinder/tests/api/test_extensions.py b/cinder/tests/api/test_extensions.py index 7d998633f..caad79db3 100644 --- a/cinder/tests/api/test_extensions.py +++ b/cinder/tests/api/test_extensions.py @@ -20,7 +20,7 @@ import iso8601 from lxml import etree import webob -from cinder.api.openstack import volume +from cinder.api.v1 import router from cinder.api import xmlutil from cinder import flags from cinder.openstack.common import jsonutils @@ -51,7 +51,7 @@ class ExtensionControllerTest(ExtensionTestCase): self.ext_list.sort() def test_list_extensions_json(self): - app = volume.APIRouter() + app = router.APIRouter() request = webob.Request.blank("/fake/extensions") response = request.get_response(app) self.assertEqual(200, response.status_int) @@ -88,7 +88,7 @@ class ExtensionControllerTest(ExtensionTestCase): self.assertEqual(output['extension']['alias'], ext['alias']) def test_get_extension_json(self): - app = volume.APIRouter() + app = router.APIRouter() request = webob.Request.blank("/fake/extensions/FOXNSOX") response = request.get_response(app) self.assertEqual(200, response.status_int) @@ -103,13 +103,13 @@ class ExtensionControllerTest(ExtensionTestCase): "links": []}) def test_get_non_existing_extension_json(self): - app = volume.APIRouter() + app = router.APIRouter() request = webob.Request.blank("/fake/extensions/4") response = request.get_response(app) self.assertEqual(404, response.status_int) def test_list_extensions_xml(self): - app = volume.APIRouter() + app = router.APIRouter() request = webob.Request.blank("/fake/extensions") request.accept = "application/xml" response = request.get_response(app) @@ -134,7 +134,7 @@ class ExtensionControllerTest(ExtensionTestCase): xmlutil.validate_schema(root, 'extensions') def test_get_extension_xml(self): - app = volume.APIRouter() + app = router.APIRouter() request = webob.Request.blank("/fake/extensions/FOXNSOX") request.accept = "application/xml" response = request.get_response(app) diff --git a/cinder/tests/api/openstack/volume/test_router.py b/cinder/tests/api/test_router.py similarity index 95% rename from cinder/tests/api/openstack/volume/test_router.py rename to cinder/tests/api/test_router.py index c0fc754ab..f26e9220f 100644 --- a/cinder/tests/api/openstack/volume/test_router.py +++ b/cinder/tests/api/test_router.py @@ -14,10 +14,10 @@ # under the License. -from cinder.api.openstack import volume -from cinder.api.openstack.volume import snapshots -from cinder.api.openstack.volume import volumes from cinder.api.openstack import wsgi +from cinder.api.v1 import router +from cinder.api.v1 import snapshots +from cinder.api.v1 import volumes from cinder.api import versions from cinder import flags from cinder.openstack.common import log as logging @@ -50,7 +50,7 @@ class VolumeRouterTestCase(test.TestCase): # NOTE(vish): versions is just returning text so, no need to stub. self.stubs.Set(snapshots, 'create_resource', create_resource) self.stubs.Set(volumes, 'create_resource', create_resource) - self.app = volume.APIRouter() + self.app = router.APIRouter() def test_versions(self): req = fakes.HTTPRequest.blank('') diff --git a/cinder/tests/api/v1/__init__.py b/cinder/tests/api/v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cinder/tests/api/openstack/volume/test_limits.py b/cinder/tests/api/v1/test_limits.py similarity index 99% rename from cinder/tests/api/openstack/volume/test_limits.py rename to cinder/tests/api/v1/test_limits.py index 6a83a08e4..23dffd0d9 100644 --- a/cinder/tests/api/openstack/volume/test_limits.py +++ b/cinder/tests/api/v1/test_limits.py @@ -24,7 +24,7 @@ from xml.dom import minidom from lxml import etree import webob -from cinder.api.openstack.volume import limits +from cinder.api.v1 import limits from cinder.api import views from cinder.api import xmlutil import cinder.context diff --git a/cinder/tests/api/openstack/volume/test_snapshots.py b/cinder/tests/api/v1/test_snapshots.py similarity index 99% rename from cinder/tests/api/openstack/volume/test_snapshots.py rename to cinder/tests/api/v1/test_snapshots.py index 6d115d8ea..4582ce4a0 100644 --- a/cinder/tests/api/openstack/volume/test_snapshots.py +++ b/cinder/tests/api/v1/test_snapshots.py @@ -18,7 +18,7 @@ import datetime from lxml import etree import webob -from cinder.api.openstack.volume import snapshots +from cinder.api.v1 import snapshots from cinder import db from cinder import exception from cinder import flags diff --git a/cinder/tests/api/openstack/volume/test_types.py b/cinder/tests/api/v1/test_types.py similarity index 99% rename from cinder/tests/api/openstack/volume/test_types.py rename to cinder/tests/api/v1/test_types.py index 9f13b1ff6..44361e9d7 100644 --- a/cinder/tests/api/openstack/volume/test_types.py +++ b/cinder/tests/api/v1/test_types.py @@ -16,7 +16,7 @@ from lxml import etree import webob -from cinder.api.openstack.volume import types +from cinder.api.v1 import types from cinder.api.views import types as views_types from cinder import exception from cinder.openstack.common import timeutils diff --git a/cinder/tests/api/openstack/volume/test_volumes.py b/cinder/tests/api/v1/test_volumes.py similarity index 99% rename from cinder/tests/api/openstack/volume/test_volumes.py rename to cinder/tests/api/v1/test_volumes.py index f717fc80e..ebf5e1df8 100644 --- a/cinder/tests/api/openstack/volume/test_volumes.py +++ b/cinder/tests/api/v1/test_volumes.py @@ -18,8 +18,8 @@ import datetime from lxml import etree import webob -from cinder.api.openstack.volume import extensions -from cinder.api.openstack.volume import volumes +from cinder.api import extensions +from cinder.api.v1 import volumes from cinder import context from cinder import db from cinder import exception diff --git a/etc/cinder/api-paste.ini b/etc/cinder/api-paste.ini index c7c5baf7e..8311cc114 100644 --- a/etc/cinder/api-paste.ini +++ b/etc/cinder/api-paste.ini @@ -3,15 +3,15 @@ ############# [composite:osapi_volume] -use = call:cinder.api.urlmap:urlmap_factory -/: osvolumeversions +use = call:cinder.api:root_app_factory +/: apiversions /v1: openstack_volume_api_v1 [composite:openstack_volume_api_v1] use = call:cinder.api.middleware.auth:pipeline_factory -noauth = faultwrap sizelimit noauth osapi_volume_app_v1 -keystone = faultwrap sizelimit authtoken keystonecontext osapi_volume_app_v1 -keystone_nolimit = faultwrap sizelimit authtoken keystonecontext osapi_volume_app_v1 +noauth = faultwrap sizelimit noauth apiv1 +keystone = faultwrap sizelimit authtoken keystonecontext apiv1 +keystone_nolimit = faultwrap sizelimit authtoken keystonecontext apiv1 [filter:faultwrap] paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory @@ -22,10 +22,10 @@ paste.filter_factory = cinder.api.middleware.auth:NoAuthMiddleware.factory [filter:sizelimit] paste.filter_factory = cinder.api.middleware.sizelimit:RequestBodySizeLimiter.factory -[app:osapi_volume_app_v1] -paste.app_factory = cinder.api.openstack.volume:APIRouter.factory +[app:apiv1] +paste.app_factory = cinder.api.v1.router:APIRouter.factory -[pipeline:osvolumeversions] +[pipeline:apiversions] pipeline = faultwrap osvolumeversionapp [app:osvolumeversionapp]