Modify ElasticHosts driver to take region argument (w.i.p.).

Signed-off-by: Tomaz Muraus <[email protected]>


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

Branch: refs/heads/trunk
Commit: cafef12052f53235fe6d972bfa7b78f846f90aea
Parents: 296e073
Author: Michael <[email protected]>
Authored: Mon Aug 26 12:47:04 2013 -0400
Committer: Tomaz Muraus <[email protected]>
Committed: Thu Oct 17 20:33:21 2013 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/elastichosts.py | 100 +++++++++++++++-----------
 libcloud/compute/providers.py            |   9 +++
 libcloud/compute/types.py                |  10 ++-
 3 files changed, 73 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cafef120/libcloud/compute/drivers/elastichosts.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/elastichosts.py 
b/libcloud/compute/drivers/elastichosts.py
index ea801ee..a649984 100644
--- a/libcloud/compute/drivers/elastichosts.py
+++ b/libcloud/compute/drivers/elastichosts.py
@@ -19,7 +19,6 @@ ElasticHosts Driver
 
 from libcloud.compute.types import Provider
 from libcloud.compute.drivers.elasticstack import ElasticStackBaseNodeDriver
-from libcloud.compute.drivers.elasticstack import ElasticStackBaseConnection
 
 
 # API end-points
@@ -122,91 +121,106 @@ STANDARD_DRIVES = {
 }
 
 
-class ElasticHostsBaseConnection(ElasticStackBaseConnection):
-    host = API_ENDPOINTS[DEFAULT_ENDPOINT]['host']
+class ElasticHostsException(Exception):
+    def __str__(self):
+        return self.args[0]
 
+    def __repr__(self):
+        return "<ElasticHostsException '%s'>" % (self.args[0])
 
-class ElasticHostsBaseNodeDriver(ElasticStackBaseNodeDriver):
+
+class ElasticHostsNodeDriver(ElasticStackBaseNodeDriver):
+    """
+    Node Driver class for ElasticHosts
+    """
     type = Provider.ELASTICHOSTS
     api_name = 'elastichosts'
     name = 'ElasticHosts'
     website = 'http://www.elastichosts.com/'
-    connectionCls = ElasticHostsBaseConnection
     features = {"create_node": ["generates_password"]}
     _standard_drives = STANDARD_DRIVES
 
+    def __init__(self, key, secret=None, secure=True, host=None, port=None,
+                 region=None, **kwargs):
 
-class ElasticHostsUK1Connection(ElasticStackBaseConnection):
-    """
-    Connection class for the ElasticHosts driver for
-    the London Peer 1 end-point
-    """
+        if hasattr(self, '_region'):
+            region = self._region
 
-    host = API_ENDPOINTS['uk-1']['host']
+        if region is not None:
 
+            if region not in API_ENDPOINTS:
+                raise ValueError('Invalid region: %s' % (region))
 
-class ElasticHostsUK1NodeDriver(ElasticHostsBaseNodeDriver):
-    """
-    ElasticHosts node driver for the London Peer 1 end-point
-    """
-    connectionCls = ElasticHostsUK1Connection
+            self.region = region
+            self._host_argument_set = host is not None
+        elif region is None and host is None:
+            raise ValueError("ElasticHosts Driver requires at least a region 
or a host argument to be specified")
+
+        super(ElasticHostsNodeDriver, self).__init__(key=key, secret=secret,
+                                                     secure=secure, host=host,
+                                                     port=port, **kwargs)
 
+    def _ex_connection_class_kwargs(self):
+        """
+        Return the host value based the user supplied region
+        """
+        if self._host_argument_set:
+            return {}
+        else:
+            return {'host': API_ENDPOINTS[self.region]['host']}
 
-class ElasticHostsUK2Connection(ElasticStackBaseConnection):
+
+class ElasticHostsUK1NodeDriver(ElasticHostsNodeDriver):
     """
-    Connection class for the ElasticHosts driver for
-    the London Bluesquare end-point
+    ElasticHosts node driver for the London Peer 1 end-point
     """
-    host = API_ENDPOINTS['uk-2']['host']
+    _region = 'uk-1'
 
 
-class ElasticHostsUK2NodeDriver(ElasticHostsBaseNodeDriver):
+class ElasticHostsUK2NodeDriver(ElasticHostsNodeDriver):
     """
     ElasticHosts node driver for the London Bluesquare end-point
     """
-    connectionCls = ElasticHostsUK2Connection
+    _region = 'uk-2'
 
 
-class ElasticHostsUS1Connection(ElasticStackBaseConnection):
+class ElasticHostsUS1NodeDriver(ElasticHostsNodeDriver):
     """
-    Connection class for the ElasticHosts driver for
-    the San Antonio Peer 1 end-point
+    ElasticHosts node driver for the San Antonio Peer 1 end-point
     """
-    host = API_ENDPOINTS['us-1']['host']
+    _region = 'us-1'
 
 
-class ElasticHostsUS1NodeDriver(ElasticHostsBaseNodeDriver):
+class ElasticHostsUS2NodeDriver(ElasticHostsNodeDriver):
     """
-    ElasticHosts node driver for the San Antonio Peer 1 end-point
+    ElasticHosts node driver for the Los Angeles Peer 1 end-point
     """
-    connectionCls = ElasticHostsUS1Connection
+    _region = 'us-2'
 
 
-class ElasticHostsUS2Connection(ElasticStackBaseConnection):
+class ElasticHostsUS3NodeDriver(ElasticHostsNodeDriver):
     """
-    Connection class for the ElasticHosts driver for
-    the Los Angeles Peer 1 end-point
+    ElasticHosts node driver for the San Jose (Silicon Valley) end-point
     """
-    host = API_ENDPOINTS['us-2']['host']
+    _region = 'us-3'
 
 
-class ElasticHostsUS2NodeDriver(ElasticHostsBaseNodeDriver):
+class ElasticHostsCA1NodeDriver(ElasticHostsNodeDriver):
     """
-    ElasticHosts node driver for the Los Angeles Peer 1 end-point
+    ElasticHosts node driver for the Toronto Peer 1 end-point
     """
-    connectionCls = ElasticHostsUS2Connection
+    _region = 'ca-1'
 
 
-class ElasticHostsCA1Connection(ElasticStackBaseConnection):
+class ElasticHostsAU1NodeDriver(ElasticHostsNodeDriver):
     """
-    Connection class for the ElasticHosts driver for
-    the Toronto Peer 1 end-point
+    ElasticHosts node driver for the Sydney end-point
     """
-    host = API_ENDPOINTS['ca-1']['host']
+    _region = 'au-1'
 
 
-class ElasticHostsCA1NodeDriver(ElasticHostsBaseNodeDriver):
+class ElasticHostsCN1NodeDriver(ElasticHostsNodeDriver):
     """
-    ElasticHosts node driver for the Toronto Peer 1 end-point
+    ElasticHosts node driver for the Hong Kong end-point
     """
-    connectionCls = ElasticHostsCA1Connection
+    _region = 'cn-1'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cafef120/libcloud/compute/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/providers.py b/libcloud/compute/providers.py
index 32c60d6..82aa75a 100644
--- a/libcloud/compute/providers.py
+++ b/libcloud/compute/providers.py
@@ -47,6 +47,8 @@ DRIVERS = {
         ('libcloud.compute.drivers.ec2', 'EC2APSESydneyNodeDriver'),
     Provider.ECP:
         ('libcloud.compute.drivers.ecp', 'ECPNodeDriver'),
+    Provider.ELASTICHOSTS:
+        ('libcloud.compute.drivers.elastichosts', 'ElasticHostsNodeDriver'),
     Provider.ELASTICHOSTS_UK1:
         ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUK1NodeDriver'),
     Provider.ELASTICHOSTS_UK2:
@@ -55,8 +57,14 @@ DRIVERS = {
         ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS1NodeDriver'),
     Provider.ELASTICHOSTS_US2:
         ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS2NodeDriver'),
+    Provider.ELASTICHOSTS_US3:
+        ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS3NodeDriver'),
     Provider.ELASTICHOSTS_CA1:
         ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCA1NodeDriver'),
+    Provider.ELASTICHOSTS_AU1:
+        ('libcloud.compute.drivers.elastichosts', 'ElasticHostsAU1NodeDriver'),
+    Provider.ELASTICHOSTS_CN1:
+        ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCN1NodeDriver'),
     Provider.SKALICLOUD:
         ('libcloud.compute.drivers.skalicloud', 'SkaliCloudNodeDriver'),
     Provider.SERVERLOVE:
@@ -146,5 +154,6 @@ def get_driver(provider):
 
     return _get_provider_driver(DRIVERS, provider)
 
+
 def set_driver(provider, module, klass):
     return _set_provider_driver(DRIVERS, provider, module, klass)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cafef120/libcloud/compute/types.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py
index aefbf5a..bae12ef 100644
--- a/libcloud/compute/types.py
+++ b/libcloud/compute/types.py
@@ -32,7 +32,7 @@ __all__ = [
     "InvalidCredsException",
     "DEPRECATED_RACKSPACE_PROVIDERS",
     "OLD_CONSTANT_TO_NEW_MAPPING"
-    ]
+]
 
 
 class Provider(object):
@@ -56,6 +56,7 @@ class Provider(object):
     :cvar IBM: IBM Developer Cloud
     :cvar OPENNEBULA: OpenNebula.org
     :cvar DREAMHOST: DreamHost Private Server
+    :cvar ELASTICHOSTS: ElasticHosts.com
     :cvar CLOUDSIGMA: CloudSigma
     :cvar NIMBUS: Nimbus
     :cvar BLUEBOX: Bluebox
@@ -94,6 +95,11 @@ class Provider(object):
     ELASTICHOSTS_UK1 = 'elastichosts_uk1'
     ELASTICHOSTS_UK2 = 'elastichosts_uk2'
     ELASTICHOSTS_US1 = 'elastichosts_us1'
+    ELASTICHOSTS_US2 = 'elastichosts_us2'
+    ELASTICHOSTS_US3 = 'elastichosts_us3'
+    ELASTICHOSTS_CA1 = 'elastichosts_ca1'
+    ELASTICHOSTS_AU1 = 'elastichosts_au1'
+    ELASTICHOSTS_CN1 = 'elastichosts_cn1'
     BRIGHTBOX = 'brightbox'
     CLOUDSIGMA = 'cloudsigma'
     NIMBUS = 'nimbus'
@@ -108,8 +114,6 @@ class Provider(object):
     CLOUDSTACK = 'cloudstack'
     CLOUDSIGMA_US = 'cloudsigma_us'
     LIBVIRT = 'libvirt'
-    ELASTICHOSTS_US2 = 'elastichosts_us2'
-    ELASTICHOSTS_CA1 = 'elastichosts_ca1'
     JOYENT = 'joyent'
     VCL = 'vcl'
     KTUCLOUD = 'ktucloud'

Reply via email to