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 2012/03/20 21:59:51 UTC

svn commit: r1303146 - in /libcloud/trunk: ./ libcloud/dns/drivers/ libcloud/loadbalancer/drivers/ test/dns/ test/dns/fixtures/rackspace/ test/loadbalancer/ test/loadbalancer/fixtures/rackspace/

Author: tomaz
Date: Tue Mar 20 20:59:50 2012
New Revision: 1303146

URL: http://svn.apache.org/viewvc?rev=1303146&view=rev
Log:
Modify Rackspace DNS and Loadbalancer driver so it works with Auth 2.0. This 
patch has been contributed by Dave King and is part of LIBCLOUD-165.

Added:
    libcloud/trunk/test/dns/fixtures/rackspace/auth_2_0.json
    libcloud/trunk/test/loadbalancer/fixtures/rackspace/auth_2_0.json
Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/dns/drivers/rackspace.py
    libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
    libcloud/trunk/test/dns/test_rackspace.py
    libcloud/trunk/test/loadbalancer/test_rackspace.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1303146&r1=1303145&r2=1303146&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Tue Mar 20 20:59:50 2012
@@ -78,6 +78,14 @@ Changes with Apache Libcloud in developm
       pass 'vip' argument to it. ; LIBCLOUD-166
       [Adam Pickeral]
 
+    - Update Rackspace driver to support Auth 2.0. ; LIBCLOUD-165
+      [Dave King]
+
+  *) DNS:
+
+    - Update Rackspace driver to support Auth 2.0. ; LIBCLOUD-165
+      [Dave King]
+
 Changes with Apache Libcloud 0.8.0:
 
   *) General:

Modified: libcloud/trunk/libcloud/dns/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/dns/drivers/rackspace.py?rev=1303146&r1=1303145&r2=1303146&view=diff
==============================================================================
--- libcloud/trunk/libcloud/dns/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/dns/drivers/rackspace.py Tue Mar 20 20:59:50 2012
@@ -101,15 +101,23 @@ class RackspaceDNSConnection(OpenStack_1
         if self._auth_version == "1.1":
             ep = self.service_catalog.get_endpoint(name="cloudServers")
 
-            if 'publicURL' in ep:
-                return ep['publicURL'].replace("servers", "dns")
-            else:
-                raise LibcloudError('Could not find specified endpoint')
+            return self._construct_dns_endpoint_from_servers_endpoint(ep)
+        elif "2.0" in self._auth_version:
+            ep = self.service_catalog.get_endpoint(name="cloudServers",
+                service_type="compute",
+                region=None)
 
+            return self._construct_dns_endpoint_from_servers_endpoint(ep)
         else:
             raise LibcloudError("Auth version %s not supported" % \
                 self._auth_version)
 
+    def _construct_dns_endpoint_from_servers_endpoint(self, ep):
+        if 'publicURL' in ep:
+            return ep['publicURL'].replace("servers", "dns")
+        else:
+            raise LibcloudError('Could not find specified endpoint')
+
 
 class RackspaceUSDNSConnection(RackspaceDNSConnection):
     auth_url = AUTH_URL_US

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py?rev=1303146&r1=1303145&r2=1303146&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py Tue Mar 20 20:59:50 2012
@@ -229,11 +229,13 @@ class RackspaceConnection(OpenStackBaseC
     poll_interval = 2
     timeout = 80
 
-    def __init__(self, user_id, key, secure=True, **kwargs):
+    def __init__(self, user_id, key, secure=True, ex_force_region='ord',
+                 **kwargs):
         super(RackspaceConnection, self).__init__(user_id, key, secure,
                                                   **kwargs)
         self.api_version = 'v1.0'
         self.accept_format = 'application/json'
+        self._ex_force_region = ex_force_region
 
     def request(self, action, params=None, data='', headers=None,
                 method='GET'):
@@ -272,15 +274,24 @@ class RackspaceConnection(OpenStackBaseC
         if self._auth_version == "1.1":
             ep = self.service_catalog.get_endpoint(name="cloudServers")
 
-            if 'publicURL' in ep:
-                return ep['publicURL'].replace("servers", "ord.loadbalancers")
-            else:
-                raise LibcloudError('Could not find specified endpoint')
+            return self._construct_loadbalancer_endpoint_from_servers_endpoint(ep)
+        elif "2.0" in self._auth_version:
+            ep = self.service_catalog.get_endpoint(name="cloudServers",
+                service_type="compute",
+                region=None)
 
+            return self._construct_loadbalancer_endpoint_from_servers_endpoint(ep)
         else:
             raise LibcloudError("Auth version %s not supported" % \
                 self._auth_version)
 
+    def _construct_loadbalancer_endpoint_from_servers_endpoint(self, ep):
+        if 'publicURL' in ep:
+            loadbalancer_prefix = "%s.loadbalancers" % self._ex_force_region
+            return ep['publicURL'].replace("servers", loadbalancer_prefix)
+        else:
+            raise LibcloudError('Could not find specified endpoint')
+
 
 class RackspaceUKConnection(RackspaceConnection):
     auth_url = AUTH_URL_UK
@@ -320,10 +331,15 @@ class RackspaceLBDriver(Driver, OpenStac
 
     def __init__(self, *args, **kwargs):
         OpenStackDriverMixin.__init__(self, *args, **kwargs)
+        self._ex_force_region = kwargs.pop('ex_force_region', None)
         super(RackspaceLBDriver, self).__init__(*args, **kwargs)
 
     def _ex_connection_class_kwargs(self):
-        return self.openstack_connection_kwargs()
+        kwargs = self.openstack_connection_kwargs()
+        if self._ex_force_region:
+            kwargs['ex_force_region'] = self._ex_force_region
+
+        return kwargs
 
     def list_protocols(self):
         return self._to_protocols(

Added: libcloud/trunk/test/dns/fixtures/rackspace/auth_2_0.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/rackspace/auth_2_0.json?rev=1303146&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/rackspace/auth_2_0.json (added)
+++ libcloud/trunk/test/dns/fixtures/rackspace/auth_2_0.json Tue Mar 20 20:59:50 2012
@@ -0,0 +1,71 @@
+{
+    "access": {
+        "token": {
+            "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+            "expires": "2012-03-14T08:10:14.000-05:00"
+        },
+        "serviceCatalog": [
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "publicURL": "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "internalURL": "https://snet-storage101.dfw1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+                    }
+                ],
+                "name": "cloudFiles",
+                "type": "object-store"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "11111",
+                        "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/11111",
+                        "versionInfo": "https://dfw.servers.api.rackspacecloud.com/v2/",
+                        "versionList": "https://dfw.servers.api.rackspacecloud.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "cloudServersOpenStack",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "tenantId": "11111",
+                        "publicURL": "https://servers.api.rackspacecloud.com/v1.0/11111",
+                        "versionInfo": "https://servers.api.rackspacecloud.com/v1.0/",
+                        "versionList": "https://servers.api.rackspacecloud.com/",
+                        "versionId": "1.0"
+                    }
+                ],
+                "name": "cloudServers",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "publicURL": "https://cdn1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+                    }
+                ],
+                "name": "cloudFilesCDN",
+                "type": "object-store"
+            }
+        ],
+        "user": {
+            "id": "9586",
+            "roles": [
+                {
+                    "id": "identity:default",
+                    "description": "Default Role.",
+                    "name": "identity:default"
+                }
+            ],
+            "name": "libclouduser"
+        }
+    }
+}

Modified: libcloud/trunk/test/dns/test_rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/test_rackspace.py?rev=1303146&r1=1303145&r2=1303146&view=diff
==============================================================================
--- libcloud/trunk/test/dns/test_rackspace.py (original)
+++ libcloud/trunk/test/dns/test_rackspace.py Tue Mar 20 20:59:50 2012
@@ -65,6 +65,15 @@ class RackspaceUSTests(unittest.TestCase
         self.assertEquals(kwargs['ex_force_auth_version'],
             driver.connection._auth_version)
 
+    def test_gets_auth_2_0_endpoint(self):
+        driver = self.klass(*DNS_PARAMS_RACKSPACE,
+            ex_force_auth_version='2.0_password'
+        )
+        driver.connection._populate_hosts_and_request_paths()
+
+        self.assertEquals('https://dns.api.rackspacecloud.com/v1.0/11111',
+            driver.connection.get_endpoint())
+
     def test_list_record_types(self):
         record_types = self.driver.list_record_types()
         self.assertEqual(len(record_types), 7)
@@ -297,9 +306,10 @@ class RackspaceMockHttp(MockHttp):
     fixtures = DNSFileFixtures('rackspace')
     base_headers = {'content-type': 'application/json'}
 
-    # fake auth token response
+
     def _v1_1_auth(self, method, url, body, headers):
         body = self.fixtures.load('auth_1_1.json')
+        # fake auth token response
         headers = {'content-length': '657', 'vary': 'Accept,Accept-Encoding',
                    'server': 'Apache/2.2.13 (Red Hat)',
                    'connection': 'Keep-Alive',
@@ -308,6 +318,14 @@ class RackspaceMockHttp(MockHttp):
         return (httplib.OK, body, headers,
                 httplib.responses[httplib.OK])
 
+    def _v2_0_tokens(self, method, url, body, headers):
+        body = self.fixtures.load('auth_2_0.json')
+        headers = {
+            'content-type': 'application/json'
+        }
+        return (httplib.OK, body, headers,
+                httplib.responses[httplib.OK])
+
     def _v1_0_11111_domains(self, method, url, body, headers):
         body = self.fixtures.load('list_zones_success.json')
         return (httplib.OK, body, self.base_headers,

Added: libcloud/trunk/test/loadbalancer/fixtures/rackspace/auth_2_0.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/loadbalancer/fixtures/rackspace/auth_2_0.json?rev=1303146&view=auto
==============================================================================
--- libcloud/trunk/test/loadbalancer/fixtures/rackspace/auth_2_0.json (added)
+++ libcloud/trunk/test/loadbalancer/fixtures/rackspace/auth_2_0.json Tue Mar 20 20:59:50 2012
@@ -0,0 +1,71 @@
+{
+    "access": {
+        "token": {
+            "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+            "expires": "2012-03-14T08:10:14.000-05:00"
+        },
+        "serviceCatalog": [
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "publicURL": "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "internalURL": "https://snet-storage101.dfw1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+                    }
+                ],
+                "name": "cloudFiles",
+                "type": "object-store"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "11111",
+                        "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/11111",
+                        "versionInfo": "https://dfw.servers.api.rackspacecloud.com/v2/",
+                        "versionList": "https://dfw.servers.api.rackspacecloud.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "cloudServersOpenStack",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "tenantId": "11111",
+                        "publicURL": "https://servers.api.rackspacecloud.com/v1.0/11111",
+                        "versionInfo": "https://servers.api.rackspacecloud.com/v1.0/",
+                        "versionList": "https://servers.api.rackspacecloud.com/",
+                        "versionId": "1.0"
+                    }
+                ],
+                "name": "cloudServers",
+                "type": "compute"
+            },
+            {
+                "endpoints": [
+                    {
+                        "region": "DFW",
+                        "tenantId": "MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+                        "publicURL": "https://cdn1.clouddrive.com/v1/MossoCloudFS_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+                    }
+                ],
+                "name": "cloudFilesCDN",
+                "type": "object-store"
+            }
+        ],
+        "user": {
+            "id": "9586",
+            "roles": [
+                {
+                    "id": "identity:default",
+                    "description": "Default Role.",
+                    "name": "identity:default"
+                }
+            ],
+            "name": "libclouduser"
+        }
+    }
+}

Modified: libcloud/trunk/test/loadbalancer/test_rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/loadbalancer/test_rackspace.py?rev=1303146&r1=1303145&r2=1303146&view=diff
==============================================================================
--- libcloud/trunk/test/loadbalancer/test_rackspace.py (original)
+++ libcloud/trunk/test/loadbalancer/test_rackspace.py Tue Mar 20 20:59:50 2012
@@ -73,6 +73,25 @@ class RackspaceLBTests(unittest.TestCase
         self.assertEquals(kwargs['ex_force_auth_version'],
             driver.connection._auth_version)
 
+    def test_gets_auth_2_0_endpoint_defaults_to_ord_region(self):
+        driver = RackspaceLBDriver('user', 'key',
+            ex_force_auth_version='2.0_password'
+        )
+        driver.connection._populate_hosts_and_request_paths()
+
+        self.assertEquals('https://ord.loadbalancers.api.rackspacecloud.com/v1.0/11111',
+            driver.connection.get_endpoint())
+
+    def test_gets_auth_2_0_endpoint_for_dfw(self):
+        driver = RackspaceLBDriver('user', 'key',
+            ex_force_auth_version='2.0_password',
+            ex_force_region='dfw'
+        )
+        driver.connection._populate_hosts_and_request_paths()
+
+        self.assertEquals('https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/11111',
+            driver.connection.get_endpoint())
+
     def test_list_protocols(self):
         protocols = self.driver.list_protocols()
 
@@ -1325,6 +1344,14 @@ class RackspaceLBMockHttp(MockHttpTestCa
         body = self.auth_fixtures.load('_v1_1__auth.json')
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
+    def _v2_0_tokens(self, method, url, body, headers):
+        body = self.fixtures.load('auth_2_0.json')
+        headers = {
+            'content-type': 'application/json'
+        }
+        return (httplib.OK, body, headers,
+                httplib.responses[httplib.OK])
+
 
 class RackspaceLBWithVIPMockHttp(MockHttpTestCase):
     fixtures = LoadBalancerFileFixtures('rackspace')
@@ -1359,6 +1386,13 @@ class RackspaceLBWithVIPMockHttp(MockHtt
         body = self.auth_fixtures.load('_v1_1__auth.json')
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
+    def _v2_0_tokens(self, method, url, body, headers):
+        body = self.fixtures.load('auth_2_0.json')
+        headers = {
+            'content-type': 'application/json'
+        }
+        return (httplib.OK, body, headers,
+                httplib.responses[httplib.OK])
 
 if __name__ == "__main__":
     sys.exit(unittest.main())