Makes blockstorage and compute composite auth more flexible

* Allows users to specify an auth composite when instantiating
   a project composite.
 * Minor pep8 and consistancy fixes.

Change-Id: I4a2567832c73087001f9a899219ea71af612ab36
This commit is contained in:
Jose Idar 2014-10-22 07:41:43 -05:00
parent b2abf89f3e
commit 8b2c48ebc9
3 changed files with 32 additions and 16 deletions

View File

@ -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

View File

@ -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 "

View File

@ -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,