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/10/15 09:37:00 UTC

[3/6] git commit: Update Rackspace DNS driver to support 'region' argument.

Update Rackspace DNS driver to support 'region' argument.


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

Branch: refs/heads/trunk
Commit: 0e7ffc9f50bc97fe3281d3ba6cf5c516b8a1bd3f
Parents: 56b1348
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Oct 14 22:23:22 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Oct 14 22:23:22 2013 +0200

----------------------------------------------------------------------
 libcloud/dns/drivers/rackspace.py               | 81 ++++++++++++--------
 libcloud/dns/providers.py                       | 14 ++--
 libcloud/dns/types.py                           |  7 +-
 .../test/dns/fixtures/rackspace/auth_2_0.json   | 71 -----------------
 libcloud/test/dns/test_rackspace.py             | 20 +----
 5 files changed, 65 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0e7ffc9f/libcloud/dns/drivers/rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/rackspace.py b/libcloud/dns/drivers/rackspace.py
index 973d158..d685745 100644
--- a/libcloud/dns/drivers/rackspace.py
+++ b/libcloud/dns/drivers/rackspace.py
@@ -25,7 +25,7 @@ import copy
 from libcloud.common.base import PollingConnection
 from libcloud.common.types import LibcloudError
 from libcloud.utils.misc import merge_valid_keys, get_new_obj
-from libcloud.common.rackspace import AUTH_URL_US, AUTH_URL_UK
+from libcloud.common.rackspace import AUTH_URL
 from libcloud.compute.drivers.openstack import OpenStack_1_1_Connection
 from libcloud.compute.drivers.openstack import OpenStack_1_1_Response
 
@@ -77,6 +77,13 @@ class RackspaceDNSConnection(OpenStack_1_1_Connection, PollingConnection):
     poll_interval = 2.5
     timeout = 30
 
+    auth_url = AUTH_URL
+    _auth_version = '2.0'
+
+    def __init__(self, *args, **kwargs):
+            self.region = kwargs.pop('region', None)
+            super(RackspaceDNSConnection, self).__init__(*args, **kwargs)
+
     def get_poll_request_kwargs(self, response, context, request_kwargs):
         job_id = response.object['jobId']
         kwargs = {'action': '/status/%s' % (job_id),
@@ -92,50 +99,45 @@ class RackspaceDNSConnection(OpenStack_1_1_Connection, PollingConnection):
         return status == 'COMPLETED'
 
     def get_endpoint(self):
-        """
-        FIXME:
-        Dirty, dirty hack. DNS doesn't get returned in the auth 1.1 service
-        catalog, so we build it from the servers url.
-        """
-
-        if self._auth_version == "1.1":
-            ep = self.service_catalog.get_endpoint(name="cloudServers")
-
-            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",
+        if '2.0' in self._auth_version:
+            ep = self.service_catalog.get_endpoint(name='cloudDNS',
+                                                   service_type='rax:dns',
                                                    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')
-
+        public_url = ep.get('publicURL', None)
 
-class RackspaceUSDNSConnection(RackspaceDNSConnection):
-    auth_url = AUTH_URL_US
+        # 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.dns.api',
+                                            'https://dns.api')
+        if self.region == 'uk':
+            # Old US account, which only has uk endpoint in the catalog
+            public_url = public_url.replace('https://dns.api',
+                                            'https://lon.dns.api')
 
-
-class RackspaceUKDNSConnection(RackspaceDNSConnection):
-    auth_url = AUTH_URL_UK
+        return public_url
 
 
 class RackspaceDNSDriver(DNSDriver, OpenStackDriverMixin):
+    name = 'Rackspace DNS'
     website = 'http://www.rackspace.com/'
+    type = Provider.RACKSPACE
+    connectionCls = RackspaceDNSConnection
 
-    def __init__(self, *args, **kwargs):
-        OpenStackDriverMixin.__init__(self, *args, **kwargs)
-        super(RackspaceDNSDriver, self).__init__(*args, **kwargs)
+    def __init__(self, key, secret=None, secure=True, host=None, port=None,
+                 region='us', **kwargs):
+        if region not in ['us', 'uk']:
+            raise ValueError('Invalid region: %s' % (region))
 
-    def _ex_connection_class_kwargs(self):
-        return self.openstack_connection_kwargs()
+        OpenStackDriverMixin.__init__(self, **kwargs)
+        super(RackspaceDNSDriver, self).__init__(key=key, secret=secret,
+                                                 host=host, port=port,
+                                                 region=region)
 
     RECORD_TYPE_MAP = {
         RecordType.A: 'A',
@@ -381,14 +383,25 @@ class RackspaceDNSDriver(DNSDriver, OpenStackDriverMixin):
         name = name.replace('.%s' % (domain), '')
         return name
 
+    def _ex_connection_class_kwargs(self):
+        kwargs = self.openstack_connection_kwargs()
+        kwargs['region'] = self.region
+        return kwargs
+
 
 class RackspaceUSDNSDriver(RackspaceDNSDriver):
     name = 'Rackspace DNS (US)'
     type = Provider.RACKSPACE_US
-    connectionCls = RackspaceUSDNSConnection
+
+    def __init__(self, *args, **kwargs):
+        kwargs['region'] = 'us'
+        super(RackspaceUSDNSDriver, self).__init__(*args, **kwargs)
 
 
 class RackspaceUKDNSDriver(RackspaceDNSDriver):
     name = 'Rackspace DNS (UK)'
     type = Provider.RACKSPACE_UK
-    connectionCls = RackspaceUKDNSConnection
+
+    def __init__(self, *args, **kwargs):
+        kwargs['region'] = 'uk'
+        super(RackspaceUKDNSDriver, self).__init__(*args, **kwargs)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0e7ffc9f/libcloud/dns/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/providers.py b/libcloud/dns/providers.py
index bdd704e..e3a0f82 100644
--- a/libcloud/dns/providers.py
+++ b/libcloud/dns/providers.py
@@ -24,16 +24,20 @@ DRIVERS = {
         ('libcloud.dns.drivers.linode', 'LinodeDNSDriver'),
     Provider.ZERIGO:
         ('libcloud.dns.drivers.zerigo', 'ZerigoDNSDriver'),
-    Provider.RACKSPACE_US:
-        ('libcloud.dns.drivers.rackspace', 'RackspaceUSDNSDriver'),
-    Provider.RACKSPACE_UK:
-        ('libcloud.dns.drivers.rackspace', 'RackspaceUKDNSDriver'),
+    Provider.RACKSPACE:
+        ('libcloud.dns.drivers.rackspace', 'RackspaceDNSDriver'),
     Provider.HOSTVIRTUAL:
         ('libcloud.dns.drivers.hostvirtual', 'HostVirtualDNSDriver'),
     Provider.ROUTE53:
         ('libcloud.dns.drivers.route53', 'Route53DNSDriver'),
     Provider.GANDI:
-        ('libcloud.dns.drivers.gandi', 'GandiDNSDriver')
+        ('libcloud.dns.drivers.gandi', 'GandiDNSDriver'),
+
+    # Deprecated
+    Provider.RACKSPACE_US:
+        ('libcloud.dns.drivers.rackspace', 'RackspaceUSDNSDriver'),
+    Provider.RACKSPACE_UK:
+        ('libcloud.dns.drivers.rackspace', 'RackspaceUKDNSDriver')
 }
 
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0e7ffc9f/libcloud/dns/types.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/types.py b/libcloud/dns/types.py
index 4698e5f..a08f1b0 100644
--- a/libcloud/dns/types.py
+++ b/libcloud/dns/types.py
@@ -30,13 +30,16 @@ __all__ = [
 class Provider(object):
     DUMMY = 'dummy'
     LINODE = 'linode'
+    RACKSPACE = 'rackspace'
     ZERIGO = 'zerigo'
-    RACKSPACE_US = 'rackspace_us'
-    RACKSPACE_UK = 'rackspace_uk'
     ROUTE53 = 'route53'
     HOSTVIRTUAL = 'hostvirtual'
     GANDI = 'gandi'
 
+    # Deprecated
+    RACKSPACE_US = 'rackspace_us'
+    RACKSPACE_UK = 'rackspace_uk'
+
 
 class RecordType(object):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0e7ffc9f/libcloud/test/dns/fixtures/rackspace/auth_2_0.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/rackspace/auth_2_0.json b/libcloud/test/dns/fixtures/rackspace/auth_2_0.json
deleted file mode 100644
index 05edc47..0000000
--- a/libcloud/test/dns/fixtures/rackspace/auth_2_0.json
+++ /dev/null
@@ -1,71 +0,0 @@
-{
-    "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"
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0e7ffc9f/libcloud/test/dns/test_rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_rackspace.py b/libcloud/test/dns/test_rackspace.py
index 48fec06..d3ca78e 100644
--- a/libcloud/test/dns/test_rackspace.py
+++ b/libcloud/test/dns/test_rackspace.py
@@ -30,6 +30,7 @@ from libcloud.test.secrets import DNS_PARAMS_RACKSPACE
 
 class RackspaceUSTests(unittest.TestCase):
     klass = RackspaceUSDNSDriver
+    endpoint_url = 'https://dns.api.rackspacecloud.com/v1.0/11111'
 
     def setUp(self):
         self.klass.connectionCls.conn_classes = (
@@ -70,8 +71,7 @@ class RackspaceUSTests(unittest.TestCase):
         driver = self.klass(*DNS_PARAMS_RACKSPACE, **kwargs)
         driver.connection._populate_hosts_and_request_paths()
 
-        self.assertEqual('https://dns.api.rackspacecloud.com/v1.0/11111',
-            driver.connection.get_endpoint())
+        self.assertEquals(self.endpoint_url, driver.connection.get_endpoint())
 
     def test_list_record_types(self):
         record_types = self.driver.list_record_types()
@@ -310,26 +310,14 @@ class RackspaceUSTests(unittest.TestCase):
                           'foo.bar')
 
 
-class RackspaceUK1Tests(RackspaceUSTests):
+class RackspaceUKTests(RackspaceUSTests):
     klass = RackspaceUKDNSDriver
-
+    endpoint_url = 'https://lon.dns.api.rackspacecloud.com/v1.0/11111'
 
 class RackspaceMockHttp(MockHttp):
     fixtures = DNSFileFixtures('rackspace')
     base_headers = {'content-type': 'application/json'}
 
-
-    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',
-                   'date': 'Sat, 29 Oct 2011 19:29:45 GMT',
-                   'content-type': 'application/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 = {