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 2012/08/01 01:07:37 UTC

svn commit: r1367815 - in /libcloud/trunk/libcloud: common/ loadbalancer/ loadbalancer/drivers/

Author: tomaz
Date: Tue Jul 31 23:07:36 2012
New Revision: 1367815

URL: http://svn.apache.org/viewvc?rev=1367815&view=rev
Log:
Update docstrings for LoadBalancer docstrings. Contributed by Ilgiz Islamgulov,
part of LIBCLOUD-238.

Modified:
    libcloud/trunk/libcloud/common/gogrid.py
    libcloud/trunk/libcloud/loadbalancer/base.py
    libcloud/trunk/libcloud/loadbalancer/drivers/brightbox.py
    libcloud/trunk/libcloud/loadbalancer/drivers/cloudstack.py
    libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py
    libcloud/trunk/libcloud/loadbalancer/drivers/ninefold.py
    libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
    libcloud/trunk/libcloud/loadbalancer/providers.py
    libcloud/trunk/libcloud/loadbalancer/types.py

Modified: libcloud/trunk/libcloud/common/gogrid.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/gogrid.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/gogrid.py (original)
+++ libcloud/trunk/libcloud/common/gogrid.py Tue Jul 31 23:07:36 2012
@@ -139,14 +139,17 @@ class BaseGoGridDriver(object):
                     private IPs. Set to None or not specify
                     at all not to filter by type
         @type       public: C{bool}
+
         @keyword    assigned: set to True to list only addresses
                     assigned to servers, False to list unassigned
                     addresses and set to None or don't set at all
                     not no filter by state
         @type       assigned: C{bool}
+
         @keyword    location: filter IP addresses by location
         @type       location: L{NodeLocation}
-        @return:    C{list} of L{GoGridIpAddress}es
+
+        @rtype: C{list} of L{GoGridIpAddress}
         """
 
         params = {}

Modified: libcloud/trunk/libcloud/loadbalancer/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/base.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/base.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/base.py Tue Jul 31 23:07:36 2012
@@ -17,11 +17,11 @@ from libcloud.common.base import Connect
 from libcloud.common.types import LibcloudError
 
 __all__ = [
-        "Member",
-        "LoadBalancer",
-        "Driver",
-        "Algorithm"
-        ]
+    "Member",
+    "LoadBalancer",
+    "Driver",
+    "Algorithm"
+]
 
 
 class Member(object):
@@ -34,7 +34,7 @@ class Member(object):
 
     def __repr__(self):
         return ('<Member: id=%s, address=%s:%s>' % (self.id,
-            self.ip, self.port))
+                                                    self.ip, self.port))
 
 
 class Algorithm(object):
@@ -52,6 +52,9 @@ class LoadBalancer(object):
     Provide a common interface for handling Load Balancers.
     """
 
+    name = None
+    website = None
+
     def __init__(self, id, name, state, ip, port, driver, extra=None):
         self.id = str(id) if id else None
         self.name = name
@@ -96,138 +99,167 @@ class Driver(BaseDriver):
     _ALGORITHM_TO_VALUE_MAP = {}
     _VALUE_TO_ALGORITHM_MAP = {}
 
-    def __init__(self, key, secret=None, secure=True, host=None, port=None, **kwargs):
+    def __init__(self, key, secret=None, secure=True, host=None,
+                 port=None, **kwargs):
         super(Driver, self).__init__(key=key, secret=secret, secure=secure,
                                      host=host, port=port, **kwargs)
 
     def list_protocols(self):
         """
         Return a list of supported protocols.
-        """
 
+        @rtype: C{list} of C{str}
+        """
         raise NotImplementedError(
-                'list_protocols not implemented for this driver')
+            'list_protocols not implemented for this driver')
 
     def list_balancers(self):
         """
         List all loadbalancers
 
-        @return: C{list} of L{LoadBalancer} objects
-
+        @rtype: C{list} of L{LoadBalancer}
         """
-
         raise NotImplementedError(
-                'list_balancers not implemented for this driver')
+            'list_balancers not implemented for this driver')
 
     def create_balancer(self, name, port, protocol, algorithm, members):
         """
         Create a new load balancer instance
 
-        @keyword name: Name of the new load balancer (required)
-        @type name: C{str}
-        @keyword members: C{list} ofL{Member}s to attach to balancer
-        @type: C{list} of L{Member}s
-        @keyword protocol: Loadbalancer protocol, defaults to http.
-        @type: C{str}
-        @keyword port: Port the load balancer should listen on, defaults to 80
-        @type port: C{str}
-        @keyword algorithm: Load balancing algorithm, defaults to
-                            LBAlgorithm.ROUND_ROBIN
-        @type algorithm: C{LBAlgorithm}
+        @param name: Name of the new load balancer (required)
+        @type  name: C{str}
 
-        """
+        @param port: Port the load balancer should listen on, defaults to 80
+        @type  port: C{str}
+
+        @param protocol: Loadbalancer protocol, defaults to http.
+        @type  protocol: C{str}
+
+        @param members: list of Members to attach to balancer
+        @type  members: C{list} of L{Member}
+
+        @param algorithm: Load balancing algorithm, defaults to ROUND_ROBIN
+        @type algorithm: L{Algorithm}
 
+        @rtype: L{LoadBalancer}
+        """
         raise NotImplementedError(
-                'create_balancer not implemented for this driver')
+            'create_balancer not implemented for this driver')
 
     def destroy_balancer(self, balancer):
         """Destroy a load balancer
 
-        @return: C{bool} True if the destroy was successful, otherwise False
+        @param balancer: LoadBalancer which should be used
+        @type  balancer: L{LoadBalancer}
 
+        @return: True if the destroy was successful, otherwise False
+        @rtype: C{bool}
         """
 
         raise NotImplementedError(
-                'destroy_balancer not implemented for this driver')
+            'destroy_balancer not implemented for this driver')
 
     def get_balancer(self, balancer_id):
         """
-        Return a C{LoadBalancer} object.
+        Return a L{LoadBalancer} object.
 
-        @keyword balancer_id: id of a load balancer you want to fetch
-        @type balancer_id: C{str}
+        @param balancer_id: id of a load balancer you want to fetch
+        @type  balancer_id: C{str}
 
-        @return: C{LoadBalancer}
+        @rtype: L{LoadBalancer}
         """
 
         raise NotImplementedError(
-                'get_balancer not implemented for this driver')
+            'get_balancer not implemented for this driver')
 
     def update_balancer(self, balancer, **kwargs):
         """
         Sets the name, algorithm, protocol, or port on a load balancer.
 
-        @keyword    name: New load balancer name
-        @type       metadata: C{str}
+        @param   balancer: LoadBalancer which should be used
+        @type    balancer: L{LoadBalancer}
+
+        @keyword name: New load balancer name
+        @type    name: C{str}
+
+        @keyword algorithm: New load balancer algorithm
+        @type    algorithm: L{Algorithm}
 
-        @keyword    algorithm: New load balancer algorithm
-        @type       metadata: C{libcloud.loadbalancer.base.Algorithm}
+        @keyword protocol: New load balancer protocol
+        @type    protocol: C{str}
 
-        @keyword    protocol: New load balancer protocol
-        @type       metadata: C{str}
+        @keyword port: New load balancer port
+        @type    port: C{int}
 
-        @keyword    port: New load balancer port
-        @type       metadata: C{int}
+        @rtype: L{LoadBalancer}
         """
         raise NotImplementedError(
-                'update_balancer not implemented for this driver')
+            'update_balancer not implemented for this driver')
 
     def balancer_attach_compute_node(self, balancer, node):
         """
         Attach a compute node as a member to the load balancer.
 
-        @keyword node: Member to join to the balancer
-        @type member: C{libcloud.compute.base.Node}
-        @return {Member} Member after joining the balancer.
+        @param balancer: LoadBalancer which should be used
+        @type  balancer: L{LoadBalancer}
+
+        @param node: Node to join to the balancer
+        @type  node: L{Node}
+
+        @return: Member after joining the balancer.
+        @rtype: L{Member}
         """
 
         return self.balancer_attach_member(balancer, Member(None,
-                                           node.public_ips[0],
-                                           balancer.port))
+                                                            node.public_ips[0],
+                                                            balancer.port))
 
     def balancer_attach_member(self, balancer, member):
         """
         Attach a member to balancer
 
-        @keyword member: Member to join to the balancer
-        @type member: C{Member}
-        @return {Member} Member after joining the balancer.
+        @param balancer: LoadBalancer which should be used
+        @type  balancer: L{LoadBalancer}
+
+        @param member: Member to join to the balancer
+        @type member: L{Member}
+
+        @return: Member after joining the balancer.
+        @rtype: L{Member}
         """
 
         raise NotImplementedError(
-                'balancer_attach_member not implemented for this driver')
+            'balancer_attach_member not implemented for this driver')
 
     def balancer_detach_member(self, balancer, member):
         """
         Detach member from balancer
 
-        @return: C{bool} True if member detach was successful, otherwise False
+        @param balancer: LoadBalancer which should be used
+        @type  balancer: L{LoadBalancer}
 
+        @param member: Member which should be used
+        @type member: L{Member}
+
+        @return: True if member detach was successful, otherwise False
+        @rtype: C{bool}
         """
 
         raise NotImplementedError(
-                'balancer_detach_member not implemented for this driver')
+            'balancer_detach_member not implemented for this driver')
 
     def balancer_list_members(self, balancer):
         """
         Return list of members attached to balancer
 
-        @return: C{list} of L{Member}s
+        @param balancer: LoadBalancer which should be used
+        @type  balancer: L{LoadBalancer}
 
+        @rtype: C{list} of L{Member}
         """
 
         raise NotImplementedError(
-                'balancer_list_members not implemented for this driver')
+            'balancer_list_members not implemented for this driver')
 
     def _value_to_algorithm(self, value):
         """
@@ -252,5 +284,7 @@ class Driver(BaseDriver):
     def list_supported_algorithms(self):
         """
         Return algorithms supported by this driver.
+
+        @rtype: C{list} of C{str}
         """
         return list(self._ALGORITHM_TO_VALUE_MAP.keys())

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/brightbox.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/brightbox.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/brightbox.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/brightbox.py Tue Jul 31 23:07:36 2012
@@ -28,6 +28,7 @@ class BrightboxLBDriver(Driver):
     connectionCls = BrightboxConnection
 
     name = 'Brightbox'
+    website = 'http://www.brightbox.co.uk/'
 
     LB_STATE_MAP = {
         'creating': State.PENDING,
@@ -55,13 +56,14 @@ class BrightboxLBDriver(Driver):
         return list(map(self._to_balancer, data))
 
     def create_balancer(self, name, port, protocol, algorithm, members):
-        response = self._post('/%s/load_balancers' % API_VERSION, {
-          'name': name,
-          'nodes': list(map(self._member_to_node, members)),
-          'policy': self._algorithm_to_value(algorithm),
-          'listeners': [{'in': port, 'out': port, 'protocol': protocol}],
-          'healthcheck': {'type': protocol, 'port': port}
-        })
+        response = self._post(
+            '/%s/load_balancers' % API_VERSION,
+            {'name': name,
+             'nodes': list(map(self._member_to_node, members)),
+             'policy': self._algorithm_to_value(algorithm),
+             'listeners': [{'in': port, 'out': port, 'protocol': protocol}],
+             'healthcheck': {'type': protocol, 'port': port}}
+        )
 
         return self._to_balancer(response.object)
 
@@ -73,9 +75,8 @@ class BrightboxLBDriver(Driver):
         return response.status == httplib.ACCEPTED
 
     def get_balancer(self, balancer_id):
-        data = self.connection.request('/%s/load_balancers/%s' % (API_VERSION,
-                                                         balancer_id)).object
-
+        data = self.connection.request(
+            '/%s/load_balancers/%s' % (API_VERSION, balancer_id)).object
         return self._to_balancer(data)
 
     def balancer_attach_compute_node(self, balancer, node):

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/cloudstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/cloudstack.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/cloudstack.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/cloudstack.py Tue Jul 31 23:07:36 2012
@@ -19,10 +19,13 @@ from libcloud.loadbalancer.base import D
 from libcloud.loadbalancer.types import State
 from libcloud.utils.misc import reverse_dict
 
+
 class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
     """Driver for CloudStack load balancers."""
 
     api_name = 'cloudstack_lb'
+    name = 'CloudStack'
+    website = 'http://cloudstack.org/'
 
     _VALUE_TO_ALGORITHM_MAP = {
         'roundrobin': Algorithm.ROUND_ROBIN,
@@ -34,9 +37,19 @@ class CloudStackLBDriver(CloudStackDrive
         'Active': State.RUNNING,
     }
 
+    def __init__(self, *args, **kwargs):
+        """
+        @inherits: L{Driver.__init__}
+        """
+        super(CloudStackLBDriver, self).__init__(*args, **kwargs)
+
     def list_protocols(self):
-        """We don't actually have any protocol awareness beyond TCP."""
-        return [ 'tcp' ]
+        """
+        We don't actually have any protocol awareness beyond TCP.
+
+        @rtype: C{list} of C{str}
+        """
+        return ['tcp']
 
     def list_balancers(self):
         balancers = self._sync_request('listLoadBalancerRules')
@@ -53,6 +66,15 @@ class CloudStackLBDriver(CloudStackDrive
     def create_balancer(self, name, members, protocol='http', port=80,
                         algorithm=DEFAULT_ALGORITHM, location=None,
                         private_port=None):
+        """
+        @inherits: L{Driver.create_balancer}
+
+        @param location: Location
+        @type  location: L{NodeLocation}
+
+        @param private_port: Private port
+        @type  private_port: C{int}
+        """
         if location is None:
             locations = self._sync_request('listZones')
             location = locations['zone'][0]['id']
@@ -64,7 +86,8 @@ class CloudStackLBDriver(CloudStackDrive
         result = self._async_request('associateIpAddress', zoneid=location)
         public_ip = result['ipaddress']
 
-        result = self._sync_request('createLoadBalancerRule',
+        result = self._sync_request(
+            'createLoadBalancerRule',
             algorithm=self._ALGORITHM_TO_VALUE_MAP[algorithm],
             name=name,
             privateport=private_port,

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/gogrid.py Tue Jul 31 23:07:36 2012
@@ -25,11 +25,13 @@ except ImportError:
 
 from libcloud.utils.misc import reverse_dict
 from libcloud.common.types import LibcloudError
-from libcloud.common.gogrid import GoGridConnection, GoGridResponse, BaseGoGridDriver
+from libcloud.common.gogrid import GoGridConnection, GoGridResponse,\
+    BaseGoGridDriver
 from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
 from libcloud.loadbalancer.base import DEFAULT_ALGORITHM
 from libcloud.loadbalancer.types import State, LibcloudLBImmutableError
 
+
 class GoGridLBResponse(GoGridResponse):
     def success(self):
         if self.status == httplib.INTERNAL_SERVER_ERROR:
@@ -37,42 +39,55 @@ class GoGridLBResponse(GoGridResponse):
             # "unexpected server error"
             body = json.loads(self.body)
             if body['method'] == '/grid/loadbalancer/add' and \
-               len(body['list']) >= 1 and \
-               body['list'][0]['message'].find('unexpected server error') != -1:
-                raise LibcloudError(value='You mostly likely tried to add a '
-                                         + 'member with an IP address not assigned '
-                                         +  'to your account', driver=self)
+                len(body['list']) >= 1 and \
+                body['list'][0]['message'].find(
+                    'unexpected server error') != -1:
+                raise LibcloudError(
+                    value='You mostly likely tried to add a member with an IP'
+                          ' address not assigned to your account', driver=self)
         return super(GoGridLBResponse, self).success()
 
+
 class GoGridLBConnection(GoGridConnection):
     """
     Connection class for the GoGrid load-balancer driver.
     """
     responseCls = GoGridLBResponse
 
+
 class GoGridLBDriver(BaseGoGridDriver, Driver):
     connectionCls = GoGridLBConnection
     api_name = 'gogrid_lb'
     name = 'GoGrid LB'
+    website = 'http://www.gogrid.com/'
 
-    LB_STATE_MAP = { 'On': State.RUNNING,
-                     'Unknown': State.UNKNOWN }
+    LB_STATE_MAP = {'On': State.RUNNING,
+                    'Unknown': State.UNKNOWN}
     _VALUE_TO_ALGORITHM_MAP = {
         'round robin': Algorithm.ROUND_ROBIN,
         'least connect': Algorithm.LEAST_CONNECTIONS
     }
     _ALGORITHM_TO_VALUE_MAP = reverse_dict(_VALUE_TO_ALGORITHM_MAP)
 
+    def __init__(self, *args, **kwargs):
+        """
+        @inherits: L{Driver.__init__}
+        """
+        super(GoGridLBDriver, self).__init__(*args, **kwargs)
+
     def list_protocols(self):
         # GoGrid only supports http
-        return [ 'http' ]
+        return ['http']
 
     def list_balancers(self):
         return self._to_balancers(
-                self.connection.request('/api/grid/loadbalancer/list').object)
+            self.connection.request('/api/grid/loadbalancer/list').object)
 
-    def ex_create_balancer_nowait(self, name, members, protocol='http', port=80,
-                                  algorithm=DEFAULT_ALGORITHM):
+    def ex_create_balancer_nowait(self, name, members, protocol='http',
+                                  port=80, algorithm=DEFAULT_ALGORITHM):
+        """
+        @inherits: L{Driver.create_balancer}
+        """
         algorithm = self._algorithm_to_value(algorithm)
 
         params = {'name': name,
@@ -82,8 +97,8 @@ class GoGridLBDriver(BaseGoGridDriver, D
         params.update(self._members_to_params(members))
 
         resp = self.connection.request('/api/grid/loadbalancer/add',
-                method='GET',
-                params=params)
+                                       method='GET',
+                                       params=params)
         return self._to_balancers(resp.object)[0]
 
     def create_balancer(self, name, members, protocol='http', port=80,
@@ -112,13 +127,14 @@ class GoGridLBDriver(BaseGoGridDriver, D
 
     def destroy_balancer(self, balancer):
         try:
-            resp = self.connection.request('/api/grid/loadbalancer/delete',
-                    method='POST', params={'id': balancer.id})
+            resp = self.connection.request(
+                '/api/grid/loadbalancer/delete', method='POST',
+                params={'id': balancer.id})
         except Exception:
             e = sys.exc_info()[1]
             if "Update request for LoadBalancer" in str(e):
-                raise LibcloudLBImmutableError("Cannot delete immutable object",
-                        GoGridLBDriver)
+                raise LibcloudLBImmutableError(
+                    "Cannot delete immutable object", GoGridLBDriver)
             else:
                 raise
 
@@ -134,7 +150,7 @@ class GoGridLBDriver(BaseGoGridDriver, D
             params['id'] = balancer_id
 
         resp = self.connection.request('/api/grid/loadbalancer/get',
-                params=params)
+                                       params=params)
 
         return self._to_balancers(resp.object)[0]
 
@@ -147,10 +163,9 @@ class GoGridLBDriver(BaseGoGridDriver, D
         params.update(self._members_to_params(members))
 
         resp = self._update_balancer(params)
-
-        return [ m for m in
+        return [m for m in
                 self._to_members(resp.object["list"][0]["realiplist"])
-                if m.ip == member.ip ][0]
+                if m.ip == member.ip][0]
 
     def balancer_detach_member(self, balancer, member):
         members = self.balancer_list_members(balancer)
@@ -166,18 +181,19 @@ class GoGridLBDriver(BaseGoGridDriver, D
 
     def balancer_list_members(self, balancer):
         resp = self.connection.request('/api/grid/loadbalancer/get',
-                params={'id': balancer.id})
+                                       params={'id': balancer.id})
         return self._to_members(resp.object["list"][0]["realiplist"])
 
     def _update_balancer(self, params):
         try:
             return self.connection.request('/api/grid/loadbalancer/edit',
-                    method='POST',
-                    params=params)
+                                           method='POST',
+                                           params=params)
         except Exception:
             e = sys.exc_info()[1]
             if "Update already pending" in str(e):
-                raise LibcloudLBImmutableError("Balancer is immutable", GoGridLBDriver)
+                raise LibcloudLBImmutableError(
+                    "Balancer is immutable", GoGridLBDriver)
 
         raise LibcloudError(value='Exception: %s' % str(e), driver=self)
 
@@ -199,23 +215,23 @@ class GoGridLBDriver(BaseGoGridDriver, D
         return params
 
     def _to_balancers(self, object):
-        return [ self._to_balancer(el) for el in object["list"] ]
+        return [self._to_balancer(el) for el in object["list"]]
 
     def _to_balancer(self, el):
         lb = LoadBalancer(id=el.get("id"),
-                name=el["name"],
-                state=self.LB_STATE_MAP.get(
-                    el["state"]["name"], State.UNKNOWN),
-                ip=el["virtualip"]["ip"]["ip"],
-                port=el["virtualip"]["port"],
-                driver=self.connection.driver)
+                          name=el["name"],
+                          state=self.LB_STATE_MAP.get(
+                              el["state"]["name"], State.UNKNOWN),
+                          ip=el["virtualip"]["ip"]["ip"],
+                          port=el["virtualip"]["port"],
+                          driver=self.connection.driver)
         return lb
 
     def _to_members(self, object):
-        return [ self._to_member(el) for el in object ]
+        return [self._to_member(el) for el in object]
 
     def _to_member(self, el):
         member = Member(id=el["ip"]["id"],
-                ip=el["ip"]["ip"],
-                port=el["port"])
+                        ip=el["ip"]["ip"],
+                        port=el["port"])
         return member

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/ninefold.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/ninefold.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/ninefold.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/ninefold.py Tue Jul 31 23:07:36 2012
@@ -17,6 +17,7 @@ from libcloud.loadbalancer.providers imp
 
 from libcloud.loadbalancer.drivers.cloudstack import CloudStackLBDriver
 
+
 class NinefoldLBDriver(CloudStackLBDriver):
     "Driver for load balancers on Ninefold's Compute platform."
 
@@ -25,3 +26,4 @@ class NinefoldLBDriver(CloudStackLBDrive
 
     type = Provider.NINEFOLD
     name = 'Ninefold LB'
+    website = 'http://ninefold.com/'

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py Tue Jul 31 23:07:36 2012
@@ -27,13 +27,12 @@ from libcloud.loadbalancer.base import D
 from libcloud.common.types import LibcloudError
 from libcloud.common.base import JsonResponse, PollingConnection
 from libcloud.loadbalancer.types import State, MemberCondition
-from libcloud.common.openstack import OpenStackBaseConnection, OpenStackDriverMixin
-from libcloud.common.rackspace import (
-        AUTH_URL_US, AUTH_URL_UK)
+from libcloud.common.openstack import OpenStackBaseConnection,\
+    OpenStackDriverMixin
+from libcloud.common.rackspace import (AUTH_URL_US, AUTH_URL_UK)
 
 
 class RackspaceResponse(JsonResponse):
-
     def parse_body(self):
         if not self.body:
             return None
@@ -51,7 +50,7 @@ class RackspaceHealthMonitor(object):
     @type type: C{str}
 
     @param delay: minimum seconds to wait before executing the health
-                  monitor.  (Must be between 1 and 3600)
+                      monitor.  (Must be between 1 and 3600)
     @type delay: C{int}
 
     @param timeout: maximum seconds to wait when establishing a
@@ -105,8 +104,8 @@ class RackspaceHTTPHealthMonitor(Rackspa
 
     def __init__(self, type, delay, timeout, attempts_before_deactivation,
                  path, body_regex, status_regex):
-        super(RackspaceHTTPHealthMonitor, self).__init__(type, delay, timeout,
-            attempts_before_deactivation)
+        super(RackspaceHTTPHealthMonitor, self).__init__(
+            type, delay, timeout, attempts_before_deactivation)
         self.path = path
         self.body_regex = body_regex
         self.status_regex = status_regex
@@ -209,7 +208,7 @@ class RackspaceAccessRule(object):
         self.address = address
 
     def _to_dict(self):
-        type_string = \
+        type_string =\
             RackspaceAccessRuleType._RULE_TYPE_STRING_MAP[self.rule_type]
 
         as_dict = {
@@ -249,8 +248,9 @@ class RackspaceConnection(OpenStackBaseC
         if method == 'GET':
             self._add_cache_busting_to_params(params)
 
-        return super(RackspaceConnection, self).request(action=action,
-                params=params, data=data, method=method, headers=headers)
+        return super(RackspaceConnection, self).request(
+            action=action, params=params,
+            data=data, method=method, headers=headers)
 
     def get_poll_request_kwargs(self, response, context, request_kwargs):
         return {'action': request_kwargs['action'],
@@ -274,16 +274,18 @@ class RackspaceConnection(OpenStackBaseC
         if self._auth_version == "1.1":
             ep = self.service_catalog.get_endpoint(name="cloudServers")
 
-            return self._construct_loadbalancer_endpoint_from_servers_endpoint(ep)
+            return self._construct_loadbalancer_endpoint_from_servers_endpoint(
+                ep)
         elif "2.0" in self._auth_version:
             ep = self.service_catalog.get_endpoint(name="cloudServers",
-                service_type="compute",
-                region=None)
+                                                   service_type="compute",
+                                                   region=None)
 
-            return self._construct_loadbalancer_endpoint_from_servers_endpoint(ep)
+            return self._construct_loadbalancer_endpoint_from_servers_endpoint(
+                ep)
         else:
-            raise LibcloudError("Auth version %s not supported" % \
-                self._auth_version)
+            raise LibcloudError(
+                "Auth version %s not supported" % self._auth_version)
 
     def _construct_loadbalancer_endpoint_from_servers_endpoint(self, ep):
         if 'publicURL' in ep:
@@ -301,6 +303,7 @@ class RackspaceLBDriver(Driver, OpenStac
     connectionCls = RackspaceConnection
     api_name = 'rackspace_lb'
     name = 'Rackspace LB'
+    website = 'http://www.rackspace.com/'
 
     LB_STATE_MAP = {
         'ACTIVE': State.RUNNING,
@@ -343,19 +346,22 @@ class RackspaceLBDriver(Driver, OpenStac
 
     def list_protocols(self):
         return self._to_protocols(
-                   self.connection.request('/loadbalancers/protocols').object)
+            self.connection.request('/loadbalancers/protocols').object)
 
     def ex_list_protocols_with_default_ports(self):
         """
-        @rtype: C{list} of tuples of protocols (C{str}) with default ports
-        (C{int}).
+        List protocols with default ports.
+
+        @rtype: C{list} of C{tuple}
         @return: A list of protocols with default ports included.
         """
         return self._to_protocols_with_default_ports(
-                   self.connection.request('/loadbalancers/protocols').object)
+            self.connection.request('/loadbalancers/protocols').object)
 
     def list_balancers(self, ex_member_address=None):
         """
+        @inherits: L{Driver.list_balancers}
+
         @param ex_member_address: Optional IP address of the attachment member.
                                   If provided, only the load balancers which
                                   have this member attached will be returned.
@@ -367,8 +373,7 @@ class RackspaceLBDriver(Driver, OpenStac
             params['nodeaddress'] = ex_member_address
 
         return self._to_balancers(
-                self.connection.request('/loadbalancers', params=params)
-                    .object)
+            self.connection.request('/loadbalancers', params=params).object)
 
     def create_balancer(self, name, members, protocol='http',
                         port=80, algorithm=DEFAULT_ALGORITHM):
@@ -380,25 +385,27 @@ class RackspaceLBDriver(Driver, OpenStac
         """
         Creates a new load balancer instance
 
-        @keyword name: Name of the new load balancer (required)
-        @type name: C{str}
+        @param name: Name of the new load balancer (required)
+        @type  name: C{str}
 
-        @keyword members: C{list} ofL{Member}s to attach to balancer
-        @type: C{list} of L{Member}s
+        @param members: C{list} ofL{Member}s to attach to balancer
+        @type  members: C{list} of L{Member}
 
-        @keyword protocol: Loadbalancer protocol, defaults to http.
-        @type: C{str}
+        @param protocol: Loadbalancer protocol, defaults to http.
+        @type  protocol: C{str}
 
-        @keyword port: Port the load balancer should listen on, defaults to 80
-        @type port: C{str}
+        @param port: Port the load balancer should listen on, defaults to 80
+        @type  port: C{str}
 
-        @keyword algorithm: Load balancing algorithm, defaults to
+        @param algorithm: Load balancing algorithm, defaults to
                             LBAlgorithm.ROUND_ROBIN
-        @type algorithm: C{LBAlgorithm}
+        @type  algorithm: L{Algorithm}
 
-        @keyword vip: Virtual ip type of PUBLIC, SERVICENET, or ID of a virtual
+        @param vip: Virtual ip type of PUBLIC, SERVICENET, or ID of a virtual
                       ip
-        @type vip: C{str}
+        @type  vip: C{str}
+
+        @rtype: L{LoadBalancer}
         """
         balancer_attrs = self._kwargs_to_mutable_attrs(
             name=name,
@@ -409,7 +416,7 @@ class RackspaceLBDriver(Driver, OpenStac
 
         balancer_attrs.update({
             'nodes': [self._member_attributes(member) for member in members],
-            })
+        })
         balancer_object = {"loadBalancer": balancer_attrs}
 
         resp = self.connection.request('/loadbalancers',
@@ -427,8 +434,8 @@ class RackspaceLBDriver(Driver, OpenStac
         # If the condition is not specified on the member, then it should be
         # set to ENABLED by default
         if 'condition' not in member_attributes:
-            member_attributes['condition'] = \
-            self.CONDITION_LB_MEMBER_MAP[MemberCondition.ENABLED]
+            member_attributes['condition'] =\
+                self.CONDITION_LB_MEMBER_MAP[MemberCondition.ENABLED]
 
         return member_attributes
 
@@ -443,15 +450,15 @@ class RackspaceLBDriver(Driver, OpenStac
         Destroys a list of Balancers (the API supports up to 10).
 
         @param balancers: A list of Balancers to destroy.
-        @type balancers: C{list}
+        @type balancers: C{list} of L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the destroy request was accepted.
+        @rtype: C{bool}
         """
         ids = [('id', balancer.id) for balancer in balancers]
         resp = self.connection.request('/loadbalancers',
-            method='DELETE',
-            params=ids)
+                                       method='DELETE',
+                                       params=ids)
 
         return resp.status == httplib.ACCEPTED
 
@@ -466,7 +473,7 @@ class RackspaceLBDriver(Driver, OpenStac
 
         uri = '/loadbalancers/%s/nodes' % (balancer.id)
         resp = self.connection.request(uri, method='POST',
-                data=json.dumps(member_object))
+                                       data=json.dumps(member_object))
         return self._to_members(resp.object)[0]
 
     def ex_balancer_attach_members(self, balancer, members):
@@ -474,17 +481,19 @@ class RackspaceLBDriver(Driver, OpenStac
         Attaches a list of members to a load balancer.
 
         @param balancer: The Balancer to which members will be attached.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param members: A list of Members to attach.
-        @type members: C{list}
+        @type  members: C{list} of L{Member}
+
+        @rtype: C{list} of L{Member}
         """
         member_objects = {"nodes": [self._member_attributes(member) for member
                                     in members]}
 
         uri = '/loadbalancers/%s/nodes' % (balancer.id)
         resp = self.connection.request(uri, method='POST',
-                data=json.dumps(member_objects))
+                                       data=json.dumps(member_objects))
         return self._to_members(resp.object)
 
     def balancer_detach_member(self, balancer, member):
@@ -503,13 +512,13 @@ class RackspaceLBDriver(Driver, OpenStac
         balancer is in a RUNNING state again.
 
         @param balancer: The Balancer to detach members from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param members: A list of Members to detach.
-        @type members: C{list}
+        @type  members: C{list} of L{Member}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         accepted = self.ex_balancer_detach_members_no_poll(balancer, members)
 
@@ -525,13 +534,13 @@ class RackspaceLBDriver(Driver, OpenStac
         This method returns immediately.
 
         @param balancer: The Balancer to detach members from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param members: A list of Members to detach.
-        @type members: C{list}
+        @type  members: C{list} of L{Member}
 
-        @rtype: C{bool}
         @return: Returns whether the detach request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/nodes' % (balancer.id)
         ids = [('id', member.id) for member in members]
@@ -542,22 +551,27 @@ class RackspaceLBDriver(Driver, OpenStac
     def balancer_list_members(self, balancer):
         uri = '/loadbalancers/%s/nodes' % (balancer.id)
         return self._to_members(
-                self.connection.request(uri).object)
+            self.connection.request(uri).object)
 
     def update_balancer(self, balancer, **kwargs):
         attrs = self._kwargs_to_mutable_attrs(**kwargs)
         resp = self.connection.async_request(
-                    action='/loadbalancers/%s' % balancer.id,
-                    method='PUT',
-                    data=json.dumps(attrs))
+            action='/loadbalancers/%s' % balancer.id,
+            method='PUT',
+            data=json.dumps(attrs))
         return self._to_balancer(resp.object["loadBalancer"])
 
     def ex_update_balancer_no_poll(self, balancer, **kwargs):
+        """
+        Update balancer no poll.
+
+        @inherits: L{Driver.update_balancer}
+        """
         attrs = self._kwargs_to_mutable_attrs(**kwargs)
         resp = self.connection.request(
-                    action='/loadbalancers/%s' % balancer.id,
-                    method='PUT',
-                    data=json.dumps(attrs))
+            action='/loadbalancers/%s' % balancer.id,
+            method='PUT',
+            data=json.dumps(attrs))
         return resp.status == httplib.ACCEPTED
 
     def ex_balancer_update_member(self, balancer, member, **kwargs):
@@ -568,17 +582,20 @@ class RackspaceLBDriver(Driver, OpenStac
         again.
 
         @param balancer: Balancer to update the member on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
+
+        @param member: Member which should be used
+        @type member: L{Member}
 
-        @param **kwargs: New attributes.  Should contain either 'weight'
+        @keyword **kwargs: New attributes.  Should contain either 'weight'
         or 'condition'.  'condition' can be set to 'ENABLED', 'DISABLED'.
         or 'DRAINING'.  'weight' can be set to a positive integer between
         1 and 100, with a higher weight indicating that the node will receive
         more traffic (assuming the Balancer is using a weighted algorithm).
         @type **kwargs: C{dict}
 
-        @rtype: C{Member}
         @return: Updated Member.
+        @rtype: L{Member}
         """
         accepted = self.ex_balancer_update_member_no_poll(
             balancer, member, **kwargs)
@@ -603,17 +620,20 @@ class RackspaceLBDriver(Driver, OpenStac
         include 'weight' or 'condition'.  This method returns immediately.
 
         @param balancer: Balancer to update the member on.
-        @type balancer: C{Balancer}
+        @type balancer: L{LoadBalancer}
 
-        @param **kwargs: New attributes.  Should contain either 'weight'
+        @param member: Member which should be used
+        @type member: L{Member}
+
+        @keyword **kwargs: New attributes.  Should contain either 'weight'
         or 'condition'.  'condition' can be set to 'ENABLED', 'DISABLED'.
         or 'DRAINING'.  'weight' can be set to a positive integer between
         1 and 100, with a higher weight indicating that the node will receive
         more traffic (assuming the Balancer is using a weighted algorithm).
         @type **kwargs: C{dict}
 
-        @rtype: C{bool}
         @return: Returns whether the update request was accepted.
+        @rtype: C{bool}
         """
         resp = self.connection.request(
             action='/loadbalancers/%s/nodes/%s' % (balancer.id, member.id),
@@ -627,17 +647,35 @@ class RackspaceLBDriver(Driver, OpenStac
         """
         Lists algorithms supported by the API.  Returned as strings because
         this list may change in the future.
+
+        @rtype: C{list} of C{str}
         """
         response = self.connection.request('/loadbalancers/algorithms')
         return [a["name"].upper() for a in response.object["algorithms"]]
 
     def ex_get_balancer_error_page(self, balancer):
+        """
+        List error page configured for the specified load balancer.
+
+        @param balancer: Balancer which should be used
+        @type balancer: L{LoadBalancer}
+
+        @rtype: C{str}
+        """
         uri = '/loadbalancers/%s/errorpage' % (balancer.id)
         resp = self.connection.request(uri)
 
         return resp.object["errorpage"]["content"]
 
     def ex_balancer_access_list(self, balancer):
+        """
+        List the access list.
+
+        @param balancer: Balancer which should be used
+        @type balancer: L{LoadBalancer}
+
+        @rtype: C{list} of L{RackspaceAccessRuleType}
+        """
         uri = '/loadbalancers/%s/accesslist' % (balancer.id)
         resp = self.connection.request(uri)
 
@@ -663,16 +701,16 @@ class RackspaceLBDriver(Driver, OpenStac
         again.
 
         @param balancer: Balancer to update.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param health_monitor: Health Monitor for the balancer.
-        @type health_monitor: C{RackspaceHealthMonitor}
+        @type  health_monitor: L{RackspaceHealthMonitor}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
-        accepted = self.ex_update_balancer_health_monitor_no_poll(balancer,
-                    health_monitor)
+        accepted = self.ex_update_balancer_health_monitor_no_poll(
+            balancer, health_monitor)
         if not accepted:
             msg = 'Update health monitor request not accepted'
             raise LibcloudError(msg, driver=self)
@@ -685,19 +723,18 @@ class RackspaceLBDriver(Driver, OpenStac
         Sets a Balancer's health monitor.  This method returns immediately.
 
         @param balancer: Balancer to update health monitor on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param health_monitor: Health Monitor for the balancer.
-        @type health_monitor: C{RackspaceHealthMonitor}
+        @type  health_monitor: L{RackspaceHealthMonitor}
 
-        @rtype: C{bool}
         @return: Returns whether the update request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/healthmonitor' % (balancer.id)
 
-        resp = self.connection.request(uri,
-            method='PUT',
-            data=json.dumps(health_monitor._to_dict()))
+        resp = self.connection.request(
+            uri, method='PUT', data=json.dumps(health_monitor._to_dict()))
 
         return resp.status == httplib.ACCEPTED
 
@@ -708,10 +745,10 @@ class RackspaceLBDriver(Driver, OpenStac
         state again.
 
         @param balancer: Balancer to disable health monitor on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_disable_balancer_health_monitor_no_poll(balancer):
             msg = 'Disable health monitor request not accepted'
@@ -725,15 +762,15 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to disable health monitor on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the disable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/healthmonitor' % (balancer.id)
 
         resp = self.connection.request(uri,
-            method='DELETE')
+                                       method='DELETE')
 
         return resp.status == httplib.ACCEPTED
 
@@ -745,13 +782,13 @@ class RackspaceLBDriver(Driver, OpenStac
         RUNNING state again.
 
         @param balancer: Balancer to update connection throttle on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param connection_throttle: Connection Throttle for the balancer.
-        @type connection_throttle: C{RackspaceConnectionThrottle}
+        @type  connection_throttle: L{RackspaceConnectionThrottle}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         accepted = self.ex_update_balancer_connection_throttle_no_poll(
             balancer, connection_throttle)
@@ -769,16 +806,17 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to update connection throttle on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param connection_throttle: Connection Throttle for the balancer.
-        @type connection_throttle: C{RackspaceConnectionThrottle}
+        @type  connection_throttle: L{RackspaceConnectionThrottle}
 
-        @rtype: C{bool}
         @return: Returns whether the update request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/connectionthrottle' % (balancer.id)
-        resp = self.connection.request(uri, method='PUT',
+        resp = self.connection.request(
+            uri, method='PUT',
             data=json.dumps(connection_throttle._to_dict()))
 
         return resp.status == httplib.ACCEPTED
@@ -790,10 +828,10 @@ class RackspaceLBDriver(Driver, OpenStac
         state again.
 
         @param balancer: Balancer to disable connection throttle on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_disable_balancer_connection_throttle_no_poll(balancer):
             msg = 'Disable connection throttle request not accepted'
@@ -807,10 +845,10 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to disable connection throttle on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the disable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/connectionthrottle' % (balancer.id)
         resp = self.connection.request(uri, method='DELETE')
@@ -824,10 +862,10 @@ class RackspaceLBDriver(Driver, OpenStac
         state again.
 
         @param balancer: Balancer to enable connection logging on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_enable_balancer_connection_logging_no_poll(balancer):
             msg = 'Enable connection logging request not accepted'
@@ -841,19 +879,17 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to enable connection logging on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the enable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/connectionlogging' % (balancer.id)
 
-        resp = self.connection.request(uri, method='PUT',
-            data=json.dumps({
-            'connectionLogging': {
-                'enabled': True
-            }
-        }))
+        resp = self.connection.request(
+            uri, method='PUT',
+            data=json.dumps({'connectionLogging': {'enabled': True}})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -864,10 +900,10 @@ class RackspaceLBDriver(Driver, OpenStac
         state again.
 
         @param balancer: Balancer to disable connection logging on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_disable_balancer_connection_logging_no_poll(balancer):
             msg = 'Disable connection logging request not accepted'
@@ -881,18 +917,16 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to disable connection logging on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the disable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/connectionlogging' % (balancer.id)
-        resp = self.connection.request(uri, method='PUT',
-            data=json.dumps({
-            'connectionLogging': {
-                'enabled': False
-            }
-        }))
+        resp = self.connection.request(
+            uri, method='PUT',
+            data=json.dumps({'connectionLogging': {'enabled': False}})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -903,10 +937,10 @@ class RackspaceLBDriver(Driver, OpenStac
         has been processed and the balancer is in a RUNNING state again.
 
         @param balancer: Balancer to enable session persistence on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_enable_balancer_session_persistence_no_poll(balancer):
             msg = 'Enable session persistence request not accepted'
@@ -920,18 +954,17 @@ class RackspaceLBDriver(Driver, OpenStac
         type to 'HTTP_COOKIE'.  This method returns immediately.
 
         @param balancer: Balancer to enable session persistence on.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the enable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/sessionpersistence' % (balancer.id)
-        resp = self.connection.request(uri, method='PUT',
-            data=json.dumps({
-                'sessionPersistence': {
-                    'persistenceType': 'HTTP_COOKIE'
-                }
-            }))
+        resp = self.connection.request(
+            uri, method='PUT',
+            data=json.dumps(
+                {'sessionPersistence': {'persistenceType': 'HTTP_COOKIE'}})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -942,10 +975,10 @@ class RackspaceLBDriver(Driver, OpenStac
         state again.
 
         @param balancer: Balancer to disable session persistence on.
-        @type balancer: C{Balancer}
+        @type balancer:  L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_disable_balancer_session_persistence_no_poll(balancer):
             msg = 'Disable session persistence request not accepted'
@@ -959,10 +992,10 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to disable session persistence for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the disable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/sessionpersistence' % (balancer.id)
         resp = self.connection.request(uri, method='DELETE')
@@ -976,13 +1009,13 @@ class RackspaceLBDriver(Driver, OpenStac
         RUNNING state again.
 
         @param balancer: Balancer to update the custom error page for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param page_content: HTML content for the custom error page.
-        @type page_content: C{string}
+        @type  page_content: C{str}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype:  L{LoadBalancer}
         """
         accepted = self.ex_update_balancer_error_page_no_poll(balancer,
                                                               page_content)
@@ -998,21 +1031,19 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to update the custom error page for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param page_content: HTML content for the custom error page.
-        @type page_content: C{string}
+        @type  page_content: C{str}
 
-        @rtype: C{bool}
         @return: Returns whether the update request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/errorpage' % (balancer.id)
-        resp = self.connection.request(uri, method='PUT',
-            data=json.dumps({
-                'errorpage': {
-                    'content': page_content
-                }
-            }))
+        resp = self.connection.request(
+            uri, method='PUT',
+            data=json.dumps({'errorpage': {'content': page_content}})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -1024,10 +1055,10 @@ class RackspaceLBDriver(Driver, OpenStac
         again.
 
         @param balancer: Balancer to disable the custom error page for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         if not self.ex_disable_balancer_custom_error_page_no_poll(balancer):
             msg = 'Disable custom error page request not accepted'
@@ -1041,10 +1072,10 @@ class RackspaceLBDriver(Driver, OpenStac
         the Rackspace-provided default.  This method returns immediately.
 
         @param balancer: Balancer to disable the custom error page for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @rtype: C{bool}
         @return: Returns whether the disable request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/errorpage' % (balancer.id)
         resp = self.connection.request(uri, method='DELETE')
@@ -1060,13 +1091,13 @@ class RackspaceLBDriver(Driver, OpenStac
         RUNNING state again.
 
         @param balancer: Balancer to create the access rule for.
-        @type balancer: C{Balancer}
+        @type balancer: L{LoadBalancer}
 
         @param rule: Access Rule to add to the balancer.
-        @type rule: C{RackspaceAccessRule}
+        @type rule: L{RackspaceAccessRule}
 
-        @rtype: C{RackspaceAccessRule}
         @return: The created access rule.
+        @rtype: L{RackspaceAccessRule}
         """
         accepted = self.ex_create_balancer_access_rule_no_poll(balancer, rule)
         if not accepted:
@@ -1089,19 +1120,19 @@ class RackspaceLBDriver(Driver, OpenStac
         immediately.
 
         @param balancer: Balancer to create the access rule for.
-        @type balancer: C{Balancer}
+        @type balancer: L{LoadBalancer}
 
         @param rule: Access Rule to add to the balancer.
-        @type rule: C{RackspaceAccessRule}
+        @type rule: L{RackspaceAccessRule}
 
-        @rtype: C{bool}
         @return: Returns whether the create request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/accesslist' % (balancer.id)
-        resp = self.connection.request(uri, method='POST',
-            data=json.dumps({
-                'networkItem': rule._to_dict()
-            }))
+        resp = self.connection.request(
+            uri, method='POST',
+            data=json.dumps({'networkItem': rule._to_dict()})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -1112,15 +1143,16 @@ class RackspaceLBDriver(Driver, OpenStac
         in a RUNNING state again.
 
         @param balancer: Balancer to create the access rule for.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @param rules: List of C{RackspaceAccessRule} to add to the balancer.
-        @type rules: C{list}
+        @param rules: List of L{RackspaceAccessRule} to add to the balancer.
+        @type  rules: C{list} of L{RackspaceAccessRule}
 
-        @rtype: C{RackspaceAccessRule}
         @return: The created access rules.
+        @rtype: L{RackspaceAccessRule}
         """
-        accepted = self.ex_create_balancer_access_rules_no_poll(balancer, rules)
+        accepted = self.ex_create_balancer_access_rules_no_poll(balancer,
+                                                                rules)
         if not accepted:
             msg = 'Create access rules not accepted'
             raise LibcloudError(msg, driver=self)
@@ -1147,8 +1179,8 @@ class RackspaceLBDriver(Driver, OpenStac
         enforces rule type and address uniqueness.
         """
         for r in access_list:
-            if rule_to_find.rule_type == r.rule_type and \
-               rule_to_find.address == r.address:
+            if rule_to_find.rule_type == r.rule_type and\
+                    rule_to_find.address == r.address:
                 return r
 
         return None
@@ -1159,19 +1191,20 @@ class RackspaceLBDriver(Driver, OpenStac
         returns immediately.
 
         @param balancer: Balancer to create the access rule for.
-        @type balancer: C{Balancer}
+        @type balancer: L{LoadBalancer}
 
-        @param rules: List of C{RackspaceAccessRule} to add to the balancer.
-        @type rules: C{list}
+        @param rules: List of L{RackspaceAccessRule} to add to the balancer.
+        @type  rules: C{list} of L{RackspaceAccessRule}
 
-        @rtype: C{bool}
         @return: Returns whether the create request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/accesslist' % (balancer.id)
-        resp = self.connection.request(uri, method='POST',
-            data=json.dumps({
-                'accessList' : [rule._to_dict() for rule in rules]
-            }))
+        resp = self.connection.request(
+            uri, method='POST',
+            data=json.dumps({'accessList':
+                             [rule._to_dict() for rule in rules]})
+        )
 
         return resp.status == httplib.ACCEPTED
 
@@ -1182,13 +1215,13 @@ class RackspaceLBDriver(Driver, OpenStac
         is in a RUNNING state again.
 
         @param balancer: Balancer to remove the access rule from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param rule: Access Rule to remove from the balancer.
-        @type rule: C{RackspaceAccessRule}
+        @type  rule: L{RackspaceAccessRule}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         accepted = self.ex_destroy_balancer_access_rule_no_poll(balancer, rule)
         if not accepted:
@@ -1203,13 +1236,13 @@ class RackspaceLBDriver(Driver, OpenStac
         returns immediately.
 
         @param balancer: Balancer to remove the access rule from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
         @param rule: Access Rule to remove from the balancer.
-        @type rule: C{RackspaceAccessRule}
+        @type  rule: L{RackspaceAccessRule}
 
-        @rtype: C{bool}
         @return: Returns whether the destroy request was accepted.
+        @rtype: C{bool}
         """
         uri = '/loadbalancers/%s/accesslist/%s' % (balancer.id, rule.id)
         resp = self.connection.request(uri, method='DELETE')
@@ -1223,14 +1256,14 @@ class RackspaceLBDriver(Driver, OpenStac
         balancer is in a RUNNING state again.
 
         @param balancer: Balancer to remove the access rules from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @param rules: List of C{RackspaceAccessRule} objects to remove from the
-        balancer.
-        @type rules: C{list}
+        @param rules: List of L{RackspaceAccessRule} objects to remove from the
+                       balancer.
+        @type  rules: C{list} of L{RackspaceAccessRule}
 
-        @rtype: C{Balancer}
         @return: Updated Balancer.
+        @rtype: L{LoadBalancer}
         """
         accepted = self.ex_destroy_balancer_access_rules_no_poll(
             balancer, rules)
@@ -1247,21 +1280,21 @@ class RackspaceLBDriver(Driver, OpenStac
         method returns immediately.
 
         @param balancer: Balancer to remove the access rules from.
-        @type balancer: C{Balancer}
+        @type  balancer: L{LoadBalancer}
 
-        @param rules: List of C{RackspaceAccessRule} objects to remove from the
-        balancer.
-        @type rules: C{list}
+        @param rules: List of L{RackspaceAccessRule} objects to remove from the
+                            balancer.
+        @type  rules: C{list} of L{RackspaceAccessRule}
 
-        @rtype: C{bool}
         @return: Returns whether the destroy request was accepted.
+        @rtype: C{bool}
         """
         ids = [('id', rule.id) for rule in rules]
         uri = '/loadbalancers/%s/accesslist' % balancer.id
 
         resp = self.connection.request(uri,
-            method='DELETE',
-            params=ids)
+                                       method='DELETE',
+                                       params=ids)
 
         return resp.status == httplib.ACCEPTED
 
@@ -1307,8 +1340,8 @@ class RackspaceLBDriver(Driver, OpenStac
         if 'protocol' in el:
             extra['protocol'] = el['protocol']
 
-        if 'algorithm' in el and el["algorithm"] in \
-            self._VALUE_TO_ALGORITHM_MAP:
+        if 'algorithm' in el and \
+           el["algorithm"] in self._VALUE_TO_ALGORITHM_MAP:
             extra["algorithm"] = self._value_to_algorithm(el["algorithm"])
 
         if 'healthMonitor' in el:
@@ -1321,8 +1354,8 @@ class RackspaceLBDriver(Driver, OpenStac
 
         if 'sessionPersistence' in el:
             persistence = el["sessionPersistence"]
-            extra["sessionPersistenceType"] = \
-                    persistence.get("persistenceType")
+            extra["sessionPersistenceType"] =\
+                persistence.get("persistenceType")
 
         if 'connectionLogging' in el:
             logging = el["connectionLogging"]
@@ -1338,17 +1371,17 @@ class RackspaceLBDriver(Driver, OpenStac
             extra['updated'] = self._iso_to_datetime(el['updated']['time'])
 
         if 'accessList' in el:
-            extra['accessList'] = [self._to_access_rule(rule) \
+            extra['accessList'] = [self._to_access_rule(rule)
                                    for rule in el['accessList']]
 
         return LoadBalancer(id=el["id"],
-                name=el["name"],
-                state=self.LB_STATE_MAP.get(
-                    el["status"], State.UNKNOWN),
-                ip=ip,
-                port=port,
-                driver=self.connection.driver,
-                extra=extra)
+                            name=el["name"],
+                            state=self.LB_STATE_MAP.get(
+                                el["status"], State.UNKNOWN),
+                            ip=ip,
+                            port=port,
+                            driver=self.connection.driver,
+                            extra=extra)
 
     def _to_members(self, object):
         return [self._to_member(el) for el in object["nodes"]]
@@ -1358,18 +1391,18 @@ class RackspaceLBDriver(Driver, OpenStac
         if 'weight' in el:
             extra['weight'] = el["weight"]
 
-        if 'condition' in el and el['condition'] in \
-           self.LB_MEMBER_CONDITION_MAP:
-            extra['condition'] = \
-                    self.LB_MEMBER_CONDITION_MAP.get(el["condition"])
+        if 'condition' in el and\
+           el['condition'] in self.LB_MEMBER_CONDITION_MAP:
+            extra['condition'] =\
+                self.LB_MEMBER_CONDITION_MAP.get(el["condition"])
 
         if 'status' in el:
             extra['status'] = el["status"]
 
         lbmember = Member(id=el["id"],
-                ip=el["address"],
-                port=el["port"],
-                extra=extra)
+                          ip=el["address"],
+                          port=el["port"],
+                          extra=extra)
         return lbmember
 
     def _protocol_to_value(self, protocol):
@@ -1394,7 +1427,7 @@ class RackspaceLBDriver(Driver, OpenStac
             update_attrs['algorithm'] = algorithm_value
 
         if "protocol" in attrs:
-            update_attrs['protocol'] = \
+            update_attrs['protocol'] =\
                 self._protocol_to_value(attrs['protocol'])
 
         if "port" in attrs:
@@ -1411,7 +1444,7 @@ class RackspaceLBDriver(Driver, OpenStac
     def _kwargs_to_mutable_member_attrs(self, **attrs):
         update_attrs = {}
         if 'condition' in attrs:
-            update_attrs['condition'] = \
+            update_attrs['condition'] =\
                 self.CONDITION_LB_MEMBER_MAP.get(attrs['condition'])
 
         if 'weight' in attrs:
@@ -1425,17 +1458,17 @@ class RackspaceLBDriver(Driver, OpenStac
         type = health_monitor_data.get("type")
         delay = health_monitor_data.get("delay")
         timeout = health_monitor_data.get("timeout")
-        attempts_before_deactivation = \
-                health_monitor_data.get("attemptsBeforeDeactivation")
+        attempts_before_deactivation =\
+            health_monitor_data.get("attemptsBeforeDeactivation")
 
         if type == "CONNECT":
-            return RackspaceHealthMonitor(type=type, delay=delay,
-                timeout=timeout,
+            return RackspaceHealthMonitor(
+                type=type, delay=delay, timeout=timeout,
                 attempts_before_deactivation=attempts_before_deactivation)
 
         if type == "HTTP" or type == "HTTPS":
-            return RackspaceHTTPHealthMonitor(type=type, delay=delay,
-                timeout=timeout,
+            return RackspaceHTTPHealthMonitor(
+                type=type, delay=delay, timeout=timeout,
                 attempts_before_deactivation=attempts_before_deactivation,
                 path=health_monitor_data.get("path"),
                 status_regex=health_monitor_data.get("statusRegex"),
@@ -1451,13 +1484,15 @@ class RackspaceLBDriver(Driver, OpenStac
         max_connection_rate = connection_throttle_data.get("maxConnectionRate")
         rate_interval = connection_throttle_data.get("rateInterval")
 
-        return RackspaceConnectionThrottle(min_connections=min_connections,
+        return RackspaceConnectionThrottle(
+            min_connections=min_connections,
             max_connections=max_connections,
             max_connection_rate=max_connection_rate,
             rate_interval_seconds=rate_interval)
 
     def _to_access_rule(self, el):
-        return RackspaceAccessRule(id=el.get("id"),
+        return RackspaceAccessRule(
+            id=el.get("id"),
             rule_type=self._to_access_rule_type(el.get("type")),
             address=el.get("address"))
 

Modified: libcloud/trunk/libcloud/loadbalancer/providers.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/providers.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/providers.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/providers.py Tue Jul 31 23:07:36 2012
@@ -17,10 +17,10 @@ from libcloud.utils.misc import get_driv
 from libcloud.loadbalancer.types import Provider
 
 __all__ = [
-        "Provider",
-        "DRIVERS",
-        "get_driver",
-        ]
+    "Provider",
+    "DRIVERS",
+    "get_driver",
+]
 
 DRIVERS = {
         Provider.RACKSPACE_US:

Modified: libcloud/trunk/libcloud/loadbalancer/types.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/types.py?rev=1367815&r1=1367814&r2=1367815&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/types.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/types.py Tue Jul 31 23:07:36 2012
@@ -14,11 +14,11 @@
 # limitations under the License.
 
 __all__ = [
-        "Provider",
-        "State",
-        "LibcloudLBError",
-        "LibcloudLBImmutableError",
-        ]
+    "Provider",
+    "State",
+    "LibcloudLBError",
+    "LibcloudLBImmutableError",
+]
 
 from libcloud.common.types import LibcloudError
 
@@ -53,9 +53,10 @@ class State(object):
     ERROR = 3
     DELETED = 4
 
+
 class MemberCondition(object):
     """
-    Each member of a load balancer can have an associated condition 
+    Each member of a load balancer can have an associated condition
     which determines its role within the load balancer.
     """
     ENABLED = 0