From 01eafb56be207c3660cbe125e28598ac83cef097 Mon Sep 17 00:00:00 2001 From: Rajaram Mallya Date: Tue, 26 Jul 2011 10:57:24 +0530 Subject: [PATCH] Rajaram/Santhosh|Added plugin interface in foxinsox and Updated README --- README | 27 ++++++++++++++++++++++++++- quantum/common/extensions.py | 2 +- quantum/plugins/SamplePlugin.py | 7 +++++-- tests/unit/extensions/foxinsocks.py | 11 +++++++++++ tests/unit/test_extensions.py | 7 +++++-- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/README b/README index f3e973faa..5c5997084 100644 --- 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 diff --git a/quantum/common/extensions.py b/quantum/common/extensions.py index 79d3cfb15..485fbc2a5 100644 --- a/quantum/common/extensions.py +++ b/quantum/common/extensions.py @@ -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 diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index ff08bb370..68cd8e54e 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -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) diff --git a/tests/unit/extensions/foxinsocks.py b/tests/unit/extensions/foxinsocks.py index 2c224af82..5bdefde95 100644 --- a/tests/unit/extensions/foxinsocks.py +++ b/tests/unit/extensions/foxinsocks.py @@ -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" diff --git a/tests/unit/test_extensions.py b/tests/unit/test_extensions.py index 0478e3a37..9772f89e9 100644 --- a/tests/unit/test_extensions.py +++ b/tests/unit/test_extensions.py @@ -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) -- 2.45.2