]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Moving api v1 implementation into v1 directory
authorMike Perez <thingee@gmail.com>
Fri, 9 Nov 2012 09:57:44 +0000 (01:57 -0800)
committerMike Perez <thingee@gmail.com>
Thu, 22 Nov 2012 05:26:40 +0000 (21:26 -0800)
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

22 files changed:
cinder/api/__init__.py
cinder/api/openstack/volume/__init__.py
cinder/api/openstack/volume/contrib/types_manage.py
cinder/api/v1/__init__.py [new file with mode: 0644]
cinder/api/v1/limits.py [moved from cinder/api/openstack/volume/limits.py with 100% similarity]
cinder/api/v1/router.py [new file with mode: 0644]
cinder/api/v1/snapshots.py [moved from cinder/api/openstack/volume/snapshots.py with 99% similarity]
cinder/api/v1/types.py [moved from cinder/api/openstack/volume/types.py with 100% similarity]
cinder/api/v1/volumes.py [moved from cinder/api/openstack/volume/volumes.py with 100% similarity]
cinder/flags.py
cinder/tests/api/openstack/fakes.py
cinder/tests/api/openstack/volume/contrib/test_admin_actions.py
cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py
cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py
cinder/tests/api/test_extensions.py
cinder/tests/api/test_router.py [moved from cinder/tests/api/openstack/volume/test_router.py with 95% similarity]
cinder/tests/api/v1/__init__.py [new file with mode: 0644]
cinder/tests/api/v1/test_limits.py [moved from cinder/tests/api/openstack/volume/test_limits.py with 99% similarity]
cinder/tests/api/v1/test_snapshots.py [moved from cinder/tests/api/openstack/volume/test_snapshots.py with 99% similarity]
cinder/tests/api/v1/test_types.py [moved from cinder/tests/api/openstack/volume/test_types.py with 99% similarity]
cinder/tests/api/v1/test_volumes.py [moved from cinder/tests/api/openstack/volume/test_volumes.py with 99% similarity]
etc/cinder/api-paste.ini

index 747015af53eba5da597f000022d99e7dce861a1a..fc348ac565903dbffc13793db0c64c098263cf76 100644 (file)
 #    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)
index b82fb8aba74738d3b4534a90a3010ac4795e489e..747015af53eba5da597f000022d99e7dce861a1a 100644 (file)
 #    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'])
index 4b0dabc0365892e863ccd9a37661867f4b6fbbf1..2e67c3539b7dcdbe13446406eac135bbcc1af26b 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/cinder/api/v1/router.py b/cinder/api/v1/router.py
new file mode 100644 (file)
index 0000000..bd56fb2
--- /dev/null
@@ -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'])
similarity index 99%
rename from cinder/api/openstack/volume/snapshots.py
rename to cinder/api/v1/snapshots.py
index 114b4e58c1deff330035e828beab75a83aae94d9..c44d63718305e0aaf79166a3e8dd27e038128589 100644 (file)
@@ -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
index b1a37b2abd9ef285126bfffaaba79b977f34cd3a..4b013c65035370b9199036371b776a360680e914 100644 (file)
@@ -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'),
index 87c2a61d3c3bb42385016b9e4b28be9284aa8310..f415c70cc7bdcaed06260dc33829d81a0046dd78 100644 (file)
@@ -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:
index 3494e62cfa55451d079eb1f982c1c3137a55ef8f..56c628b2a1dee6ebe7866a9ead3454901d6eadab 100644 (file)
@@ -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
index d32076ecc5e13ef6c4d8e529db010ca97da9c320..61e4cfe8939b7d0a70454ed1d352097545676732 100644 (file)
@@ -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
index 65a17d73d1b3ea8af44a266347060110c0954e55..300ccaf3a2a595b0f3945a3eef1306e65fec48f0 100644 (file)
@@ -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
index 7d998633fbee1e12e9debef1868bd6b5dac26d71..caad79db32eda8c32e9b9c71008fef6068d4fd60 100644 (file)
@@ -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)
similarity index 95%
rename from cinder/tests/api/openstack/volume/test_router.py
rename to cinder/tests/api/test_router.py
index c0fc754ab8d3eaef242b8a9751091fdab50f427d..f26e9220f58e1033a1d4ce956e19626df7991d1f 100644 (file)
 #    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 (file)
index 0000000..e69de29
similarity index 99%
rename from cinder/tests/api/openstack/volume/test_limits.py
rename to cinder/tests/api/v1/test_limits.py
index 6a83a08e4249ddb9daced7fd30013500441ba0e9..23dffd0d9f43ec41a37be2975fab899aebc48448 100644 (file)
@@ -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
similarity index 99%
rename from cinder/tests/api/openstack/volume/test_snapshots.py
rename to cinder/tests/api/v1/test_snapshots.py
index 6d115d8ea9e32878f05f01edb867903eb3aa8a70..4582ce4a05e448ead3f3da956b81f5530ffd00d5 100644 (file)
@@ -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
similarity index 99%
rename from cinder/tests/api/openstack/volume/test_types.py
rename to cinder/tests/api/v1/test_types.py
index 9f13b1ff6b003a8383d8549ddb30c4e4617f0c14..44361e9d7449675bd1dd853f4ad04fd12195f501 100644 (file)
@@ -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
similarity index 99%
rename from cinder/tests/api/openstack/volume/test_volumes.py
rename to cinder/tests/api/v1/test_volumes.py
index f717fc80e65808a83761cfa83d094b65baf2a79c..ebf5e1df82982122155da5aac903255e123107ca 100644 (file)
@@ -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
index c7c5baf7e90265675b86084a10ca591ab61d868b..8311cc114a35490361136ec624c949dbbda9af24 100644 (file)
@@ -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]