libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject libcloud git commit: Fixed the loadbalancer method for cloudstack incl tests
Date Wed, 21 Jan 2015 09:59:34 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 5591e2eb9 -> 60cbe22bf


Fixed the loadbalancer method for cloudstack incl tests

Signed-off-by: Sebastien Goasguen <runseb@gmail.com>


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

Branch: refs/heads/trunk
Commit: 60cbe22bf03a06b3f5df6956e5c2326b6ae54796
Parents: 5591e2e
Author: Jeroen de Korte <jeroen@jedeko.com>
Authored: Thu Jan 15 14:00:14 2015 +0100
Committer: Sebastien Goasguen <runseb@gmail.com>
Committed: Wed Jan 21 04:58:46 2015 -0500

----------------------------------------------------------------------
 CHANGES.rst                                     |  7 +++
 libcloud/compute/drivers/cloudstack.py          | 18 +++++---
 libcloud/loadbalancer/drivers/cloudstack.py     | 47 ++++++++++++++++----
 .../createLoadBalancerRule_default.json         |  2 +-
 .../listLoadBalancerRules_default.json          |  2 +-
 libcloud/test/loadbalancer/test_cloudstack.py   |  4 +-
 6 files changed, 63 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 1a7bbfa..8be94b3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -149,6 +149,13 @@ Storage
   (GITHUB-408, LIBCLOUD-639)
   [Peter Schmidt]
 
+Loadbalancer
+~~~~~~~~~~~~
+
+- Updates to CloudStack Load-Balancer
+  (GITHUB-434)
+  [Jeroen de Korte]
+
 DNS
 ~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 50af6d1..f006445 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -970,21 +970,27 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         }
         if location is not None:
             args['zoneid'] = location.id
+
         imgs = self._sync_request(command='listTemplates',
                                   params=args,
                                   method='GET')
         images = []
         for img in imgs.get('template', []):
+
+            extra = {'hypervisor': img['hypervisor'],
+                     'format': img['format'],
+                     'os': img['ostypename'],
+                     'displaytext': img['displaytext']}
+
+            size = img.get('size', None)
+            if size is not None:
+                extra.update({'size': img['size']})
+
             images.append(NodeImage(
                 id=img['id'],
                 name=img['name'],
                 driver=self.connection.driver,
-                extra={
-                    'hypervisor': img['hypervisor'],
-                    'format': img['format'],
-                    'size': img['size'],
-                    'os': img['ostypename'],
-                    'displaytext': img['displaytext']}))
+                extra=extra))
         return images
 
     def list_locations(self):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/libcloud/loadbalancer/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/cloudstack.py b/libcloud/loadbalancer/drivers/cloudstack.py
index ee88824..a8d5485 100644
--- a/libcloud/loadbalancer/drivers/cloudstack.py
+++ b/libcloud/loadbalancer/drivers/cloudstack.py
@@ -86,7 +86,7 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
 
     def create_balancer(self, name, members, protocol='http', port=80,
                         algorithm=DEFAULT_ALGORITHM, location=None,
-                        private_port=None):
+                        private_port=None, network_id=None, vpc_id=None):
         """
         @inherits: :class:`Driver.create_balancer`
 
@@ -95,7 +95,14 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
 
         :param private_port: Private port
         :type  private_port: ``int``
+
+        :param network_id: The guest network this rule will be created for.
+        :type  network_id: ``str``
         """
+
+        args = {}
+        ip_args = {}
+
         if location is None:
             locations = self._sync_request(command='listZones', method='GET')
             location = locations['zone'][0]['id']
@@ -104,21 +111,44 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
         if private_port is None:
             private_port = port
 
+        if network_id is not None:
+            args['networkid'] = network_id
+            ip_args['networkid'] = network_id
+
+        if vpc_id is not None:
+            ip_args['vpcid'] = vpc_id
+
+        ip_args.update({'zoneid': location,
+                        'networkid': network_id,
+                        'vpc_id': vpc_id})
+
         result = self._async_request(command='associateIpAddress',
-                                     params={'zoneid': location},
+                                     params=ip_args,
                                      method='GET')
         public_ip = result['ipaddress']
 
+        args.update({'algorithm': self._ALGORITHM_TO_VALUE_MAP[algorithm],
+                     'name': name,
+                     'privateport': private_port,
+                     'publicport': port,
+                     'publicipid': public_ip['id']})
+
         result = self._sync_request(
             command='createLoadBalancerRule',
-            params={'algorithm': self._ALGORITHM_TO_VALUE_MAP[algorithm],
-                    'name': name,
-                    'privateport': private_port,
-                    'publicport': port,
-                    'publicipid': public_ip['id']},
+            params=args,
+            method='GET')
+
+        listbalancers = self._sync_request(
+            command='listLoadBalancerRules',
+            params=args,
             method='GET')
 
-        balancer = self._to_balancer(result['loadbalancer'])
+        listbalancers = [rule for rule in listbalancers['loadbalancerrule'] if
+                         rule['id'] == result['id']]
+        if len(listbalancers) != 1:
+            return None
+
+        balancer = self._to_balancer(listbalancers[0])
 
         for member in members:
             balancer.attach_member(member)
@@ -128,6 +158,7 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
     def destroy_balancer(self, balancer):
         self._async_request(command='deleteLoadBalancerRule',
                             params={'id': balancer.id},
+
                             method='GET')
         self._async_request(command='disassociateIpAddress',
                             params={'id': balancer.ex_public_ip_id},

http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/libcloud/test/loadbalancer/fixtures/cloudstack/createLoadBalancerRule_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/fixtures/cloudstack/createLoadBalancerRule_default.json
b/libcloud/test/loadbalancer/fixtures/cloudstack/createLoadBalancerRule_default.json
index 4a442a0..e13fca2 100644
--- a/libcloud/test/loadbalancer/fixtures/cloudstack/createLoadBalancerRule_default.json
+++ b/libcloud/test/loadbalancer/fixtures/cloudstack/createLoadBalancerRule_default.json
@@ -1 +1 @@
-{ "createloadbalancerruleresponse" :  { "loadbalancer" : {"id":2253,"name":"fake","publicipid":34000,"publicip":"1.1.1.49","publicport":"80","privateport":"80","algorithm":"roundrobin","account":"fakeaccount","domainid":801,"domain":"AA000062-libcloud-dev","state":"Add"}
}  }
+{ "createloadbalancerruleresponse" : {"id":"2253","jobid":"e3f6740b-c9e3-40c5-83e2-04d929482ef4"}
}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/libcloud/test/loadbalancer/fixtures/cloudstack/listLoadBalancerRules_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/fixtures/cloudstack/listLoadBalancerRules_default.json
b/libcloud/test/loadbalancer/fixtures/cloudstack/listLoadBalancerRules_default.json
index f3ae05a..fa8e6d5 100644
--- a/libcloud/test/loadbalancer/fixtures/cloudstack/listLoadBalancerRules_default.json
+++ b/libcloud/test/loadbalancer/fixtures/cloudstack/listLoadBalancerRules_default.json
@@ -1 +1 @@
-{ "listloadbalancerrulesresponse" : { "loadbalancerrule" : [  {"id":2247,"name":"test","publicipid":34000,"publicip":"1.1.1.49","publicport":"80","privateport":"80","algorithm":"roundrobin","account":"fakeaccount","domainid":801,"domain":"AA000062-libcloud-dev","state":"Active"},{"id":2249,"name":"testmore","publicipid":34001,"publicip":"1.1.2.49","publicport":"80","privateport":"80","algorithm":"leastconn","account":"fakeaccount","domainid":801,"domain":"AA000062-libcloud-dev","state":"Active"}
] } }
+{ "listloadbalancerrulesresponse" : { "loadbalancerrule" : [  {"id":"2253","name":"test","publicipid":34000,"publicip":"1.1.1.49","publicport":"80","privateport":"80","algorithm":"roundrobin","account":"fakeaccount","domainid":801,"domain":"AA000062-libcloud-dev","state":"Active"},{"id":2249,"name":"testmore","publicipid":34001,"publicip":"1.1.2.49","publicport":"80","privateport":"80","algorithm":"leastconn","account":"fakeaccount","domainid":801,"domain":"AA000062-libcloud-dev","state":"Active"}
] } }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/60cbe22b/libcloud/test/loadbalancer/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_cloudstack.py b/libcloud/test/loadbalancer/test_cloudstack.py
index a54c177..05f3cbc 100644
--- a/libcloud/test/loadbalancer/test_cloudstack.py
+++ b/libcloud/test/loadbalancer/test_cloudstack.py
@@ -60,7 +60,9 @@ class CloudStackLBTests(unittest.TestCase):
 
     def test_create_balancer(self):
         members = [Member(1, '1.1.1.1', 80), Member(2, '1.1.1.2', 80)]
-        balancer = self.driver.create_balancer('fake', members)
+        balancer = self.driver.create_balancer(
+            name='test', algorithm=Algorithm.ROUND_ROBIN,
+            members=members)
         self.assertTrue(isinstance(balancer, LoadBalancer))
 
     def test_destroy_balancer(self):


Mime
View raw message