Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ex_creaate_balancer method to the Rackspace driver and allow user to

pass 'vip' argument to it. THis patch has been contributed by Adam Pickeral and
is part of LIBCLOUD-166.


git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1301126 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit abe09bb9b5af53f2b64acdf820f718bd56478004 1 parent f82450e
@Kami Kami authored
View
4 CHANGES
@@ -74,6 +74,10 @@ Changes with Apache Libcloud in development:
LIBCLOUD-152
[Adam Pickeral]
+ - Add ex_creaate_balancer method to the Rackspace driver and allow user to
+ pass 'vip' argument to it. ; LIBCLOUD-166
+ [Adam Pickeral]
+
Changes with Apache Libcloud 0.8.0:
*) General:
View
52 libcloud/loadbalancer/drivers/rackspace.py
@@ -349,21 +349,49 @@ def list_balancers(self, ex_member_address=None):
def create_balancer(self, name, members, protocol='http',
port=80, algorithm=DEFAULT_ALGORITHM):
+ return self.ex_create_balancer(name, members, protocol, port,
+ algorithm)
+
+ def ex_create_balancer(self, name, members, protocol='http',
+ port=80, algorithm=DEFAULT_ALGORITHM, vip='PUBLIC'):
+ """
+ Creates 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}
+
+ @keyword vip: Virtual ip type of PUBLIC, SERVICENET, or ID of a virtual
+ ip
+ @type vip: C{str}
+ """
balancer_attrs = self._kwargs_to_mutable_attrs(
- name=name,
- protocol=protocol,
- port=port,
- algorithm=algorithm)
+ name=name,
+ protocol=protocol,
+ port=port,
+ algorithm=algorithm,
+ vip=vip)
balancer_attrs.update({
- 'virtualIps': [{'type': 'PUBLIC'}],
'nodes': [self._member_attributes(member) for member in members],
})
balancer_object = {"loadBalancer": balancer_attrs}
resp = self.connection.request('/loadbalancers',
- method='POST',
- data=json.dumps(balancer_object))
+ method='POST',
+ data=json.dumps(balancer_object))
return self._to_balancer(resp.object['loadBalancer'])
def _member_attributes(self, member):
@@ -373,8 +401,8 @@ def _member_attributes(self, member):
member_attributes.update(self._kwargs_to_mutable_member_attrs(
**member.extra))
- # If the condition is not specified on the member, then it should be set
- # to ENABLED by default
+ # 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]
@@ -1285,6 +1313,12 @@ def _kwargs_to_mutable_attrs(self, **attrs):
if "port" in attrs:
update_attrs['port'] = int(attrs['port'])
+ if "vip" in attrs:
+ if attrs['vip'] == 'PUBLIC' or attrs['vip'] == 'SERVICENET':
+ update_attrs['virtualIps'] = [{'type': attrs['vip']}]
+ else:
+ update_attrs['virtualIps'] = [{'id': attrs['vip']}]
+
return update_attrs
def _kwargs_to_mutable_member_attrs(self, **attrs):
View
53 test/loadbalancer/test_rackspace.py
@@ -23,7 +23,6 @@
import json
from libcloud.utils.py3 import httplib
-from libcloud.utils.py3 import urllib
from libcloud.utils.py3 import urlencode
from libcloud.loadbalancer.base import LoadBalancer, Member, Algorithm
@@ -113,6 +112,21 @@ def test_create_balancer(self):
self.assertEquals(balancer.name, 'test2')
self.assertEquals(balancer.id, '8290')
+ def test_ex_create_balancer(self):
+ RackspaceLBDriver.connectionCls.conn_classes = (None,
+ RackspaceLBWithVIPMockHttp)
+ RackspaceLBMockHttp.type = None
+ driver = RackspaceLBDriver('user', 'key')
+ balancer = driver.ex_create_balancer(name='test2',
+ port=80,
+ algorithm=Algorithm.ROUND_ROBIN,
+ members=(Member(None, '10.1.0.11', 80),),
+ vip='12af'
+ )
+
+ self.assertEquals(balancer.name, 'test2')
+ self.assertEquals(balancer.id, '8290')
+
def test_destroy_balancer(self):
balancer = self.driver.list_balancers()[0]
@@ -832,6 +846,8 @@ def _v1_0_slug_loadbalancers(self, method, url, body, headers):
self.assertEqual(loadbalancer_json['protocol'], 'HTTP')
self.assertEqual(loadbalancer_json['algorithm'], 'ROUND_ROBIN')
+ self.assertEqual(loadbalancer_json['virtualIps'][0]['type'],
+ 'PUBLIC')
self.assertEqual(member_1_json['condition'], 'DISABLED')
self.assertEqual(member_1_json['weight'], 10)
self.assertEqual(member_2_json['condition'], 'ENABLED')
@@ -1283,5 +1299,40 @@ def _v1_1_auth(self, method, url, body, headers):
body = self.auth_fixtures.load('_v1_1__auth.json')
return (httplib.OK, body, headers, httplib.responses[httplib.OK])
+
+class RackspaceLBWithVIPMockHttp(MockHttpTestCase):
+ fixtures = LoadBalancerFileFixtures('rackspace')
+ auth_fixtures = OpenStackFixtures()
+
+ def _v1_0(self, method, url, body, headers):
+ headers = {'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug',
+ 'x-auth-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
+ 'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06',
+ 'x-storage-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
+ 'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06'}
+ return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT])
+
+ def _v1_0_slug_loadbalancers(self, method, url, body, headers):
+ if method == "GET":
+ body = self.fixtures.load('v1_slug_loadbalancers.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ elif method == "POST":
+ body_json = json.loads(body)
+ loadbalancer_json = body_json['loadBalancer']
+
+ self.assertEqual(loadbalancer_json['virtualIps'][0]['id'], '12af')
+
+ body = self.fixtures.load('v1_slug_loadbalancers_post.json')
+ return (httplib.ACCEPTED, body, {},
+ httplib.responses[httplib.ACCEPTED])
+
+ raise NotImplementedError
+
+ def _v1_1_auth(self, method, url, body, headers):
+ headers = {'content-type': 'application/json; charset=UTF-8'}
+ body = self.auth_fixtures.load('_v1_1__auth.json')
+ return (httplib.OK, body, headers, httplib.responses[httplib.OK])
+
+
if __name__ == "__main__":
sys.exit(unittest.main())
Please sign in to comment.
Something went wrong with that request. Please try again.