libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/3] libcloud git commit: - Made _ex_list_balancer_tags & _ex_populate_balancer_tags private extra Closes #848
Date Fri, 30 Sep 2016 05:52:41 GMT
- Made _ex_list_balancer_tags & _ex_populate_balancer_tags private extra
Closes #848


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

Branch: refs/heads/trunk
Commit: 6d6fe47b4df7fee84fd845d8b0782531399c07a6
Parents: 1438d35
Author: Anton Kozyrev <anton.kozyrev@gmail.com>
Authored: Thu Aug 18 14:56:32 2016 +0300
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Sep 30 15:50:57 2016 +1000

----------------------------------------------------------------------
 libcloud/loadbalancer/base.py          | 13 ----------
 libcloud/loadbalancer/drivers/elb.py   | 38 ++++++++++++++++++-----------
 libcloud/test/loadbalancer/test_elb.py | 21 ++++++++++++++--
 3 files changed, 43 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6d6fe47b/libcloud/loadbalancer/base.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/base.py b/libcloud/loadbalancer/base.py
index ae71942..171b6bf 100644
--- a/libcloud/loadbalancer/base.py
+++ b/libcloud/loadbalancer/base.py
@@ -222,19 +222,6 @@ class Driver(BaseDriver):
         raise NotImplementedError(
             'get_balancer not implemented for this driver')
 
-    def get_tags(self, balancer_id):
-        """
-        Return a dict of tag/value
-
-        :param balancer_id: id of a load balancer you want to fetch tags for
-        :type  balancer_id: ``str``
-
-        :rtype: ``dict``
-        """
-
-        raise NotImplementedError(
-            'get_tags not implemented for this driver')
-
     def update_balancer(self, balancer, **kwargs):
         """
         Sets the name, algorithm, protocol, or port on a load balancer.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6d6fe47b/libcloud/loadbalancer/drivers/elb.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/elb.py b/libcloud/loadbalancer/drivers/elb.py
index 006816b..766c86d 100644
--- a/libcloud/loadbalancer/drivers/elb.py
+++ b/libcloud/loadbalancer/drivers/elb.py
@@ -69,11 +69,8 @@ class ElasticLBDriver(Driver):
         balancers = self._to_balancers(data)
 
         if ex_fetch_tags:
-            for lb in balancers:
-                tags = lb.extra.get('tags', {})
-                tags.update(self.get_tags(lb.id))
-                if tags:
-                    lb.extra['tags'] = tags
+            for balancer in balancers:
+                self._ex_populate_balancer_tags(balancer)
 
         return balancers
 
@@ -116,21 +113,18 @@ class ElasticLBDriver(Driver):
         self.connection.request(ROOT, params=params)
         return True
 
-    def get_balancer(self, balancer_id):
+    def get_balancer(self, balancer_id, ex_fetch_tags=False):
         params = {
             'Action': 'DescribeLoadBalancers',
             'LoadBalancerNames.member.1': balancer_id
         }
         data = self.connection.request(ROOT, params=params).object
-        return self._to_balancers(data)[0]
+        balancer = self._to_balancers(data)[0]
 
-    def get_tags(self, balancer_id):
-        params = {
-            'Action': 'DescribeTags',
-            'LoadBalancerNames.member.1': balancer_id
-        }
-        data = self.connection.request(ROOT, params=params).object
-        return self._to_tags(data)
+        if ex_fetch_tags:
+            balancer = self._ex_populate_balancer_tags(balancer)
+
+        return balancer
 
     def balancer_attach_compute_node(self, balancer, node):
         params = {
@@ -393,3 +387,19 @@ class ElasticLBDriver(Driver):
             kwargs['signature_version'] = self.signature_version
 
         return kwargs
+
+    def _ex_list_balancer_tags(self, balancer_id):
+        params = {
+            'Action': 'DescribeTags',
+            'LoadBalancerNames.member.1': balancer_id
+        }
+        data = self.connection.request(ROOT, params=params).object
+        return self._to_tags(data)
+
+    def _ex_populate_balancer_tags(self, balancer):
+        tags = balancer.extra.get('tags', {})
+        tags.update(self._ex_list_balancer_tags(balancer.id))
+        if tags:
+            balancer.extra['tags'] = tags
+
+        return balancer

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6d6fe47b/libcloud/test/loadbalancer/test_elb.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_elb.py b/libcloud/test/loadbalancer/test_elb.py
index 3ddb1d6..93d47a5 100644
--- a/libcloud/test/loadbalancer/test_elb.py
+++ b/libcloud/test/loadbalancer/test_elb.py
@@ -72,8 +72,8 @@ class ElasticLBTests(unittest.TestCase):
         self.assertTrue(('tags' in balancers[0].extra), 'No tags dict found in balancer.extra')
         self.assertEqual(balancers[0].extra['tags']['project'], 'lima')
 
-    def test_get_tags(self):
-        tags = self.driver.get_tags('tests')
+    def test_list_balancer_tags(self):
+        tags = self.driver._ex_list_balancer_tags('tests')
 
         self.assertEqual(len(tags), 1)
         self.assertEqual(tags['project'], 'lima')
@@ -85,6 +85,23 @@ class ElasticLBTests(unittest.TestCase):
         self.assertEqual(balancer.name, 'tests')
         self.assertEqual(balancer.state, State.UNKNOWN)
 
+    def test_get_balancer_with_tags(self):
+        balancer = self.driver.get_balancer(balancer_id='tests', ex_fetch_tags=True)
+
+        self.assertEqual(balancer.id, 'tests')
+        self.assertEqual(balancer.name, 'tests')
+        self.assertTrue(('tags' in balancer.extra), 'No tags dict found in balancer.extra')
+        self.assertEqual(balancer.extra['tags']['project'], 'lima')
+
+    def test_populate_balancer_tags(self):
+        balancer = self.driver.get_balancer(balancer_id='tests')
+        balancer = self.driver._ex_populate_balancer_tags(balancer)
+
+        self.assertEqual(balancer.id, 'tests')
+        self.assertEqual(balancer.name, 'tests')
+        self.assertTrue(('tags' in balancer.extra), 'No tags dict found in balancer.extra')
+        self.assertEqual(balancer.extra['tags']['project'], 'lima')
+
     def test_destroy_balancer(self):
         balancer = self.driver.get_balancer(balancer_id='tests')
 


Mime
View raw message