]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
merged salvatore's changes to local branch
authorSomik Behera <somik@nicira.com>
Fri, 13 May 2011 22:49:08 +0000 (15:49 -0700)
committerSomik Behera <somik@nicira.com>
Fri, 13 May 2011 22:49:08 +0000 (15:49 -0700)
1  2 
quantum/manager.py
quantum/quantum_plugin_base.py

index 1d2c440b16e548a3cf7d0792066cebe6aac3808f,fe08addd90690fe9cf7c1f6d21354515dffba676..a8a6da6ed9d57241edfcff7ee462eee4a37b7a0e
  #    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()
++
index 7fedd528cf736fc615f15269aeb3fd0c5a394377,c19febe666aecd15cab7fd45d692691fe0e0c514..0ab80897928238b3b436e9bf9494ad7288b8139e
@@@ -133,21 -134,3 +134,23 @@@ class QuantumPluginBase(object)
          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
++
++