Updated Branches: refs/heads/make_rackspace_drivers_multi_datacenter_aware [created] 615410618
Modify Rackspace compute and storage drivers to use _ex_connection_class_kwargs and move to global auth. Also modify first gen compute driver to use and only support auth 2.0. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/51cc274e Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/51cc274e Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/51cc274e Branch: refs/heads/make_rackspace_drivers_multi_datacenter_aware Commit: 51cc274e2fc9671907c24e252a536e50450aeb9f Parents: 692dd9c Author: Tomaz Muraus <[email protected]> Authored: Sat Jun 22 23:28:51 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Sat Jun 22 23:28:51 2013 +0200 ---------------------------------------------------------------------- libcloud/common/rackspace.py | 6 +-- libcloud/compute/drivers/rackspace.py | 64 ++++++++++++++++++++--------- libcloud/storage/drivers/cloudfiles.py | 53 ++++++++++-------------- 3 files changed, 68 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/51cc274e/libcloud/common/rackspace.py ---------------------------------------------------------------------- diff --git a/libcloud/common/rackspace.py b/libcloud/common/rackspace.py index 79da728..f36e606 100644 --- a/libcloud/common/rackspace.py +++ b/libcloud/common/rackspace.py @@ -17,10 +17,8 @@ Common settings for Rackspace Cloud Servers and Cloud Files """ -AUTH_URL_US = 'https://auth.api.rackspacecloud.com/v1.1/' -AUTH_URL_UK = 'https://lon.auth.api.rackspacecloud.com/v1.1/' +AUTH_URL = 'https://auth.api.rackspacecloud.com/v1.1/' __all__ = [ - "AUTH_URL_US", - "AUTH_URL_UK", + 'AUTH_URL', ] http://git-wip-us.apache.org/repos/asf/libcloud/blob/51cc274e/libcloud/compute/drivers/rackspace.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/rackspace.py b/libcloud/compute/drivers/rackspace.py index 9aadad3..44926f3 100644 --- a/libcloud/compute/drivers/rackspace.py +++ b/libcloud/compute/drivers/rackspace.py @@ -22,7 +22,7 @@ from libcloud.compute.drivers.openstack import OpenStack_1_0_Connection,\ from libcloud.compute.drivers.openstack import OpenStack_1_1_Connection,\ OpenStack_1_1_NodeDriver -from libcloud.common.rackspace import AUTH_URL_US, AUTH_URL_UK +from libcloud.common.rackspace import AUTH_URL ENDPOINT_ARGS_MAP = { @@ -40,27 +40,48 @@ ENDPOINT_ARGS_MAP = { 'region': 'SYD'}, } +VALID_DATACENTERS = ENDPOINT_ARGS_MAP.keys() + class RackspaceFirstGenConnection(OpenStack_1_0_Connection): """ Connection class for the Rackspace first-gen driver. """ responseCls = OpenStack_1_0_Response - auth_url = AUTH_URL_US XML_NAMESPACE = 'http://docs.rackspacecloud.com/servers/api/v1.0' + auth_url = AUTH_URL + _auth_version = '2.0' + + def __init__(self, *args, **kwargs): + self.region = kwargs.pop('region', None) + super(RackspaceFirstGenConnection, self).__init__(*args, **kwargs) def get_endpoint(self): ep = {} if '2.0' in self._auth_version: ep = self.service_catalog.get_endpoint(service_type='compute', name='cloudServers') - elif ('1.1' in self._auth_version) or ('1.0' in self._auth_version): - ep = self.service_catalog.get_endpoint(name='cloudServers') + else: + raise LibcloudError( + 'Auth version "%s" not supported' % (self._auth_version)) - if 'publicURL' in ep: - return ep['publicURL'] + public_url = ep.get('publicURL', None) + + if not public_url: + raise LibcloudError('Could not find specified endpoint') + + # This is a nasty hack, but because of how global auth and old accounts + # work, there is no way around it. + if self.region == 'us': + # Old UK account, which only has us endpoint in the catalog + public_url = public_url.replace('https://lon.servers.api', + 'https://servers.api') + if self.region == 'uk': + # Old US account, which only has uk endpoint in the catalog + public_url = public_url.replace('https://servers.api', + 'https://lon.servers.api') - raise LibcloudError('Could not find specified endpoint') + return public_url class RackspaceFirstGenNodeDriver(OpenStack_1_0_NodeDriver): @@ -81,11 +102,6 @@ class RackspaceFirstGenNodeDriver(OpenStack_1_0_NodeDriver): if region not in ['us', 'uk']: raise ValueError('Invalid region: %s' % (region)) - if region == 'us': - self.connectionCls.auth_url = AUTH_URL_US - elif region == 'uk': - self.connectionCls.auth_url = AUTH_URL_UK - self.region = region super(RackspaceFirstGenNodeDriver, self).__init__(key=key, @@ -110,12 +126,21 @@ class RackspaceFirstGenNodeDriver(OpenStack_1_0_NodeDriver): return locations + def _ex_connection_class_kwargs(self): + kwargs = {'region': self.region} + return kwargs + class RackspaceConnection(OpenStack_1_1_Connection): """ Connection class for the Rackspace next-gen OpenStack base driver. """ - get_endpoint_args = {} + auth_url = AUTH_URL + _auth_version = '2.0' + + def __init__(self, *args, **kwargs): + self.get_endpoint_args = kwargs.pop('get_endpoint_args', None) + super(RackspaceConnection, self).__init__(*args, **kwargs) def get_endpoint(self): if not self.get_endpoint_args: @@ -153,22 +178,21 @@ class RackspaceNodeDriver(OpenStack_1_1_NodeDriver): @type datacenter: C{str} """ - if datacenter not in ['dfw', 'ord', 'lon', 'syd']: + if datacenter not in VALID_DATACENTERS: raise ValueError('Invalid datacenter: %s' % (datacenter)) if datacenter in ['dfw', 'ord', 'syd']: - self.connectionCls.auth_url = AUTH_URL_US self.api_name = 'rackspacenovaus' elif datacenter == 'lon': - self.connectionCls.auth_url = AUTH_URL_UK self.api_name = 'rackspacenovalon' - self.connectionCls._auth_version = '2.0' - self.connectionCls.get_endpoint_args = \ - ENDPOINT_ARGS_MAP[datacenter] - self.datacenter = datacenter super(RackspaceNodeDriver, self).__init__(key=key, secret=secret, secure=secure, host=host, port=port, **kwargs) + + def _ex_connection_class_kwargs(self): + endpoint_args = ENDPOINT_ARGS_MAP[self.datacenter] + kwargs = {'get_endpoint_args': endpoint_args} + return kwargs http://git-wip-us.apache.org/repos/asf/libcloud/blob/51cc274e/libcloud/storage/drivers/cloudfiles.py ---------------------------------------------------------------------- diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py index 8e51e59..41c5b47 100644 --- a/libcloud/storage/drivers/cloudfiles.py +++ b/libcloud/storage/drivers/cloudfiles.py @@ -48,7 +48,7 @@ from libcloud.storage.types import InvalidContainerNameError from libcloud.common.openstack import OpenStackBaseConnection from libcloud.common.openstack import OpenStackDriverMixin -from libcloud.common.rackspace import AUTH_URL_US, AUTH_URL_UK +from libcloud.common.rackspace import AUTH_URL CDN_HOST = 'cdn.clouddrive.com' API_VERSION = 'v1.0' @@ -102,46 +102,40 @@ class CloudFilesConnection(OpenStackBaseConnection): responseCls = CloudFilesResponse rawResponseCls = CloudFilesRawResponse + auth_url = AUTH_URL + _auth_version = '2.0' - def __init__(self, user_id, key, secure=True, auth_url=AUTH_URL_US, - **kwargs): + def __init__(self, user_id, key, secure=True, **kwargs): super(CloudFilesConnection, self).__init__(user_id, key, secure=secure, **kwargs) - self.auth_url = auth_url self.api_version = API_VERSION self.accept_format = 'application/json' self.cdn_request = False - if self._ex_force_service_region: - self.service_region = self._ex_force_service_region - def get_endpoint(self): - # First, we parse out both files and cdn endpoints - # for each auth version + region = self._ex_force_service_region.upper() + if '2.0' in self._auth_version: - eps = self.service_catalog.get_endpoints( + ep = self.service_catalog.get_endpoint( service_type='object-store', - name='cloudFiles') - cdn_eps = self.service_catalog.get_endpoints( + name='cloudFiles', + region=region) + cdn_ep = self.service_catalog.get_endpoint( service_type='object-store', - name='cloudFilesCDN') - elif ('1.1' in self._auth_version) or ('1.0' in self._auth_version): - eps = self.service_catalog.get_endpoints(name='cloudFiles') - cdn_eps = self.service_catalog.get_endpoints(name='cloudFilesCDN') + name='cloudFilesCDN', + region=region) + else: + raise LibcloudError( + 'Auth version "%s" not supported' % (self._auth_version)) # if this is a CDN request, return the cdn url instead if self.cdn_request: - eps = cdn_eps - - if self._ex_force_service_region: - eps = [ep for ep in eps if ep['region'].lower() == self._ex_force_service_region.lower()] + ep = cdn_ep - if len(eps) == 0: + if not ep: # TODO: Better error message raise LibcloudError('Could not find specified endpoint') - ep = eps[0] - if 'publicURL' in ep: return ep['publicURL'] else: @@ -211,8 +205,6 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin): @param datacenter: Datacenter ID which should be used. @type datacenter: C{str} """ - if hasattr(self, '_datacenter'): - datacenter = self._datacenter # This is here for backard compatibility if 'ex_force_service_region' in kwargs: @@ -793,12 +785,6 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin): def _ex_connection_class_kwargs(self): kwargs = {'ex_force_service_region': self.datacenter} - - if self.datacenter in ['dfw', 'ord', 'syd']: - kwargs['auth_url'] = AUTH_URL_US - elif self.datacenter == 'lon': - kwargs['auth_url'] = AUTH_URL_UK - kwargs.update(self.openstack_connection_kwargs()) return kwargs @@ -810,6 +796,8 @@ class CloudFilesUSStorageDriver(CloudFilesStorageDriver): type = Provider.CLOUDFILES_US name = 'CloudFiles (US)' + + _datacenter = 'ord' @@ -841,6 +829,9 @@ class CloudFilesUKStorageDriver(CloudFilesStorageDriver): name = 'CloudFiles (UK)' _datacenter = 'lon' + def __init__(*args, **kwargs): + kwargs['datacenter'] = 'lon' + super(CloudFilesUKStorageDriver, self).__init__(*args, **kwargs) class FileChunkReader(object): def __init__(self, file_path, chunk_size):
