libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [06/15] libcloud git commit: Introduce new "list_region" class method in the base Driver class.
Date Wed, 06 Apr 2016 15:17:38 GMT
Introduce new "list_region" class method in the base Driver class.

This method is to be used with provider drivers which support multiple
regions and "region" constructor arguments. It allows users to enumerate
available regions.


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

Branch: refs/heads/trunk
Commit: 04dbe1891f7e3c90c5f5890f67d4f41c54f3a23b
Parents: 94d1baa
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Thu Mar 31 18:50:34 2016 -0700
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Thu Mar 31 19:10:49 2016 -0700

----------------------------------------------------------------------
 CHANGES.rst                                | 20 +++++++++++++-------
 libcloud/common/base.py                    |  9 +++++++++
 libcloud/compute/drivers/ec2.py            |  7 ++++++-
 libcloud/dns/drivers/rackspace.py          |  7 ++++++-
 libcloud/loadbalancer/drivers/rackspace.py |  3 +++
 libcloud/storage/drivers/cloudfiles.py     |  4 ++++
 6 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 6b3048f..b8c2457 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -29,6 +29,19 @@ General
   (GITHUB-711, GITHUB-714, LIBCLOUD-803)
   [Tomaz Muraus, Scott Crunkleton]
 
+* Remove deprecated provider constants with the region in the name and related
+  driver classes (e.g. ``EC2_US_EAST``, etc.).
+
+  Those drivers have moved to single provider constant + ``region`` constructor
+  argument model.
+  [Tomaz Muraus]
+
+* Introduce new `list_regions`` class method on the base driver class. This
+  method is to be used with provider drivers which support multiple regions and
+  ``region`` constructor argument. It allows users to enumerate available /
+  supported regions.
+  [Tomaz Muraus]
+
 Compute
 ~~~~~~~
 
@@ -107,13 +120,6 @@ Compute
   (LIBCLOUD-802, GITHUB-712)
   [Sam Song]
 
-* Remove deprecated provider constants with the region in the name and related
-  driver classes (e.g. `EC2_US_EAST``, etc.).
-
-  Those drivers have moved to single provider constant + ``region`` constructor
-  argument model.
-  [Tomaz Muraus]
-
 Storage
 ~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 1f353ab..0cdb257 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -1162,6 +1162,15 @@ class BaseDriver(object):
         self.connection.driver = self
         self.connection.connect()
 
+    @classmethod
+    def list_regions(cls):
+        """
+        Method which returns a list of the available / supported regions.
+
+        :rtype: ``list`` of ``str``
+        """
+        return []
+
     def _ex_connection_class_kwargs(self):
         """
         Return extra connection keyword arguments which are passed to the

http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 9ac4793..f21b49e 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -6321,7 +6321,8 @@ class EC2NodeDriver(BaseEC2NodeDriver):
         if hasattr(self, '_region'):
             region = self._region
 
-        if region not in VALID_EC2_REGIONS:
+        valid_regions = self.list_regions()
+        if region not in valid_regions:
             raise ValueError('Invalid region: %s' % (region))
 
         details = REGION_DETAILS[region]
@@ -6337,6 +6338,10 @@ class EC2NodeDriver(BaseEC2NodeDriver):
                                             secure=secure, host=host,
                                             port=port, **kwargs)
 
+    @classmethod
+    def list_regions(cls):
+        return VALID_EC2_REGIONS
+
 
 class IdempotentParamError(LibcloudError):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/libcloud/dns/drivers/rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/rackspace.py b/libcloud/dns/drivers/rackspace.py
index 4e0d705..6d231e0 100644
--- a/libcloud/dns/drivers/rackspace.py
+++ b/libcloud/dns/drivers/rackspace.py
@@ -162,7 +162,8 @@ class RackspaceDNSDriver(DNSDriver, OpenStackDriverMixin):
 
     def __init__(self, key, secret=None, secure=True, host=None, port=None,
                  region='us', **kwargs):
-        if region not in ['us', 'uk']:
+        valid_regions = self.list_regions()
+        if region not in valid_regions:
             raise ValueError('Invalid region: %s' % (region))
 
         OpenStackDriverMixin.__init__(self, **kwargs)
@@ -181,6 +182,10 @@ class RackspaceDNSDriver(DNSDriver, OpenStackDriverMixin):
         RecordType.TXT: 'TXT',
     }
 
+    @classmethod
+    def list_regions(cls):
+        return ['us', 'uk']
+
     def iterate_zones(self):
         offset = 0
         limit = 100

http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/libcloud/loadbalancer/drivers/rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/rackspace.py b/libcloud/loadbalancer/drivers/rackspace.py
index 898c0bc..a24e516 100644
--- a/libcloud/loadbalancer/drivers/rackspace.py
+++ b/libcloud/loadbalancer/drivers/rackspace.py
@@ -324,6 +324,9 @@ class RackspaceLBDriver(Driver, OpenStackDriverMixin):
         super(RackspaceLBDriver, self).__init__(key=key, secret=secret,
                                                 secure=secure, host=host,
                                                 port=port, region=region)
+    @classmethod
+    def list_regions(cls):
+        return ENDPOINT_ARGS_MAP.keys()
 
     def _ex_connection_class_kwargs(self):
         endpoint_args = ENDPOINT_ARGS_MAP[self.region]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/04dbe189/libcloud/storage/drivers/cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py
index 16d6d16..2502d42 100644
--- a/libcloud/storage/drivers/cloudfiles.py
+++ b/libcloud/storage/drivers/cloudfiles.py
@@ -265,6 +265,10 @@ class CloudFilesStorageDriver(StorageDriver, OpenStackDriverMixin):
                                                       port=port, region=region,
                                                       **kwargs)
 
+    @classmethod
+    def list_regions(cls):
+        return ['ord', 'dfw', 'iad', 'lon', 'hkg', 'syd']
+
     def iterate_containers(self):
         response = self.connection.request('')
 


Mime
View raw message