]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Rajaram/Santhosh|Added plugin interface in foxinsox and Updated README
authorRajaram Mallya <rajarammallya@gmail.com>
Tue, 26 Jul 2011 05:27:24 +0000 (10:57 +0530)
committerRajaram Mallya <rajarammallya@gmail.com>
Tue, 26 Jul 2011 05:27:24 +0000 (10:57 +0530)
README
quantum/common/extensions.py
quantum/plugins/SamplePlugin.py
tests/unit/extensions/foxinsocks.py
tests/unit/test_extensions.py

diff --git a/README b/README
index f3e973faacd002e0c4632a733191c7e74ce5f388..5c59970840e8cb672b09069eac94d28f0e01b1b8 100644 (file)
--- a/README
+++ b/README
@@ -105,4 +105,29 @@ There are a few requirements to writing your own plugin:
 4) Launch the Quantum Service, and your plug-in is configured and ready to
    manage a Cloud Networking Fabric.
 
-
+# -- Extensions
+
+1) Creating Extensions:
+   An example extension exists in ./tests/unit/extensions/foxinsocks.py
+   The unit tests in ./tests/unit/test_extensions.py document the complete
+   set of extension features supported
+2) Loading Extension: 
+   a) The extension file should have a class with same name as the filename. 
+      This class should implement the contract required by the extension framework. 
+      See ExtensionDescriptor class in ./quantum/common/extensions.py for details
+      For an example look at Foxinsocks class in foxinsocks.py
+   b) The extension file should be deployed in the ./extensions folder. 
+      If the filename starts with an "_", it will not be treated as an extension.
+3) Plugins advertizing extension support:
+   A Plugin can advertize all the extensions it supports through the 
+   'supported_extension_aliases' attribute. Eg:
+   class SomePlugin:
+      ...
+      supported_extension_aliases = ['extension1_alias', 
+                                     'extension2_alias',
+                                     'extension3_alias']
+4) Standardizing extensions:
+  An extension might be supported by multiple plugins. In such cases, the extension
+  can mandate an interface that all plugins have to support for that extension.
+  For an example see the FoxInSocksPluginInterface in foxinsocks.py and the QuantumEchoPlugin
index 79d3cfb153e6f79e5e8b8e632730315d9b25d8af..485fbc2a5ae2c5796770cbefc7d3f45562a88746 100644 (file)
@@ -24,7 +24,7 @@ import logging
 import webob.dec
 import webob.exc
 from gettext import gettext as _
-from abc import ABCMeta, abstractmethod
+from abc import ABCMeta
 
 from quantum.manager import QuantumManager
 from quantum.common import exceptions
index ff08bb370100c094ecfa6e20e50e7cef5bec7aee..68cd8e54e7ed646f8ecda38025aeef049d00d45f 100644 (file)
@@ -119,6 +119,11 @@ class QuantumEchoPlugin(object):
         """
         print("unplug_interface() called\n")
 
+    supported_extension_aliases = ["FOXNSOX"]
+
+    def method_to_support_foxnsox_extension(self):
+        print("method_to_support_foxnsox_extension() called\n")
+
 
 class DummyDataPlugin(object):
 
@@ -237,8 +242,6 @@ class FakePlugin(object):
         db.configure_db({'sql_connection': 'sqlite:///:memory:'})
         FakePlugin._net_counter = 0
 
-    supported_extension_aliases = ["FOXNSOX"]
-
     def _get_network(self, tenant_id, network_id):
         try:
             network = db.network_get(network_id)
index 2c224af8292b5f72d6caa719695f480a65d6f86d..5bdefde95fda3e926b8ca9d9092eb77688bd6bcf 100644 (file)
@@ -19,6 +19,7 @@ import json
 
 from quantum.common import wsgi
 from quantum.common import extensions
+from abc import  abstractmethod
 
 
 class FoxInSocksController(wsgi.Controller):
@@ -27,11 +28,21 @@ class FoxInSocksController(wsgi.Controller):
         return "Try to say this Mr. Knox, sir..."
 
 
+class FoxInSocksPluginInterface(extensions.PluginInterface):
+
+    @abstractmethod
+    def method_to_support_foxnsox_extension(self):
+        pass
+
+
 class Foxinsocks(object):
 
     def __init__(self):
         pass
 
+    def get_plugin_interface(self):
+        return FoxInSocksPluginInterface
+
     def get_name(self):
         return "Fox In Socks"
 
index 0478e3a3775a884861daa3ea39900e54fdc19428..9772f89e9ffc0b4f9c53437bc9d5028882485bea 100644 (file)
@@ -27,11 +27,11 @@ from quantum.common import config
 from quantum.common.extensions import (ExtensionManager,
                                        PluginAwareExtensionManager,
                                        ExtensionMiddleware)
+from quantum.plugins.SamplePlugin import QuantumEchoPlugin
 
 test_conf_file = os.path.join(os.path.dirname(__file__), os.pardir,
                               os.pardir, 'etc', 'quantum.conf.test')
-
-plugin_options = {'plugin_provider': "quantum.plugins.SamplePlugin.FakePlugin"}
+extensions_path = os.path.join(os.path.dirname(__file__), "extensions")
 
 
 class StubExtension(object):
@@ -409,6 +409,9 @@ def setup_base_app():
 
 
 def setup_extensions_middleware(extension_manager=None):
+    extension_manager = (extension_manager or
+                         PluginAwareExtensionManager(extensions_path,
+                                                     QuantumEchoPlugin()))
     options = {'config_file': test_conf_file}
     conf, app = config.load_paste_app('extensions_test_app', options, None)
     return ExtensionMiddleware(app, conf, ext_mgr=extension_manager)