Update Rackspace DNS driver to use 'region' kwarg.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7e827a3c Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7e827a3c Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7e827a3c Branch: refs/heads/make_rackspace_drivers_multi_datacenter_aware Commit: 7e827a3ca347dac2ac2e265752f8be1abbd52fda Parents: 7a0c1e3 Author: Tomaz Muraus <[email protected]> Authored: Sun Jun 23 08:24:17 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Sun Jun 23 08:24:17 2013 +0200 ---------------------------------------------------------------------- libcloud/dns/drivers/rackspace.py | 64 +++++++++++++++++++++------------- libcloud/dns/providers.py | 12 ++++--- libcloud/dns/types.py | 7 ++-- 3 files changed, 53 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e827a3c/libcloud/dns/drivers/rackspace.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/drivers/rackspace.py b/libcloud/dns/drivers/rackspace.py index dd30171..c2b7173 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 @@ -76,6 +76,12 @@ class RackspaceDNSConnection(OpenStack_1_1_Connection, PollingConnection): XML_NAMESPACE = None 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'] @@ -97,45 +103,53 @@ class RackspaceDNSConnection(OpenStack_1_1_Connection, PollingConnection): 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 + 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.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): website = 'http://www.rackspace.com/' + name = 'Rackspace DNS' + type = Provider.RACKSPACE + connectionCls = RackspaceDNSConnection def __init__(self, *args, **kwargs): + region = kwargs.pop('region', 'us') + + if region not in ['us', 'uk']: + raise ValueError('Invalid region: %s' % (region)) + + self.region = region OpenStackDriverMixin.__init__(self, *args, **kwargs) super(RackspaceDNSDriver, self).__init__(*args, **kwargs) def _ex_connection_class_kwargs(self): - return self.openstack_connection_kwargs() + kwargs = {'region': self.region} + kwargs.update(self.openstack_connection_kwargs()) + return kwargs RECORD_TYPE_MAP = { RecordType.A: 'A', @@ -385,10 +399,12 @@ class RackspaceDNSDriver(DNSDriver, OpenStackDriverMixin): class RackspaceUSDNSDriver(RackspaceDNSDriver): name = 'Rackspace DNS (US)' type = Provider.RACKSPACE_US - connectionCls = RackspaceUSDNSConnection 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/7e827a3c/libcloud/dns/providers.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/providers.py b/libcloud/dns/providers.py index bdd704e..948a9b7 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: + Provider.RACKSPACE: ('libcloud.dns.drivers.rackspace', 'RackspaceUSDNSDriver'), - Provider.RACKSPACE_UK: - ('libcloud.dns.drivers.rackspace', 'RackspaceUKDNSDriver'), 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/7e827a3c/libcloud/dns/types.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/types.py b/libcloud/dns/types.py index 7acb1e4..5191088 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): """
