From: Somik Behera Date: Fri, 13 May 2011 22:49:08 +0000 (-0700) Subject: merged salvatore's changes to local branch X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1290f3a0e0a6f9fb3c576058326d3ffa26d754ba;p=openstack-build%2Fneutron-build.git merged salvatore's changes to local branch --- 1290f3a0e0a6f9fb3c576058326d3ffa26d754ba diff --cc quantum/manager.py index 1d2c440b1,fe08addd9..a8a6da6ed --- a/quantum/manager.py +++ b/quantum/manager.py @@@ -14,50 -14,8 +14,49 @@@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +# @author: Somik Behera, Nicira Networks, Inc. + """ -Manager is responsible for parsing a config file and instantiating the correct -set of plugins that concretely implement quantum_plugin_base class +Quantum's Manager class is responsible for parsing a config file and instantiating the correct +plugin that concretely implement quantum_plugin_base class + +The caller should make sure that QuantumManager is a singleton. """ + +import utils +from quantum_plugin_base import QuantumPluginBase + +CONFIG_FILE = "quantum_plugin.conf" + +class QuantumManager(object): + + def __init__(self,config=CONFIG_FILE): + self.configuration_file = CONFIG_FILE + #TODO(somik): plugin location should be grabbed from a + # configuration file as opposed to hard-coding the location + # + #plugin_location = get_plugin_location(configuration_file) + plugin_location = "plugins.SamplePlugin.QuantumEchoPlugin" + plugin_klass = utils.import_class(plugin_location) + if not issubclass(plugin_klass, QuantumPluginBase): + raise Exception("Imported plugin didn't pass compatibility test") + else: + print("Imported plugin passed compatibility test\n") + self.plugin = plugin_klass() + + def get_manager(self): + return self.plugin + +# TODO(somik): rmove the main class +# Added for temporary testing purposes +def main(): + manager = QuantumManager() + myManager = manager.get_manager() + myManager.get_all_networks("tesst") + #print("is a plugin") + +# Standard boilerplate to call the main() function. +if __name__ == '__main__': + main() - - ++ diff --cc quantum/quantum_plugin_base.py index 7fedd528c,c19febe66..0ab808979 --- a/quantum/quantum_plugin_base.py +++ b/quantum/quantum_plugin_base.py @@@ -133,21 -134,3 +134,23 @@@ class QuantumPluginBase(object) a particular Virtual Network. """ pass + + @classmethod + def __subclasshook__(cls, klass): + """ + The __subclasshook__ method is a class method + that will be called everytime a class is tested + using issubclass(klass, Plugin). + In that case, it will check that every method + marked with the abstractmethod decorator is + provided by the plugin class. + """ + if cls is QuantumPluginBase: + for method in cls.__abstractmethods__: + if any(method in base.__dict__ for base in klass.__mro__): + continue + return NotImplemented + return True - return NotImplemented ++ return NotImplemented ++ ++