You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/06/22 23:48:46 UTC

[1/2] git commit: Modify Rackspace compute and storage drivers to use _ex_connection_class_kwargs and move to global auth.

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 <to...@apache.org>
Authored: Sat Jun 22 23:28:51 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
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):


[2/2] git commit: Update affected storage tests.

Posted by to...@apache.org.
Update affected storage tests.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/61541061
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/61541061
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/61541061

Branch: refs/heads/make_rackspace_drivers_multi_datacenter_aware
Commit: 615410618d7a1ea75b3641ceaddc09108f44b5bd
Parents: 51cc274
Author: Tomaz Muraus <to...@apache.org>
Authored: Sat Jun 22 23:44:39 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sat Jun 22 23:44:39 2013 +0200

----------------------------------------------------------------------
 libcloud/storage/drivers/cloudfiles.py          |   2 +-
 .../fixtures/cloudfiles/_v2_0__auth.json        | 128 +++++++++++++++++++
 libcloud/test/storage/test_cloudfiles.py        |  18 +--
 3 files changed, 139 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/61541061/libcloud/storage/drivers/cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py
index 41c5b47..e6507dc 100644
--- a/libcloud/storage/drivers/cloudfiles.py
+++ b/libcloud/storage/drivers/cloudfiles.py
@@ -829,7 +829,7 @@ class CloudFilesUKStorageDriver(CloudFilesStorageDriver):
     name = 'CloudFiles (UK)'
     _datacenter = 'lon'
 
-    def __init__(*args, **kwargs):
+    def __init__(self, *args, **kwargs):
         kwargs['datacenter'] = 'lon'
         super(CloudFilesUKStorageDriver, self).__init__(*args, **kwargs)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/61541061/libcloud/test/storage/fixtures/cloudfiles/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/fixtures/cloudfiles/_v2_0__auth.json b/libcloud/test/storage/fixtures/cloudfiles/_v2_0__auth.json
new file mode 100644
index 0000000..b9cbb9d
--- /dev/null
+++ b/libcloud/test/storage/fixtures/cloudfiles/_v2_0__auth.json
@@ -0,0 +1,128 @@
+{
+    "access": {
+        "token": {
+            "id": "aaaaaaaaaaaa-bbb-cccccccccccccc",
+            "expires": "2011-11-23T21:00:14.000-06:00"
+        },
+        "serviceCatalog": [
+            {
+                "endpoints": [
+                    {
+                        "region": "ORD",
+                        "tenantId": "MossoCloudFS_11111-111111111-1111111111-1111111",
+                        "publicURL": "https://cdn.clouddrive.com/v1/MossoCloudFS",
+                        "version": {
+                            "versionInfo": "https://cdn2.clouddrive.com/v1/",
+                            "versionList": "https://cdn2.clouddrive.com/",
+                            "versionId": "1"
+                        }
+                    },
+                    {
+                        "region": "LON",
+                        "tenantId": "MossoCloudFS_11111-111111111-1111111111-1111111",
+                        "publicURL": "https://cdn.clouddrive.com/v1/MossoCloudFS",
+                        "version": {
+                            "versionInfo": "https://cdn2.clouddrive.com/v1/",
+                            "versionList": "https://cdn2.clouddrive.com/",
+                            "versionId": "1"
+                        }
+                    }
+
+                ],
+                "name": "cloudFilesCDN",
+                "type": "object-store"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "ORD",
+                        "tenantId": "MossoCloudFS_11111-111111111-1111111111-1111111",
+                        "publicURL": "https://storage4.ord1.clouddrive.com/v1/MossoCloudFS",
+                        "internalURL": "https://snet-storage101.ord1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111"
+                    },
+                    {
+                        "region": "LON",
+                        "tenantId": "MossoCloudFS_11111-111111111-1111111111-1111111",
+                        "publicURL": "https://storage4.lon1.clouddrive.com/v1/MossoCloudFS",
+                        "internalURL": "https://snet-storage101.lon1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111"
+                    }
+                ],
+                "name": "cloudFiles",
+                "type": "object-store"
+            },
+            {
+                "endpoints": [
+                    {
+                        "tenantId": "1337",
+                        "publicURL": "https://servers.api.rackspacecloud.com/v1.0/1337",
+                        "version": {
+                            "versionInfo": "https://servers.api.rackspacecloud.com/v1.0/",
+                            "versionList": "https://servers.api.rackspacecloud.com/",
+                            "versionId": "1.0"
+                        }
+                    }
+                ],
+                "name": "cloudServers",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "RegionOne",
+                        "tenantId": "1337",
+                        "publicURL": "https://127.0.0.1/v2/1337",
+                        "versionInfo": "https://127.0.0.1/v2/",
+                        "versionList": "https://127.0.0.1/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "nova",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "613469",
+                        "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/1337",
+                        "versionInfo": "https://dfw.servers.api.rackspacecloud.com/v2/",
+                        "versionList": "https://dfw.servers.api.rackspacecloud.com/",
+                        "versionId": "2"
+                    },
+                    {
+                        "region": "ORD",
+                        "tenantId": "613469",
+                        "publicURL": "https://ord.servers.api.rackspacecloud.com/v2/1337",
+                        "versionInfo": "https://ord.servers.api.rackspacecloud.com/v2/",
+                        "versionList": "https://ord.servers.api.rackspacecloud.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "cloudServersOpenStack",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "1337",
+                        "publicURL": "https://preprod.dfw.servers.api.rackspacecloud.com/v2/1337"
+                    }
+                ],
+                "name": "cloudServersPreprod",
+                "type": "compute"
+            }
+        ],
+        "user": {
+            "id": "7",
+            "roles": [
+                {
+                    "id": "identity:default",
+                    "description": "Default Role.",
+                    "name": "identity:default"
+                }
+            ],
+            "name": "testuser"
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/61541061/libcloud/test/storage/test_cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py
index 1fd5f06..7cfb772 100644
--- a/libcloud/test/storage/test_cloudfiles.py
+++ b/libcloud/test/storage/test_cloudfiles.py
@@ -147,7 +147,7 @@ class CloudFilesTests(unittest.TestCase):
             self.fail('Exception was not thrown')
 
     def test_service_catalog(self):
-        url = 'https://storage101.%s1.clouddrive.com/v1/MossoCloudFS' % \
+        url = 'https://storage4.%s1.clouddrive.com/v1/MossoCloudFS' % \
               (self.datacenter)
         self.assertEqual(
              url,
@@ -155,7 +155,7 @@ class CloudFilesTests(unittest.TestCase):
 
         self.driver.connection.cdn_request = True
         self.assertEqual(
-             'https://cdn2.clouddrive.com/v1/MossoCloudFS',
+             'https://cdn.clouddrive.com/v1/MossoCloudFS',
              self.driver.connection.get_endpoint())
         self.driver.connection.cdn_request = False
 
@@ -723,7 +723,7 @@ class CloudFilesTests(unittest.TestCase):
                                     "/v1/MossoCloudFS/foo_bar_container/foo_bar_object")
         sig = hmac.new(b('foo'), b(hmac_body), sha1).hexdigest()
         ret = self.driver.ex_get_object_temp_url(obj, 'GET')
-        temp_url = 'https://storage101.%s1.clouddrive.com/v1/MossoCloudFS/foo_bar_container/foo_bar_object?temp_url_expires=60&temp_url_sig=%s' % (self.datacenter, sig)
+        temp_url = 'https://storage4.%s1.clouddrive.com/v1/MossoCloudFS/foo_bar_container/foo_bar_object?temp_url_expires=60&temp_url_sig=%s' % (self.datacenter, sig)
 
         self.assertEquals(''.join(sorted(ret)), ''.join(sorted(temp_url)))
 
@@ -761,9 +761,15 @@ class CloudFilesDeprecatedUKTests(CloudFilesTests):
 class CloudFilesMockHttp(StorageMockHttp, MockHttpTestCase):
 
     fixtures = StorageFileFixtures('cloudfiles')
-    auth_fixtures = OpenStackFixtures()
     base_headers = { 'content-type': 'application/json; charset=UTF-8'}
 
+    def _v2_0_tokens(self, method, url, body, headers):
+        headers = copy.deepcopy(self.base_headers)
+        body = self.fixtures.load('_v2_0__auth.json')
+        return (httplib.OK, body, headers,
+                httplib.responses[httplib.OK])
+
+
     # fake auth token response
     def _v1_0(self, method, url, body, headers):
         headers = copy.deepcopy(self.base_headers)
@@ -1004,10 +1010,6 @@ class CloudFilesMockHttp(StorageMockHttp, MockHttpTestCase):
 
         return (status_code, body, headers, httplib.responses[httplib.OK])
 
-    def _v1_1_auth(self, method, url, body, headers):
-        body = self.auth_fixtures.load('_v1_1__auth.json')
-        return (httplib.OK, body, {'content-type': 'application/json; charset=UTF-8'}, httplib.responses[httplib.OK])
-
 
 class CloudFilesMockRawResponse(MockRawResponse):