libcloud.loadbalancer.drivers.alb module

class libcloud.loadbalancer.drivers.alb.ApplicationLBDriver(access_id, secret, region, token=None)[source]

Bases: Driver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

connectionCls

alias of ALBConnection

create_balancer(name, port, protocol, algorithm, members, ex_scheme=None, ex_security_groups=None, ex_subnets=None, ex_tags=None, ex_ssl_cert_arn=None)[source]

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.

Parameters:
  • name (str) – Name of the new load balancer

  • port (int) – Port number to setup load balancer listener

  • protocol (str) – Load balancer protocol, should be ‘HTTP’ or ‘HTTPS’.

  • algorithm (Algorithm or None) – Load balancing algorithm. Ignored for AWS ALB.

  • members (list of Member) – List of Members to attach to the balancer. If ‘port’ attribute is set for the member - load balancer will send traffic there. Otherwise - load balancer port is used on the memeber’s side. ‘ip’ attribute is ignored.

  • ex_scheme (str) – Scheme of load balancer. Can be ‘internet-facing’ or ‘internal’.

  • ex_security_groups (list of str) – List of load balancer security group ids.

  • ex_subnets (list of str) – List of load balancer subnet ids.

  • ex_tags (dict) – Tags to assign to the load balancer.

  • ex_ssl_cert_arn (str) – SSL certificate ARN to use when load balancer protocol is ‘HTTPS’.

Returns:

LoadBalancer object

Return type:

LoadBalancer

ex_create_balancer(name, addr_type='ipv4', scheme='internet-facing', security_groups=None, subnets=None, tags=None)[source]

AWS-specific method to create a new load balancer. Since ALB is a composite object (load balancer, target group, listener etc) - extra methods must be called to assemble ready-to-use balancer.

Parameters:
  • name (str) – Name of the new load balancer

  • addr_type (str) – Load balancer address type. Can be ‘ipv4’ or ‘ipv6’.

  • scheme (str) – Scheme of load balancer. Can be ‘internet-facing’ or ‘internal’.

  • security_groups (list of str) – List of load balancer security group ids.

  • subnets (list of str) – List of load balancer subnet ids.

  • tags (dict) – Tags to assign to the load balancer.

Returns:

LoadBalancer object

Return type:

LoadBalancer

ex_create_listener(balancer, port, proto, target_group, action='forward', ssl_cert_arn=None, ssl_policy=None)[source]

Create a listener for application load balancer

Parameters:
  • balancer (LoadBalancer) – LoadBalancer to create listener for

  • port (int) – Port number to setup load balancer listener

  • proto (str) – Load balancer protocol, should be ‘HTTP’ or ‘HTTPS’.

  • target_group (ALBTargetGroup) – Target group associated with the listener.

  • action (str) – Default action for the listener, valid value is ‘forward’

  • ssl_cert_arn (str) – SSL certificate ARN to use when listener protocol is ‘HTTPS’.

  • ssl_policy (str) – The security policy that defines which ciphers and protocols are supported. The default is the current predefined security policy. Example: ‘ELBSecurityPolicy-2016-08’

Returns:

Listener object

Return type:

ALBListener

ex_create_listener_rule(listener, priority, target_group, action='forward', condition_field=None, condition_value=None)[source]

Create a rule for listener.

Parameters:
  • listener (ALBListener) – Listener object where to create rule

  • priority (str) – The priority for the rule. A listener can’t have multiple rules with the same priority.

  • target_group (ALBTargetGroup) – Target group object to associate with rule

  • action (str) – Action for the rule, valid value is ‘forward’

  • condition_field (str) – Rule condition field name. The possible values are ‘host-header’ and ‘path-pattern’.

  • condition_value – Value to match. Wildcards are supported, for example: ‘/img/*

Returns:

Rule object

Return type:

ALBRule

ex_create_target_group(name, port, proto, vpc, health_check_interval=30, health_check_path='/', health_check_port='traffic-port', health_check_proto='HTTP', health_check_timeout=5, health_check_matcher='200', healthy_threshold=5, unhealthy_threshold=2)[source]

Create a target group for AWS ALB load balancer.

Parameters:
  • name (str) – Name of target group

  • port (int) – The port on which the targets receive traffic. This port is used unless you specify a port override when registering the target.

  • proto (str) – The protocol to use for routing traffic to the targets. Can be ‘HTTP’ or ‘HTTPS’.

  • vpc (str) – The identifier of the virtual private cloud (VPC).

  • health_check_interval (int) – The approximate amount of time, in seconds, between health checks of an individual target. The default is 30 seconds.

  • health_check_path (str) – The ping path that is the destination on the targets for health checks. The default is /

  • health_check_port (str) – The port the load balancer uses when performing health checks on targets. The default is traffic-port, which indicates the port on which each target receives traffic from the load balancer.

  • health_check_proto (str) – The protocol the load balancer uses when performing health checks on targets. Can be ‘HTTP’ (default) or ‘HTTPS’.

  • health_check_timeout (int) – The amount of time, in seconds, during which no response from a target means a failed health check. The default is 5s.

  • health_check_matcher (str) – The HTTP codes to use when checking for a successful response from a target. Valid values: “200”, “200,202”, “200-299”.

  • healthy_threshold (int) – The number of consecutive health checks successes required before considering an unhealthy target healthy. The default is 5

  • unhealthy_threshold (int) – The number of consecutive health check failures required before considering a target unhealthy. The default is 2.

Returns:

Target group object.

Return type:

ALBTargetGroup

ex_get_listener(listener_id)[source]

Get listener object by ARN

Parameters:

listener_id (str) – ARN of listener object to get

Returns:

Listener object

Return type:

ALBListener

ex_get_rule(rule_id)[source]

Get rule by ARN.

Parameters:

rule_id (str) – ARN of rule

Returns:

Rule object

Return type:

ALBRule

ex_get_target_group(target_group_id)[source]

Get target group object by ARN

Parameters:

target_group_id (str) – ARN of target group

Returns:

Target group object

Return type:

ALBTargetGroup

ex_register_targets(target_group, members=None)[source]

Register members as targets at target group

Parameters:
  • target_group (dict) – Target group dict where register members.

  • members (list of Member) – List of Members to attach to the balancer. If ‘port’ attribute is set for the member - load balancer will send traffic there. Otherwise - load balancer port is used on the memeber’s side. ‘ip’ attribute is ignored.

Returns:

True on success, False if no members provided.

Return type:

bool

get_balancer(balancer_id)[source]

Get a load balancer object by ARN

Parameters:

balancer_id (str) – ARN of load balancer you wish to fetch.

Return type:

LoadBalancer

list_balancers()[source]

List all load balancers

Return type:

list of LoadBalancer

list_protocols()[source]

Return list of protocols supported by driver

Return type:

list of strings

name = 'Amazon Application Load Balancing'
signature_version = '4'
website = 'http://aws.amazon.com/elasticloadbalancing/'