aliyun.slb.connection module

exception aliyun.slb.connection.Error[source]

Bases: exceptions.Exception

Base Exception class for this module.

class aliyun.slb.connection.SlbConnection(region_id, access_key_id=None, secret_access_key=None)[source]

Bases: aliyun.connection.Connection

A connection to Aliyun SLB service.

add_backend_server_ids(load_balancer_id, backend_server_ids)[source]
Helper wrapper to add backend server IDs specified to the SLB
specified.
Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
  • backend_server_ids (list of str) – the backend server ids to add
add_backend_servers(load_balancer_id, backend_servers)[source]

Add backend servers to a load balancer

Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
  • backend_servers (list of BackendServer) – the backend servers to add
create_http_listener(load_balancer_id, listener_port, backend_server_port, bandwidth, sticky_session, health_check, healthy_threshold=3, unhealthy_threshold=3, scheduler=None, connect_timeout=None, interval=None, x_forwarded_for=None, sticky_session_type=None, cookie_timeout=None, cookie=None, domain=None, uri=None)[source]

Create an HTTP SLB Listener

Parameters:
  • load_balancer_id (str) – LoadBalancerId unique identifier of the SLB.
  • listener_port (int) – Port for the SLB to listen on
  • backend_server_port (int) – Port to send traffic to on the back-end
  • bandwidth (int) – The peak burst speed of the network. Optional values: - 1|1 - 1000Mbps For the paybybandwidth intances, the peak burst speed of all Listeners should not exceed the Bandwidth value in SLB instance creation, and the Bandwidth value must not be set to - 1. For paybytraffic instances, this value can be set to - 1, meaning there is no restriction on bandwidth peak speed.
  • sticky_session (str) – on or off
  • healthy_threshold (int) – Number of successful healthchecks before considering the listener healthy. Default 3.
  • unhealthy_threshold (int) – Number of failed healthchecks before considering the listener unhealthy. Default 3.
  • health_check (str) – ‘on’ and ‘off’ (default)
HTTPListener arguments:
scheduler (str): wrr or wlc. Round Robin (default) or
Least Connections.
connect_timeout (int): number of seconds to timeout and fail a
health check

interval (int): number of seconds between health checks x_forwarded_for (bool): wether or not to append ips to

x-fordwarded-for http header
sticky_session_type (str):
‘insert’ to have the SLB add a cookie to requests ‘server’ to have the SLB look for a server-injected cookie sticky_session must be ‘on’
cookie_timeout (int [0-86400]):
Lifetime of cookie in seconds. Max 1 day. sticky_session must be ‘on’
cookie (str):
The Cookie key to use as sticky_session indicator. sticky_session_type must be ‘server’

domain (str): the Host header to use for the health check uri (str): URL path for healthcheck. E.g. /health

create_load_balancer(region_id, address_type=None, internet_charge_type=None, bandwidth=None, load_balancer_name=None)[source]

Create a load balancer. This does not configure listeners nor backend servers.

Parameters:
  • region_id (str) – An id from get_all_region_ids()
  • addres_type (str) – IP the SLB on the public network (‘internet’, default) or the private network (‘intranet’)
  • internet_charge_type (str) – ‘paybytraffic’ (default) vs ‘paybybandwidth’
  • bandwidth (int) – peak burst speed of ‘paybybandwidth’ type slbs. Listener must be set first before this will take effect. default: 1 (unit Mbps)
  • load_balancer_name (str) – Name of the SLB. 80 char max. Optional.
Returns:

load_balancer_id of the created LB. Address and Name are not given.

create_tcp_listener(load_balancer_id, listener_port, backend_server_port, healthy_threshold=3, unhealthy_threshold=3, listener_status=None, scheduler=None, health_check=None, connect_timeout=None, interval=None, connect_port=None, persistence_timeout=None)[source]

Create a TCP SLB Listener

Parameters:
  • load_balancer_id (str) – LoadBalancerId unique identifier of the SLB.
  • listener_port (int) – Port for the SLB to listen on
  • backend_server_port (int) – Port to send traffic to on the back-end
  • healthy_threshold (int) – Number of successful healthchecks before considering the listener healthy. Default 3.
  • unhealthy_threshold (int) – Number of failed healthchecks before considering the listener unhealthy. Default 3.
  • arguments (TCPListener) –
  • listener_status (str) – ‘active’ (default) or ‘stopped’.
  • scheduler (str) – wrr or wlc. Round Robin (default) or Least Connections.
  • health_check (bool) – True for ‘on’ and False for ‘off’ (default)
  • connect_timeout (int) – number of seconds to timeout and fail a health check
  • interval (int) – number of seconds between health checks
  • connect_port (int) – defaults to backend_server_port
  • persistence_timeout (int) – number of seconds to hold TCP connection open
delete_listener(load_balancer_id, listener_port)[source]

Delete the SLB Listner on specified port

Parameters:
  • load_balancer_id (str) – SLB ID
  • listener_port (int) – SLB Listener port. Between 1 and 65535.
delete_load_balancer(load_balancer_id)[source]

Delete a LoadBalancer by ID

Parameters:load_balancer_id (str) – Aliyun SLB LoadBalancerId to delete.
deregister_backend_server_ids(server_ids)[source]

Helper wrapper to get load balancers with the server id in them and remove the server from each load balancer.

Parameters:server_id (List of str) – List of Aliyun ECS Instance IDs
Returns:List of SLB IDs that were modified.
deregister_backend_servers(backend_servers)[source]
get_all_load_balancer_ids()[source]

Get all the load balancer IDs in the region.

get_all_load_balancer_status(instance_id=None)[source]

Get all LoadBalancerStatus in the region.

Parameters:instance_id (str, optional) – Restrict results to LBs with this instance.
Returns:List of LoadBalancerStatus.
get_all_region_ids()[source]
get_all_regions()[source]

Get all regions.

Return: list[slb.Region]

get_backend_server_ids(load_balancer_id, listener_port=None)[source]
get_backend_servers(load_balancer_id, listener_port=None)[source]

Get backend servers for a given load balancer and its listener port.

If listener_port is not specified, all listeners are listed separately.

Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
  • listener_port (int, optional) – the port to get backend server statuses for
Returns:

List of ListenerStatus

get_http_listener(load_balancer_id, listener_port)[source]

Get the HTTP Listener from an SLB ID and port

Parameters:
  • load_balancer_id (str) – SLB ID
  • listener_port (int) – SLB Listener port. Between 1 and 65535.
Returns:

HTTPListener

get_load_balancer(load_balancer_id)[source]

Get a LoadBalancer by ID.

Parameters:load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
Returns:LoadBalancer with given ID.
get_tcp_listener(load_balancer_id, listener_port)[source]

Get the TCP Listener from an SLB ID and port

Parameters:
  • load_balancer_id (str) – SLB ID
  • listener_port (int) – SLB Listener port. Between 1 and 65535.
Returns:

TCPListener

remove_backend_server_ids(load_balancer_id, backend_server_ids)[source]
Helper wrapper to remove backend server IDs specified from the SLB
specified.
Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
  • backend_server_ids (list of str) – the backend server ids to remove
remove_backend_servers(load_balancer_id, backend_servers)[source]
Remove backend servers from a load balancer
Note: the SLB API ignores Weight when Removing Backend Servers. So you’re probably better off using remove_backend_server_id anyway.
Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId to retrieve.
  • backend_servers (list of BackendServer) – the backend servers to remove
set_listener_status(load_balancer_id, listener_port, status)[source]

Set the status of an SLB Listener. Turn them on or off.

Parameters:
  • load_balancer_id (str) – SLB ID
  • listener_port (int) – SLB Listener port. Between 1 and 65535.
  • status (str) – ‘inactive’ for off and ‘active’ for on.
set_load_balancer_name(load_balancer_id, name)[source]

Set the Name of an SLB

Parameters:
  • load_balancer_id (str) – SLB ID
  • name (str) – Alias for the SLB. Up to 64 characters.
set_load_balancer_status(load_balancer_id, status)[source]

Set the Status of an SLB

Parameters:
  • load_balancer_id (str) – SLB ID
  • status (str) – One of ‘inactive’ or ‘active’
start_load_balancer_listener(load_balancer_id, listener_port)[source]

Start a listener

Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId
  • listener_port (int) – The listener port to activate
stop_load_balancer_listener(load_balancer_id, listener_port)[source]

Stop a listener

Parameters:
  • load_balancer_id (str) – Aliyun SLB LoadBalancerId
  • listener_port (int) – The listener port to activate
update_http_listener(load_balancer_id, listener_port, healthy_threshold=None, unhealthy_threshold=None, scheduler=None, health_check=None, health_check_timeout=None, interval=None, x_forwarded_for=None, sticky_session=None, sticky_session_type=None, cookie_timeout=None, cookie=None, domain=None, uri=None)[source]

Update an existing HTTP SLB Listener

Parameters:
  • load_balancer_id (str) – LoadBalancerId unique identifier of the SLB.
  • listener_port (int) – Port for the SLB to listen on
  • healthy_threshold (int) – Number of successful healthchecks before considering the listener healthy. Default 3.
  • unhealthy_threshold (int) – Number of failed healthchecks before considering the listener unhealthy. Default 3.
  • scheduler (str) – wrr or wlc. Round Robin (default) or Least Connections.
  • health_check (bool) – True for ‘on’ and False for ‘off’ (default)
  • health_check_timeout (int) – number of seconds to timeout and fail a health check
  • interval (int) – number of seconds between health checks
  • x_forwarded_for (bool) – wether or not to append ips to x-fordwarded-for http header
  • sticky_session (bool) – use slb sticky sessions. default false.
  • sticky_session_type (str) – ‘insert’ to have the SLB add a cookie to requests ‘server’ to have the SLB look for a server-injected cookie sticky_session must be ‘on’
  • cookie_timeout (int [0-86400]) – Lifetime of cookie in seconds. Max 1 day. sticky_session must be ‘on’
  • cookie (str) – The Cookie key to use as sticky_session indicator. sticky_session_type must be ‘server’
  • domain (str) – the Host header to use for the health check
  • uri (str) – URL path for healthcheck. E.g. /health
update_tcp_listener(load_balancer_id, listener_port, healthy_threshold=None, unhealthy_threshold=None, scheduler=None, health_check=None, connect_timeout=None, interval=None, connect_port=None, persistence_timeout=None)[source]

Update an existing TCP SLB Listener

Parameters:
  • load_balancer_id (str) – LoadBalancerId unique identifier of the SLB.
  • listener_port (int) – Port for the SLB to listen on
  • healthy_threshold (int) – Number of successful healthchecks before considering the listener healthy. Default 3.
  • unhealthy_threshold (int) – Number of failed healthchecks before considering the listener unhealthy. Default 3.
  • scheduler (str) – wrr or wlc. Round Robin (default) or Least Connections.
  • health_check (bool) – True for ‘on’ and False for ‘off’ (default)
  • connect_timeout (int) – number of seconds to timeout and fail a health check
  • interval (int) – number of seconds between health checks
  • connect_port (int) – defaults to backend_server_port
  • persistence_timeout (int) – number of seconds to hold TCP connection open