Преглед изворни кода

Middleware inheritance from factory

almahmoud пре 7 година
родитељ
комит
1c101698e2

+ 4 - 4
cloudbridge/cloud/base/provider.py

@@ -2,14 +2,13 @@
 import functools
 import logging
 import os
+from copy import deepcopy
 from os.path import expanduser
 try:
     from configparser import ConfigParser
 except ImportError:  # Python 2
     from ConfigParser import SafeConfigParser as ConfigParser
 
-from pyeventsystem.middleware import SimpleMiddlewareManager
-
 import six
 
 from ..base.middleware import ExceptionWrappingMiddleware
@@ -83,11 +82,12 @@ class BaseConfiguration(Configuration):
 
 
 class BaseCloudProvider(CloudProvider):
-    def __init__(self, config):
+    def __init__(self, config, factory):
+        self._factory = factory
         self._config = BaseConfiguration(config)
         self._config_parser = ConfigParser()
         self._config_parser.read(CloudBridgeConfigLocations)
-        self._middleware = SimpleMiddlewareManager()
+        self._middleware = deepcopy(factory.middleware)
         self.add_required_middleware()
 
     @property

+ 8 - 1
cloudbridge/cloud/factory.py

@@ -4,6 +4,8 @@ import logging
 import pkgutil
 from collections import defaultdict
 
+from pyeventsystem.middleware import SimpleMiddlewareManager
+
 from cloudbridge.cloud import providers
 from cloudbridge.cloud.interfaces import CloudProvider
 from cloudbridge.cloud.interfaces import TestMockHelperMixin
@@ -27,9 +29,14 @@ class CloudProviderFactory(object):
     """
 
     def __init__(self):
+        self._middleware = SimpleMiddlewareManager()
         self.provider_list = defaultdict(dict)
         log.debug("Providers List: %s", self.provider_list)
 
+    @property
+    def middleware(self):
+        return self._middleware
+
     def register_provider_class(self, cls):
         """
         Registers a provider class with the factory. The class must
@@ -136,7 +143,7 @@ class CloudProviderFactory(object):
                 'A provider with name {0} could not be'
                 ' found'.format(name))
         log.debug("Created '%s' provider", name)
-        return provider_class(config)
+        return provider_class(config, self)
 
     def get_provider_class(self, name):
         """

+ 2 - 2
cloudbridge/cloud/providers/aws/provider.py

@@ -17,8 +17,8 @@ class AWSCloudProvider(BaseCloudProvider):
     PROVIDER_ID = 'aws'
     AWS_INSTANCE_DATA_DEFAULT_URL = "http://cloudve.org/cb-aws-vmtypes.json"
 
-    def __init__(self, config):
-        super(AWSCloudProvider, self).__init__(config)
+    def __init__(self, config, factory):
+        super(AWSCloudProvider, self).__init__(config, factory)
 
         # Initialize cloud connection fields
         # These are passed as-is to Boto

+ 2 - 2
cloudbridge/cloud/providers/azure/provider.py

@@ -23,8 +23,8 @@ log = logging.getLogger(__name__)
 class AzureCloudProvider(BaseCloudProvider):
     PROVIDER_ID = 'azure'
 
-    def __init__(self, config):
-        super(AzureCloudProvider, self).__init__(config)
+    def __init__(self, config, factory):
+        super(AzureCloudProvider, self).__init__(config, factory)
 
         # mandatory config values
         self.subscription_id = self._get_config_value(

+ 2 - 2
cloudbridge/cloud/providers/gcp/provider.py

@@ -196,8 +196,8 @@ class GCPCloudProvider(BaseCloudProvider):
 
     PROVIDER_ID = 'gcp'
 
-    def __init__(self, config):
-        super(GCPCloudProvider, self).__init__(config)
+    def __init__(self, config, factory):
+        super(GCPCloudProvider, self).__init__(config, factory)
 
         # Disable warnings about file_cache not being available when using
         # oauth2client >= 4.0.0.

+ 2 - 2
cloudbridge/cloud/providers/mock/provider.py

@@ -25,9 +25,9 @@ class MockAWSCloudProvider(AWSCloudProvider, TestMockHelperMixin):
     """
     PROVIDER_ID = 'mock'
 
-    def __init__(self, config):
+    def __init__(self, config, factory):
         self.setUpMock()
-        super(MockAWSCloudProvider, self).__init__(config)
+        super(MockAWSCloudProvider, self).__init__(config, factory)
 
     def setUpMock(self):
         """

+ 2 - 2
cloudbridge/cloud/providers/openstack/provider.py

@@ -31,8 +31,8 @@ class OpenStackCloudProvider(BaseCloudProvider):
 
     PROVIDER_ID = 'openstack'
 
-    def __init__(self, config):
-        super(OpenStackCloudProvider, self).__init__(config)
+    def __init__(self, config, factory):
+        super(OpenStackCloudProvider, self).__init__(config, factory)
 
         # Initialize cloud connection fields
         self.username = self._get_config_value(

+ 1 - 1
test/helpers/__init__.py

@@ -262,7 +262,7 @@ class ProviderTestBase(unittest.TestCase):
         config = {'default_wait_interval':
                   self.get_provider_wait_interval(provider_class),
                   'default_result_limit': 5}
-        return provider_class(config)
+        return provider_class(config, factory)
 
     @property
     def provider(self):