libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] Kami commented on a change in pull request #1349: Implemented create methods for AWS ALB driver
Date Sun, 08 Sep 2019 16:49:56 GMT
Kami commented on a change in pull request #1349: Implemented create methods for AWS ALB driver
URL: https://github.com/apache/libcloud/pull/1349#discussion_r322018801
 
 

 ##########
 File path: libcloud/loadbalancer/drivers/alb.py
 ##########
 @@ -60,26 +211,496 @@ def __init__(self, access_id, secret, region, token=None):
         )
 
     def list_protocols(self):
+        """
+        Return list of protocols supported by driver
+
+        :rtype: ``list`` of ``strings``
+        """
         return ['http', 'https']
 
     def list_balancers(self):
+        """
+        List all load balancers
+
+        :rtype: ``list`` of :class:`LoadBalancer`
+        """
         params = {'Action': 'DescribeLoadBalancers'}
         data = self.connection.request(ROOT, params=params).object
         return self._to_balancers(data)
 
-    def balancer_list_members(self, balancer):
-        return balancer._members
-
     def get_balancer(self, balancer_id):
+        """
+        Get a load balancer object by ARN
+
+        :param  balancer_id: ARN of load balancer you wish to fetch.
+        :type  balancer_id: ``str``
+
+        :rtype: :class:`LoadBalancer`
+        """
         params = {
             'Action': 'DescribeLoadBalancers',
-            'LoadBalancerNames.member.1': balancer_id
+            'LoadBalancerArns.member.1': balancer_id
         }
         data = self.connection.request(ROOT, params=params).object
         return self._to_balancers(data)[0]
 
-    def ex_balancer_list_listeners(self, balancer):
-        return balancer.extra.get('listeners', [])
+    def create_balancer(self, name, port, protocol, algorithm, members,
+                        ex_scheme="", ex_security_groups=[], ex_subnets=[],
+                        ex_tags={}, ex_ssl_cert_arn=""):
+        """
+        Create a new load balancer instance.
+
+        AWS ALB balancer creation consists of 5 steps:
+        http://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/Welcome.html
+
+        create_balancer() is a standard API method so, it's made as a wrapper
+        here to preserve compatibility with other drivers where LB creation
+        is one-step process. It calls respective ALB methods to assemble
+        ready-to-use load balancer.
+
+        :param name: Name of the new load balancer
+        :type name: ``str``
+
+        :param port: Port number to setup load balancer listener
+        :type port: ``int``
+
+        :param protocol: Load balancer protocol, should be 'HTTP' or 'HTTPS'.
+        :type protocol: ``str``
+
+        :param algorithm: Load balancing algorithm. Ignored for AWS ALB.
+        :type algorithm: :class:`Algorithm` or ``None``
+
+        :param members: List of Members to attach to the balancer. If 'port'
+                        attribute is set for the memeber - load balancer will
+                        send traffic there. Otherwise - load balancer port is
+                        used on the memeber's side. 'ip' attribute is ignored.
+        :type members: ``list`` of :class:`Member`
+
+        :param ex_scheme: Scheme of load balancer. Can be 'internet-facing' or
+                          'internal'.
+        :type ex_scheme: ``str``
+
+        :param ex_security_groups: List of load balancer security group ids.
+        :type ex_security_groups: ``list`` of ``str``
+
+        :param ex_subnets: List of load balancer subnet ids.
+        :type ex_subnets: ``list`` of ``str``
+
+        :param ex_tags: Tags to assign to the load balancer.
+        :type ex_tags: ``dict``
+
+        :param ex_ssl_cert_arn: SSL certificate ARN to use when load balancer
+                protocol is 'HTTPS'.
+        :type ex_ssl_cert_arn: ``str``
+
+        :return: LoadBalancer object
+        :rtype: :class:`LoadBalancer`
+        """
+
+        balancer = self.ex_create_balancer(name, scheme=ex_scheme,
+                                           security_groups=ex_security_groups,
+                                           subnets=ex_subnets, tags=ex_tags)
+
+        target_group = self.ex_create_target_group(
+            name + "-tg", port, protocol, balancer.extra.get('vpc'),
+            health_check_proto=protocol
+        )
+        self.ex_register_targets(target_group, members)
+        listener = self.ex_create_listener(balancer, port, protocol,
+                                           target_group,
+                                           ssl_cert_arn=ex_ssl_cert_arn)
+
+        balancer.extra['listener'] = listener
+
+        return balancer
+
+    def ex_create_balancer(self, name, addr_type="ipv4",
+                           scheme="internet-facing", security_groups=[],
 
 Review comment:
   Same here (re mutable default arguments).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message