lighthouse.haproxy.control

class lighthouse.haproxy.control.HAProxyControl(config_file_path, socket_file_path, pid_file_path)[source]

Bases: object

Class used to control a running HAProxy process.

Includes basic functionality for soft restarts as well as gathering info about the HAProxy process and its active nodes, plus methods for enabling or disabling nodes on the fly.

Also allows for sending commands to the HAProxy control socket itself.

restart()[source]

Performs a soft reload of the HAProxy process.

get_version()[source]

Returns a tuple representing the installed HAProxy version.

The value of the tuple is (<major>, <minor>, <patch>), e.g. if HAProxy version 1.5.3 is installed, this will return (1, 5, 3).

get_info()[source]

Parses the output of a “show info” HAProxy command and returns a simple dictionary of the results.

get_active_nodes()[source]

Returns a dictionary of lists, where the key is the name of a service and the list includes all active nodes associated with that service.

enable_node(service_name, node_name)[source]

Enables a given node name for the given service name via the “enable server” HAProxy command.

disable_node(service_name, node_name)[source]

Disables a given node name for the given service name via the “disable server” HAProxy command.

send_command(command)[source]

Sends a given command to the HAProxy control socket.

Returns the response from the socket as a string.

If a known error response (e.g. “Permission denied.”) is given then the appropriate exception is raised.

process_command_response(command, response)[source]

Takes an HAProxy socket command and its response and either raises an appropriate exception or returns the formatted response.

exception lighthouse.haproxy.control.HAProxyControlError[source]

Bases: exceptions.Exception

Base exception for HAProxyControl-related actions.

exception lighthouse.haproxy.control.UnknownCommandError[source]

Bases: lighthouse.haproxy.control.HAProxyControlError

Exception raised if an unrecognized command was sent to the HAProxy socket.

exception lighthouse.haproxy.control.PermissionError[source]

Bases: lighthouse.haproxy.control.HAProxyControlError

Exception denoting that the HAProxy control socket does not have proper authentication level for executing a given command.

For example, if the socket is set up with a a level lower than “admin”, the enable/disable server commands will fail.

exception lighthouse.haproxy.control.UnknownServerError[source]

Bases: lighthouse.haproxy.control.HAProxyControlError

Exception raised if an enable/disable server command is executed against a backend that HAProxy doesn’t know about.