libcloud.loadbalancer.drivers.rackspace module

class libcloud.loadbalancer.drivers.rackspace.RackspaceAccessRule(id=None, rule_type=None, address=None)[source]

Bases: object

An access rule allows or denies traffic to a Load Balancer based on the incoming IPs.

Parameters:
  • id (int) – Unique identifier to refer to this rule by.

  • rule_type – RackspaceAccessRuleType.ALLOW or RackspaceAccessRuleType.DENY.

  • address (str) – IP address or cidr (can be IPv4 or IPv6).

class libcloud.loadbalancer.drivers.rackspace.RackspaceAccessRuleType[source]

Bases: object

ALLOW = 0
DENY = 1
class libcloud.loadbalancer.drivers.rackspace.RackspaceConnection(*args, **kwargs)[source]

Bases: RackspaceConnection, PollingConnection

Initialize user_id and key; set secure to an int based on passed value.

auth_url: str = 'https://identity.api.rackspacecloud.com'
cache_busting = True
encode_data(data)[source]

Encode body data.

Override in a provider’s subclass.

get_poll_request_kwargs(response, context, request_kwargs)[source]

Return keyword arguments which are passed to the request() method when polling for the job status.

Parameters:
  • response (dict) – Response object returned by poll request.

  • request_kwargs – Kwargs previously used to initiate the poll request.

:return dict Keyword arguments

has_completed(response)[source]

Return job completion status.

Parameters:

response (HTTPResponse) – Response object returned by poll request.

:return bool True if the job has completed, False otherwise.

poll_interval = 2
request(action, params=None, data='', headers=None, method='GET')[source]

Request a given action.

Basically a wrapper around the connection object’s request that does some helpful pre-processing.

Parameters:
  • action (str) – A path. This can include arguments. If included, any extra parameters are appended to the existing ones.

  • params (dict) – Optional mapping of additional parameters to send. If None, leave as an empty dict.

  • data (unicode) – A body of data to send with the request.

  • headers (dict) – Extra headers to add to the request None, leave as an empty dict.

  • method (str) – An HTTP method such as “GET” or “POST”.

  • raw (bool) – True to perform a “raw” request aka only send the headers and use the rawResponseCls class. This is used with storage API when uploading a file.

  • stream (bool) – True to return an iterator in Response.iter_content and allow streaming of the response data (for downloading large files)

  • retry_failed – True if failed requests should be retried. This argument can override module level constant and environment variable value on per-request basis.

Returns:

An Response instance.

Return type:

Response instance

responseCls

alias of RackspaceResponse

timeout: int | float | None = 80
class libcloud.loadbalancer.drivers.rackspace.RackspaceConnectionThrottle(min_connections, max_connections, max_connection_rate, rate_interval_seconds)[source]

Bases: object

Parameters:
  • min_connections (int) – Minimum number of connections per IP address before applying throttling.

  • max_connections (int) – Maximum number of connections per IP address. (Must be between 0 and 100000, 0 allows an unlimited number of connections.)

  • max_connection_rate (int) – Maximum number of connections allowed from a single IP address within the given rate_interval_seconds. (Must be between 0 and 100000, 0 allows an unlimited number of connections.)

  • rate_interval_seconds (int) – Interval at which the max_connection_rate is enforced. (Must be between 1 and 3600.)

class libcloud.loadbalancer.drivers.rackspace.RackspaceHTTPHealthMonitor(type, delay, timeout, attempts_before_deactivation, path, body_regex, status_regex)[source]

Bases: RackspaceHealthMonitor

A HTTP health monitor adds extra features to a Rackspace health monitor.

Parameters:
  • path (str) – the HTTP path to monitor.

  • body_regex (str) – Regular expression used to evaluate the body of the HTTP response.

  • status_regex (str) – Regular expression used to evaluate the HTTP status code of the response.

class libcloud.loadbalancer.drivers.rackspace.RackspaceHealthMonitor(type, delay, timeout, attempts_before_deactivation)[source]

Bases: object

Parameters:
  • type (str) – type of load balancer. currently CONNECT (connection monitoring), HTTP, HTTPS (connection and HTTP monitoring) are supported.

  • delay (int) – minimum seconds to wait before executing the health monitor. (Must be between 1 and 3600)

  • timeout (int) – maximum seconds to wait when establishing a connection before timing out. (Must be between 1 and 3600)

  • attempts_before_deactivation (int) – Number of monitor failures before removing a node from rotation. (Must be between 1 and 10)

class libcloud.loadbalancer.drivers.rackspace.RackspaceLBDriver(key, secret=None, secure=True, host=None, port=None, region='ord', **kwargs)[source]

Bases: Driver, OpenStackDriverMixin

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

CONDITION_LB_MEMBER_MAP = {0: 'ENABLED', 1: 'DISABLED', 2: 'DRAINING'}
LB_MEMBER_CONDITION_MAP = {'DISABLED': 1, 'DRAINING': 2, 'ENABLED': 0}
LB_STATE_MAP = {'ACTIVE': 0, 'BUILD': 1, 'DELETED': 4, 'ERROR': 3, 'PENDING_DELETE': 1, 'PENDING_UPDATE': 1}
api_name = 'rackspace_lb'
balancer_attach_member(balancer, member)[source]

Attach a member to balancer

Parameters:
  • balancer (LoadBalancer) – LoadBalancer which should be used

  • member (Member) – Member to join to the balancer

Returns:

Member after joining the balancer.

Return type:

Member

balancer_detach_member(balancer, member)[source]

Detach member from balancer

Parameters:
  • balancer (LoadBalancer) – LoadBalancer which should be used

  • member (Member) – Member which should be used

Returns:

True if member detach was successful, otherwise False.

Return type:

bool

balancer_list_members(balancer)[source]

Return list of members attached to balancer

Parameters:

balancer (LoadBalancer) – LoadBalancer which should be used

Return type:

list of Member

connectionCls

alias of RackspaceConnection

create_balancer(name, members, protocol='http', port=80, algorithm=1)[source]

Create a new load balancer instance

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

  • port (str) – Port the load balancer should listen on, defaults to 80

  • protocol (str) – Loadbalancer protocol, defaults to http.

  • members (list of Member) – list of Members to attach to balancer

  • algorithm (Algorithm) – Load balancing algorithm, defaults to ROUND_ROBIN.

Return type:

LoadBalancer

destroy_balancer(balancer)[source]

Destroy a load balancer

Parameters:

balancer (LoadBalancer) – LoadBalancer which should be used

Returns:

True if the destroy was successful, otherwise False.

Return type:

bool

ex_balancer_access_list(balancer)[source]

List the access list.

Parameters:

balancer (LoadBalancer) – Balancer which should be used

Return type:

list of RackspaceAccessRule

ex_balancer_attach_members(balancer, members)[source]

Attaches a list of members to a load balancer.

Parameters:
  • balancer (LoadBalancer) – The Balancer to which members will be attached.

  • members (list of Member) – A list of Members to attach.

Return type:

list of Member

ex_balancer_detach_members(balancer, members)[source]

Detaches a list of members from a balancer (the API supports up to 10). This method blocks until the detach request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – The Balancer to detach members from.

  • members (list of Member) – A list of Members to detach.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_balancer_detach_members_no_poll(balancer, members)[source]

Detaches a list of members from a balancer (the API supports up to 10). This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – The Balancer to detach members from.

  • members (list of Member) – A list of Members to detach.

Returns:

Returns whether the detach request was accepted.

Return type:

bool

ex_balancer_update_member(balancer, member, **kwargs)[source]

Updates a Member’s extra attributes for a Balancer. The attributes can include ‘weight’ or ‘condition’. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to update the member on.

  • member (Member) – Member which should be used

  • **kwargs

    New attributes. Should contain either ‘weight’

or ‘condition’. ‘condition’ can be set to ‘ENABLED’, ‘DISABLED’. or ‘DRAINING’. ‘weight’ can be set to a positive integer between 1 and 100, with a higher weight indicating that the node will receive more traffic (assuming the Balancer is using a weighted algorithm). :type **kwargs: dict

Returns:

Updated Member.

Return type:

Member

ex_balancer_update_member_no_poll(balancer, member, **kwargs)[source]

Updates a Member’s extra attributes for a Balancer. The attribute can include ‘weight’ or ‘condition’. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to update the member on.

  • member (Member) – Member which should be used

  • **kwargs

    New attributes. Should contain either ‘weight’

or ‘condition’. ‘condition’ can be set to ‘ENABLED’, ‘DISABLED’. or ‘DRAINING’. ‘weight’ can be set to a positive integer between 1 and 100, with a higher weight indicating that the node will receive more traffic (assuming the Balancer is using a weighted algorithm). :type **kwargs: dict

Returns:

Returns whether the update request was accepted.

Return type:

bool

ex_create_balancer(name, members, protocol='http', port=80, algorithm=1, vip='PUBLIC')[source]

Creates a new load balancer instance

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

  • members (list of Member) – list of:class:`Member`s to attach to balancer

  • protocol (str) – Loadbalancer protocol, defaults to http.

  • port (str) – Port the load balancer should listen on, defaults to 80

  • algorithm (Algorithm) – Load balancing algorithm, defaults to LBAlgorithm.ROUND_ROBIN

  • vip (str) – Virtual ip type of PUBLIC, SERVICENET, or ID of a virtual ip

Return type:

LoadBalancer

ex_create_balancer_access_rule(balancer, rule)[source]

Adds an access rule to a Balancer’s access list. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to create the access rule for.

  • rule (RackspaceAccessRule) – Access Rule to add to the balancer.

Returns:

The created access rule.

Return type:

RackspaceAccessRule

ex_create_balancer_access_rule_no_poll(balancer, rule)[source]

Adds an access rule to a Balancer’s access list. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to create the access rule for.

  • rule (RackspaceAccessRule) – Access Rule to add to the balancer.

Returns:

Returns whether the create request was accepted.

Return type:

bool

ex_create_balancer_access_rules(balancer, rules)[source]

Adds a list of access rules to a Balancer’s access list. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
Returns:

The created access rules.

Return type:

RackspaceAccessRule

ex_create_balancer_access_rules_no_poll(balancer, rules)[source]

Adds a list of access rules to a Balancer’s access list. This method returns immediately.

Parameters:
Returns:

Returns whether the create request was accepted.

Return type:

bool

ex_destroy_balancer_access_rule(balancer, rule)[source]

Removes an access rule from a Balancer’s access list. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to remove the access rule from.

  • rule (RackspaceAccessRule) – Access Rule to remove from the balancer.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_destroy_balancer_access_rule_no_poll(balancer, rule)[source]

Removes an access rule from a Balancer’s access list. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to remove the access rule from.

  • rule (RackspaceAccessRule) – Access Rule to remove from the balancer.

Returns:

Returns whether the destroy request was accepted.

Return type:

bool

ex_destroy_balancer_access_rules(balancer, rules)[source]

Removes a list of access rules from a Balancer’s access list. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_destroy_balancer_access_rules_no_poll(balancer, rules)[source]

Removes a list of access rules from a Balancer’s access list. This method returns immediately.

Parameters:
Returns:

Returns whether the destroy request was accepted.

Return type:

bool

ex_destroy_balancers(balancers)[source]

Destroys a list of Balancers (the API supports up to 10).

Parameters:

balancers (list of LoadBalancer) – A list of Balancers to destroy.

Returns:

Returns whether the destroy request was accepted.

Return type:

bool

ex_disable_balancer_connection_logging(balancer)[source]

Disables connection logging for a Balancer. This method blocks until the enable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to disable connection logging on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_disable_balancer_connection_logging_no_poll(balancer)[source]

Disables connection logging for a Balancer. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to disable connection logging on.

Returns:

Returns whether the disable request was accepted.

Return type:

bool

ex_disable_balancer_connection_throttle(balancer)[source]

Disables a Balancer’s connection throttle. This method blocks until the disable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to disable connection throttle on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_disable_balancer_connection_throttle_no_poll(balancer)[source]

Disables a Balancer’s connection throttle. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to disable connection throttle on.

Returns:

Returns whether the disable request was accepted.

Return type:

bool

ex_disable_balancer_custom_error_page(balancer)[source]

Disables a Balancer’s custom error page, returning its error page to the Rackspace-provided default. This method blocks until the disable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to disable the custom error page for.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_disable_balancer_custom_error_page_no_poll(balancer)[source]

Disables a Balancer’s custom error page, returning its error page to the Rackspace-provided default. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to disable the custom error page for.

Returns:

Returns whether the disable request was accepted.

Return type:

bool

ex_disable_balancer_health_monitor(balancer)[source]

Disables a Balancer’s health monitor. This method blocks until the disable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to disable health monitor on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_disable_balancer_health_monitor_no_poll(balancer)[source]

Disables a Balancer’s health monitor. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to disable health monitor on.

Returns:

Returns whether the disable request was accepted.

Return type:

bool

ex_disable_balancer_session_persistence(balancer)[source]

Disables session persistence for a Balancer. This method blocks until the disable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to disable session persistence on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_disable_balancer_session_persistence_no_poll(balancer)[source]

Disables session persistence for a Balancer. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to disable session persistence for.

Returns:

Returns whether the disable request was accepted.

Return type:

bool

ex_enable_balancer_connection_logging(balancer)[source]

Enables connection logging for a Balancer. This method blocks until the enable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to enable connection logging on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_enable_balancer_connection_logging_no_poll(balancer)[source]

Enables connection logging for a Balancer. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to enable connection logging on.

Returns:

Returns whether the enable request was accepted.

Return type:

bool

ex_enable_balancer_session_persistence(balancer)[source]

Enables session persistence for a Balancer by setting the persistence type to ‘HTTP_COOKIE’. This method blocks until the enable request has been processed and the balancer is in a RUNNING state again.

Parameters:

balancer (LoadBalancer) – Balancer to enable session persistence on.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_enable_balancer_session_persistence_no_poll(balancer)[source]

Enables session persistence for a Balancer by setting the persistence type to ‘HTTP_COOKIE’. This method returns immediately.

Parameters:

balancer (LoadBalancer) – Balancer to enable session persistence on.

Returns:

Returns whether the enable request was accepted.

Return type:

bool

ex_get_balancer_error_page(balancer)[source]

List error page configured for the specified load balancer.

Parameters:

balancer (LoadBalancer) – Balancer which should be used

Return type:

str

ex_list_algorithm_names()[source]

Lists algorithms supported by the API. Returned as strings because this list may change in the future.

Return type:

list of str

ex_list_current_usage(balancer)[source]

Return current load balancer usage report.

Parameters:

balancer (LoadBalancer) – Balancer to remove the access rules from.

Returns:

Raw load balancer usage object.

Return type:

dict

ex_list_protocols_with_default_ports()[source]

List protocols with default ports.

Return type:

list of tuple

Returns:

A list of protocols with default ports included.

ex_update_balancer_connection_throttle(balancer, connection_throttle)[source]

Updates a Balancer’s connection throttle. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to update connection throttle on.

  • connection_throttle (RackspaceConnectionThrottle) – Connection Throttle for the balancer.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_update_balancer_connection_throttle_no_poll(balancer, connection_throttle)[source]

Sets a Balancer’s connection throttle. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to update connection throttle on.

  • connection_throttle (RackspaceConnectionThrottle) – Connection Throttle for the balancer.

Returns:

Returns whether the update request was accepted.

Return type:

bool

ex_update_balancer_error_page(balancer, page_content)[source]

Updates a Balancer’s custom error page. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to update the custom error page for.

  • page_content (str) – HTML content for the custom error page.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_update_balancer_error_page_no_poll(balancer, page_content)[source]

Updates a Balancer’s custom error page. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to update the custom error page for.

  • page_content (str) – HTML content for the custom error page.

Returns:

Returns whether the update request was accepted.

Return type:

bool

ex_update_balancer_health_monitor(balancer, health_monitor)[source]

Sets a Balancer’s health monitor. This method blocks until the update request has been processed and the balancer is in a RUNNING state again.

Parameters:
  • balancer (LoadBalancer) – Balancer to update.

  • health_monitor (RackspaceHealthMonitor) – Health Monitor for the balancer.

Returns:

Updated Balancer.

Return type:

LoadBalancer

ex_update_balancer_health_monitor_no_poll(balancer, health_monitor)[source]

Sets a Balancer’s health monitor. This method returns immediately.

Parameters:
  • balancer (LoadBalancer) – Balancer to update health monitor on.

  • health_monitor (RackspaceHealthMonitor) – Health Monitor for the balancer.

Returns:

Returns whether the update request was accepted.

Return type:

bool

ex_update_balancer_no_poll(balancer, **kwargs)[source]

Update balancer no poll.

@inherits: Driver.update_balancer

get_balancer(balancer_id)[source]

Return a LoadBalancer object.

Parameters:

balancer_id (str) – id of a load balancer you want to fetch

Return type:

LoadBalancer

list_balancers(ex_member_address=None, ex_status=None, ex_changes_since=None, ex_params={})[source]

@inherits: Driver.list_balancers

Parameters:
  • ex_member_address (str) – Optional IP address of the attachment member. If provided, only the load balancers which have this member attached will be returned.

  • ex_status (str) – Optional. Filter balancers by status

  • ex_changes_since (str) – Optional. List all load balancers that have changed since the specified date/time

  • ex_params (dict) – Optional. Set parameters to be submitted to the API in the query string

list_protocols()[source]

Return a list of supported protocols.

Return type:

list of str

classmethod list_regions()[source]
name = 'Rackspace LB'
update_balancer(balancer, **kwargs)[source]

Sets the name, algorithm, protocol, or port on a load balancer.

Parameters:
  • balancer (LoadBalancer) – LoadBalancer which should be used

  • name (str) – New load balancer name

  • algorithm (Algorithm) – New load balancer algorithm

  • protocol (str) – New load balancer protocol

  • port (int) – New load balancer port

Return type:

LoadBalancer

website = 'http://www.rackspace.com/'
class libcloud.loadbalancer.drivers.rackspace.RackspaceResponse(response, connection)[source]

Bases: JsonResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)

  • connection (Connection) – Parent connection object.

parse_body()[source]

Parse response body.

Override in a provider’s subclass.

Returns:

Parsed body.

Return type:

str

success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:

bool

Returns:

True or False