]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add extensions listing to the controller
authorKevin Benton <blak111@gmail.com>
Thu, 11 Jun 2015 14:32:44 +0000 (07:32 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Sat, 1 Aug 2015 18:57:38 +0000 (18:57 +0000)
Extensions aren't like normal resources handled by the
core plugin or a service plugin so they need special code
to handle them. The resource identifier hook also had to
be tweaked to let the request slip through without having
an entry in the attributes map.

Change-Id: I5f42bdd7aa3c103b2ff3550ce1b0d9a3baf35a35
Co-Authored-By: Brandon Logan <brandon.logan@rackspace.com>
Partially-Implements: blueprint wsgi-pecan-switch

neutron/api/extensions.py
neutron/newapi/controllers/root.py
neutron/newapi/hooks/resource_identifier.py
neutron/tests/functional/newapi/test_functional.py

index 8eb0f9070c9937fba25a6f173950dfc313bd6f39..27b8a0d4dcb0a1593baff422e1c25229060c3488 100644 (file)
@@ -208,7 +208,8 @@ class ExtensionController(wsgi.Controller):
     def __init__(self, extension_manager):
         self.extension_manager = extension_manager
 
-    def _translate(self, ext):
+    @staticmethod
+    def _translate(ext):
         ext_data = {}
         ext_data['name'] = ext.get_name()
         ext_data['alias'] = ext.get_alias()
index 221755f943b7630dfd069a56fd1e32cd6eb2c27c..4185080f5c4fe9443993dbbea3408e08d4856216 100644 (file)
@@ -16,6 +16,8 @@
 
 import pecan
 
+from neutron.api import extensions
+
 
 def expose(*args, **kwargs):
     """Helper function so we don't have to specify json for everything."""
@@ -48,9 +50,41 @@ class V2Controller(object):
 
     @expose()
     def _lookup(self, endpoint, *remainder):
+        if endpoint == 'extensions':
+            return ExtensionsController(), remainder
         return GeneralController(endpoint), remainder
 
 
+class ExtensionsController(object):
+
+    @expose()
+    def _lookup(self, alias, *remainder):
+        return ExtensionController(alias), remainder
+
+    @expose()
+    def index(self):
+        ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
+        exts = [extensions.ExtensionController._translate(ext)
+                for ext in ext_mgr.extensions.values()]
+        return {'extensions': exts}
+
+
+class ExtensionController(object):
+
+    def __init__(self, alias):
+        self.alias = alias
+
+    @expose()
+    def index(self):
+        ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
+        ext = ext_mgr.extensions.get(self.alias, None)
+        if not ext:
+            pecan.abort(
+                404, detail=_("Extension with alias %s "
+                              "does not exist") % self.alias)
+        return {'extension': extensions.ExtensionController._translate(ext)}
+
+
 class GeneralController(object):
 
     def __init__(self, token):
index 5b6f1badea1f3ac78b689e51637517c307751818..91000f4f0dda80b701524e76eba86d1b14eb0e80 100644 (file)
@@ -35,7 +35,8 @@ class ResourceIdentifierHook(hooks.PecanHook):
             url_type = state.request.path.split('/')[2].rsplit('.', 1)[0]
         except IndexError:
             return
-
+        if url_type == 'extensions':
+            return
         for plural, single in attributes.PLURALS.items():
             if plural == url_type:
                 state.request.resource_type = single
index bc7089c8d43aa1b5b4a4f009b748339668aae0c8..e4e4506d2aae7943d9eef23119e16c0360514d1b 100644 (file)
@@ -91,6 +91,14 @@ class TestV2Controller(PecanFunctionalTest):
     def test_plugin_initialized(self):
         self.assertIsNotNone(manager.NeutronManager._instance)
 
+    def test_get_extensions(self):
+        response = self.app.get('/v2.0/extensions.json')
+        self.assertEqual(response.status_int, 200)
+
+    def test_get_specific_extension(self):
+        response = self.app.get('/v2.0/extensions/allowed-address-pairs.json')
+        self.assertEqual(response.status_int, 200)
+
 
 class TestErrors(PecanFunctionalTest):