diff --git a/cloudcafe/auth/provider.py b/cloudcafe/auth/provider.py index 7e6342b2..1c334168 100644 --- a/cloudcafe/auth/provider.py +++ b/cloudcafe/auth/provider.py @@ -55,8 +55,8 @@ class MemoizedAuthServiceComposite(object): @classmethod @memoized - def get_rackspace_mfa_access_data(cls, username, password, tenant_id, - auth_endpoint, passcode): + def get_rackspace_mfa_access_data( + cls, username, password, tenant_id, auth_endpoint, passcode): if passcode is None: # TODO: This is a place holder for adding the functionality to # use an external service (e.g. - SMS) to provide the passcode diff --git a/cloudcafe/blockstorage/composites.py b/cloudcafe/blockstorage/composites.py index a97e6a4b..b4b08577 100644 --- a/cloudcafe/blockstorage/composites.py +++ b/cloudcafe/blockstorage/composites.py @@ -1,3 +1,5 @@ +import warnings + from cloudcafe.auth.provider import MemoizedAuthServiceComposite from cloudcafe.blockstorage.config import BlockStorageConfig from cloudcafe.blockstorage.volumes_api.common.config import VolumesAPIConfig @@ -18,10 +20,11 @@ from cloudcafe.blockstorage.volumes_api.v2.behaviors import \ class _BlockstorageAuthComposite(MemoizedAuthServiceComposite): + _blockstorage_config = BlockStorageConfig + def __init__(self): - self.config = BlockStorageConfig() - self.availability_zone = \ - self.config.availability_zone + self.config = self._blockstorage_config() + self.availability_zone = self.config.availability_zone super(_BlockstorageAuthComposite, self).__init__( self.config.identity_service_name, self.config.region) @@ -30,17 +33,30 @@ class _BaseVolumesComposite(object): _config = None _client = None _behaviors = None + _auth = _BlockstorageAuthComposite - def __init__(self): - self.blockstorage_auth = _BlockstorageAuthComposite() + def __init__(self, auth_composite=None): + self.auth = auth_composite or self._auth() self.config = self._config() self.client = self._client( - url=self.blockstorage_auth.public_url, - auth_token=self.blockstorage_auth.token_id, + url=self.auth.public_url, + auth_token=self.auth.token_id, serialize_format=self.config.serialize_format, deserialize_format=self.config.deserialize_format) self.behaviors = self._behaviors(self.client) + # For backwards compatability (deprecated - see property below) + self._blockstorage_auth = self.auth + + @property + def blockstorage_auth(self): + warnings.warn( + "the 'blockstorage_auth' attribute of the VolumesComposite is " + "deprecated. Please use the 'auth' attribute instead", + DeprecationWarning) + + return self._blockstorage_auth + class VolumesV1Composite(_BaseVolumesComposite): _config = v1Config @@ -55,12 +71,12 @@ class VolumesV2Composite(_BaseVolumesComposite): class VolumesAutoComposite(object): - def __new__(cls): + def __new__(cls, auth_composite=None): config = VolumesAPIConfig() if config.version_under_test == "1": - return VolumesV1Composite() + return VolumesV1Composite(auth_composite=auth_composite) if config.version_under_test == "2": - return VolumesV2Composite() + return VolumesV2Composite(auth_composite=auth_composite) else: raise Exception( "VolumesAutoComposite cannot be used unless the " diff --git a/cloudcafe/compute/composites.py b/cloudcafe/compute/composites.py index 1923bb7f..38bf56c8 100644 --- a/cloudcafe/compute/composites.py +++ b/cloudcafe/compute/composites.py @@ -87,8 +87,8 @@ class _ComputeAdminAuthComposite(_ComputeAuthComposite): class ComputeComposite(object): _auth_composite = _ComputeAuthComposite - def __init__(self): - auth_composite = self._auth_composite() + def __init__(self, auth_composite=None): + auth_composite = auth_composite or self._auth_composite() self.user = auth_composite._auth_user_config self.servers = ServersComposite(auth_composite) self.flavors = FlavorsComposite(auth_composite) @@ -141,9 +141,9 @@ class ComputeAdminComposite(ComputeComposite): class ComputeIntegrationComposite(ComputeComposite): - def __init__(self): + def __init__(self, auth_composite=None): super(ComputeIntegrationComposite, self).__init__() - self.volumes = VolumesAutoComposite() + self.volumes = VolumesAutoComposite(auth_composite=auth_composite) self.volume_attachments.behaviors = \ self.volume_attachments.behavior_class( self.volume_attachments.client,