# 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()
++
a particular Virtual Network.
"""
pass
- return NotImplemented
+
+ @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
++
++