libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1103109 - in /incubator/libcloud/trunk: libcloud/loadbalancer/drivers/gogrid.py libcloud/loadbalancer/drivers/rackspace.py test/loadbalancer/test_gogrid.py test/loadbalancer/test_rackspace.py
Date Sat, 14 May 2011 13:31:38 GMT
Author: tomaz
Date: Sat May 14 13:31:38 2011
New Revision: 1103109

URL: http://svn.apache.org/viewvc?rev=1103109&view=rev
Log:
Update create_balancer method in the GoGrid driver.

Modified:
    incubator/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py
    incubator/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
    incubator/libcloud/trunk/test/loadbalancer/test_gogrid.py
    incubator/libcloud/trunk/test/loadbalancer/test_rackspace.py

Modified: incubator/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py?rev=1103109&r1=1103108&r2=1103109&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py Sat May 14 13:31:38 2011
@@ -19,7 +19,7 @@ from libcloud.common.types import Libclo
 from libcloud.utils import reverse_dict
 from libcloud.common.gogrid import GoGridConnection, BaseGoGridDriver
 from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
-from libcloud.loadbalancer.base import DEFAULT_ALGORITHM 
+from libcloud.loadbalancer.base import DEFAULT_ALGORITHM
 from libcloud.loadbalancer.types import Provider, State, LibcloudLBImmutableError
 
 
@@ -37,15 +37,17 @@ class GoGridLBDriver(BaseGoGridDriver, D
     }
     _ALGORITHM_TO_VALUE_MAP = reverse_dict(_VALUE_TO_ALGORITHM_MAP)
 
+    def list_protocols(self):
+        # GoGrid only supports http
+        return [ 'http' ]
+
     def list_balancers(self):
         return self._to_balancers(
                 self.connection.request('/api/grid/loadbalancer/list').object)
 
-    def ex_create_balancer_nowait(self, name, port, algorithm, members):
-        if not algorithm:
-            algorithm = DEFAULT_ALGORITHM
-        else:
-            algorithm = self._algorithm_to_value(algorithm)
+    def ex_create_balancer_nowait(self, name, members, protocol='http', port=80,
+                                  algorithm=Algorithm.ROUND_ROBIN):
+        algorithm = self._algorithm_to_value(algorithm)
 
         params = {'name': name,
                   'loadbalancer.type': algorithm,
@@ -58,8 +60,10 @@ class GoGridLBDriver(BaseGoGridDriver, D
                 params=params)
         return self._to_balancers(resp.object)[0]
 
-    def create_balancer(self, name, port, algorithm, members):
-        balancer = self.ex_create_balancer_nowait(name, port, algorithm, members)
+    def create_balancer(self, name, members, protocol='http', port=80,
+                        algorithm=Algorithm.ROUND_ROBIN):
+        balancer = self.ex_create_balancer_nowait(name, members, protocol,
+                                                  port, algorithm)
 
         timeout = 60 * 20
         waittime = 0

Modified: incubator/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py?rev=1103109&r1=1103108&r2=1103109&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py (original)
+++ incubator/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py Sat May 14 13:31:38
2011
@@ -20,8 +20,9 @@ try:
 except ImportError:
     import simplejson as json
 
+from libcloud.utils import reverse_dict
 from libcloud.common.base import Response
-from libcloud.loadbalancer.base import LoadBalancer, Member, Driver
+from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
 from libcloud.loadbalancer.types import Provider, State
 from libcloud.common.rackspace import (AUTH_HOST_US,
         RackspaceBaseConnection)
@@ -71,19 +72,27 @@ class RackspaceLBDriver(Driver):
 
     LB_STATE_MAP = { 'ACTIVE': State.RUNNING,
                      'BUILD': State.PENDING }
+    _VALUE_TO_ALGORITHM_MAP = {
+        'RANDOM': Algorithm.RANDOM,
+        'ROUND_ROBIN': Algorithm.ROUND_ROBIN,
+        'LEAST_CONNECTIONS': Algorithm.LEAST_CONNECTIONS
+    }
+    _ALGORITHM_TO_VALUE_MAP = reverse_dict(_VALUE_TO_ALGORITHM_MAP)
 
     def list_balancers(self):
         return self._to_balancers(
                 self.connection.request('/loadbalancers').object)
 
-    def create_balancer(self, **kwargs):
-        name = kwargs['name']
-        port = kwargs['port']
-        members = kwargs['members']
+    def create_balancer(self, name, port, algorithm, members):
+        if not algorithm:
+            algorithm = DEFAULT_ALGORITHM
+        else:
+            algorithm = self._algorithm_to_value(algorithm)
 
         balancer_object = {"loadBalancer":
                 {"name": name,
                     "port": port,
+                    "algorithm": algorithm,
                     "protocol": "HTTP",
                     "virtualIps": [{"type": "PUBLIC"}],
                     "nodes": [{"address": member.ip,

Modified: incubator/libcloud/trunk/test/loadbalancer/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/loadbalancer/test_gogrid.py?rev=1103109&r1=1103108&r2=1103109&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/loadbalancer/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/loadbalancer/test_gogrid.py Sat May 14 13:31:38 2011
@@ -17,6 +17,12 @@ class GoGridTests(unittest.TestCase):
         GoGridLBMockHttp.type = None
         self.driver = GoGridLBDriver('user', 'key')
 
+    def test_list_protocols(self):
+        protocols = self.driver.list_protocols()
+
+        self.assertEqual(len(protocols), 1)
+        self.assertEqual(protocols[0], 'http')
+
     def test_list_balancers(self):
         balancers = self.driver.list_balancers()
 
@@ -29,9 +35,10 @@ class GoGridTests(unittest.TestCase):
     def test_create_balancer(self):
         balancer = self.driver.create_balancer(name='test2',
                 port=80,
+                protocol='http',
                 algorithm=Algorithm.ROUND_ROBIN,
                 members=(Member(None, '10.1.0.10', 80),
-                         Member(None, '10.1.0.11', 80))
+                    Member(None, '10.1.0.11', 80))
                 )
 
         self.assertEquals(balancer.name, 'test2')

Modified: incubator/libcloud/trunk/test/loadbalancer/test_rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/loadbalancer/test_rackspace.py?rev=1103109&r1=1103108&r2=1103109&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/loadbalancer/test_rackspace.py (original)
+++ incubator/libcloud/trunk/test/loadbalancer/test_rackspace.py Sat May 14 13:31:38 2011
@@ -3,7 +3,7 @@ import os.path
 import sys
 import unittest
 
-from libcloud.loadbalancer.base import Member
+from libcloud.loadbalancer.base import Member, Algorithm
 from libcloud.loadbalancer.drivers.rackspace import RackspaceLBDriver
 
 from test import MockHttp, MockRawResponse
@@ -29,6 +29,7 @@ class RackspaceLBTests(unittest.TestCase
     def test_create_balancer(self):
         balancer = self.driver.create_balancer(name='test2',
                 port=80,
+                algorithm=Algorithm.ROUND_ROBIN,
                 members=(Member(None, '10.1.0.10', 80),
                     Member(None, '10.1.0.11', 80))
                 )



Mime
View raw message