Channel Revision Published Runs on
latest/stable 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/stable 66 08 Nov 2021
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/candidate 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/candidate 64 14 Oct 2021
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/beta 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04
latest/edge 147 29 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/edge 37 11 Nov 2020
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
2.8/stable 216 20 Aug 2025
Ubuntu 24.04
2.8/edge 228 11 Sep 2025
Ubuntu 24.04
juju deploy haproxy
Show information

Platform:

Ubuntu
24.04 22.04 20.04 18.04 16.04 14.04

charms.haproxy.v0.haproxy_route_tcp

Haproxy-route interface library.

Getting Started

To get started using the library, you just need to fetch the library using charmcraft.

cd some-charm
charmcraft fetch-lib charms.haproxy.v1.haproxy_route_tcp

In the metadata.yaml of the charm, add the following:

requires:
    backend-tcp:
        interface: haproxy-route-tcp
        limit: 1

Then, to initialise the library:

from charms.haproxy.v0.haproxy_route_tcp import HaproxyRouteTcpRequirer

class SomeCharm(CharmBase):
  def __init__(self, *args):
    # ...

    # There are 2 ways you can use the requirer implementation:
    # 1. To initialize the requirer with parameters:
    self.haproxy_route_tcp_requirer = HaproxyRouteTcpRequirer(
        self,
        relation_name="haproxy-route-tcp"
        port=<optional>  # The port exposed on the provider.
        backend_port=<optional>  # The port where the backend service is listening.
        hosts=<optional>  # List of backend server addresses. Currently only support IP addresses.
        sni=<optional>  # Server name identification. Used to route traffic to the service.
        check_interval=<optional>  # Interval between health checks in seconds.
        check_rise=<optional>  # Number of successful health checks
            before server is considered up.
        check_fall=<optional>  # Number of failed health checks before server is considered down.
        check_type=<optional>  # Can be 'generic', 'mysql', 'postgres', 'redis' or 'smtp'ßß.
        check_send=<optional>  # Only used in generic health checks,
            specify a string to send in the health check request.
        check_expect=<optional>  # Only used in generic health checks,
            specify the expected response from a health check request.
        check_db_user=<optional>  # Only used if type is postgres or mysql,
            specify the user name to enable HAproxy to send a Client Authentication packet.
        load_balancing_algorithm=<optional>  # Algorithm to use for load balancing.
        load_balancing_consistent_hashing=<optional>  # Whether to use consistent hashing.
        rate_limit_connections_per_minute=<optional>  # Maximum connections allowed per minute.
        rate_limit_policy=<optional>  # Policy to apply when rate limit is reached.
        upload_limit=<optional>  # Maximum upload bandwidth in bytes per second.
        download_limit=<optional>  # Maximum download bandwidth in bytes per second.
        retry_count=<optional>  # Number of times to retry failed requests.
        retry_redispatch=<optional>  # Whether to redispatch failed requests to another server.
        server_timeout=<optional>  # Timeout for requests from haproxy
            to backend servers in seconds.
        connect_timeout=<optional>  # Timeout for client requests to haproxy in seconds.
        queue_timeout=<optional>  # Timeout for requests waiting in queue in seconds.
        server_maxconn=<optional>  # Maximum connections per server.
        ip_deny_list=<optional>  # List of source IP addresses to block.
        enforce_tls=<optional>  # Whether to enforce TLS for all traffic coming to the backend.
        tls_terminate=<optional>  # Whether to enable tls termination on the dedicated frontend.
        unit_address=<optional>  # IP address of the unit
            (if not provided, will use binding address).
    )

    # 2.To initialize the requirer with no parameters, i.e
    # self.haproxy_route_tcp_requirer = HaproxyRouteTcpRequirer(self)
    # This will simply initialize the requirer class and it won't perfom any action.

    # Afterwards regardless of how you initialized the requirer you can call the
    # provide_haproxy_route_requirements method anywhere in your charm to update the requirer data.
    # The method takes the same number of parameters as the requirer class.
    # provide_haproxy_route_tcp_requirements(port=, ...)

    self.framework.observe(
        self.framework.on.config_changed, self._on_config_changed
    )
    self.framework.observe(
        self.haproxy_route_tcp_requirer.on.ready, self._on_endpoints_ready
    )
    self.framework.observe(
        self.haproxy_route_tcp_requirer.on.removed, self._on_endpoints_removed
    )

    def _on_config_changed(self, event: ConfigChangedEvent) -> None:
        self.haproxy_route_tcp_requirer.provide_haproxy_route_tcp_requirements(...)

    def _on_endpoints_ready(self, _: EventBase) -> None:
        # Handle endpoints ready event
        if endpoints := self.haproxy_route_tcp_requirer.get_proxied_endpoints():
            # Do something with the endpoints information
        ...

    def _on_endpoints_removed(self, _: EventBase) -> None:
        # Handle endpoints removed event
        ...

    # 3.To initialize the requirer together with helper methods.
    # This will use chaining of the helper methods to populate the requirer
    # data attributes.
    self.haproxy_tcp_route_requirer = HaproxyRouteTcpRequirer(self, relation_name="")         .configure_port(4000)         .configure_backend_port(5000)         .configure_health_check(60, 5, 5)         .configure_rate_limit(10, TCPRateLimitPolicy.SILENT)         .update_relation_data()


## Using the library as the provider
The provider charm should expose the interface as shown below:
```yaml
provides:
    haproxy-route-tcp:
        interface: haproxy-route-tcp

Note that this interface supports relating to multiple endpoints.

Then, to initialise the library:

from charms.haproxy.v0.haproxy_route import HaproxyRouteTcpProvider

class SomeCharm(CharmBase):
    self.haproxy_route_tcp_provider = HaproxyRouteTcpProvider(self)
    self.framework.observe(
        self.haproxy_route_tcp_provider.on.data_available, self._on_haproxy_route_data_available
    )

    def _on_haproxy_route_data_available(self, event: EventBase) -> None:
        data = self.haproxy_route_tcp_provider.get_data(self.haproxy_route_tcp_provider.relations)
        # data is an object of the `HaproxyRouteTcpRequirersData` class, see below for the
        # available attributes
        ...

        # Publish the endpoints to the requirers
        for requirer_data in data.requirers_data:
            self.haproxy_route_tcp.publish_proxied_endpoints(
                ["..."], requirer_data.relation_id
            )

Index

def value_contains_invalid_characters(value)

Validate if value contains invalid haproxy config characters.

Arguments

value

The value to validate.

Returns

The validated value.

class DataValidationError

Description

Raised when data validation fails. None

class HaproxyRouteTcpInvalidRelationDataError

Description

Raised when data validation of the haproxy-route relation fails. None

class TCPHealthCheckType

Enum of possible rate limiting policies.

Description

Attrs: GENERIC: deny a client's HTTP request to return a 403 Forbidden error. MYSQL: closes the connection immediately without sending a response. POSTGRES: disconnects immediately without notifying the client that the connection has been closed. REDIS: closes the connection immediately without sending a response. SMTP: closes the connection immediately without sending a response.

class TCPServerHealthCheck

Configuration model for backend server health checks.

Attributes

interval
Number of seconds between consecutive health check attempts.
rise
Number of consecutive successful health checks required for up.
fall
Number of consecutive failed health checks required for DOWN.
check_type
Health check type, Can be “generic”, “mysql”, “postgres”, “redis” or “smtp”.
send
Only used in generic health checks, specify a string to send in the health check request.
expect
Only used in generic health checks, specify the expected response from a health check request.
db_user
Only used if type is postgres or mysql, specify the user name to enable HAproxy to send a Client Authentication packet.

Methods

TCPServerHealthCheck. check_all_required_fields_set( self )

Check that all required fields for health check are set.

Returns

The validated model.

class TCPRateLimitPolicy

Enum of possible rate limiting policies.

Description

Attrs: REJECT: Send a TCP reset packet to close the connection. SILENT: disconnects immediately without notifying the client that the connection has been closed (no packet sent).

class RateLimit

Configuration model for connection rate limiting.

Attributes

connections_per_minute
Number of connections allowed per minute for a client.
policy
Action to take when the rate limit is exceeded.

class LoadBalancingAlgorithm

Enum of possible http_route types.

Description

Attrs: LEASTCONN: The server with the lowest number of connections receives the connection. SRCIP: Load balance using the hash of The source IP address. ROUNDROBIN: Each server is used in turns, according to their weights.

class TCPLoadBalancingConfiguration

Configuration model for load balancing.

Attributes

algorithm
Algorithm to use for load balancing.
consistent_hashing
Use consistent hashing to avoid redirection when servers are added/removed.

Methods

TCPLoadBalancingConfiguration. validate_attributes( self )

Check that algorithm-specific configs are only set with their respective algorithm.

Returns

The validated model.

class BandwidthLimit

Configuration model for bandwidth rate limiting.

Attributes

upload
Limit upload speed (bytes per second).
download
Limit download speed (bytes per second).

class Retry

Configuration model for retry.

Attributes

count
How many times should a request retry.
redispatch
Whether to redispatch failed requests to another server.

class TimeoutConfiguration

Configuration model for timeout.

Attributes

server
Timeout for requests from haproxy to backend servers.
connect
Timeout for client requests to haproxy.
queue
Timeout for requests waiting in the queue after server-maxconn is reached.

class TcpRequirerApplicationData

Configuration model for HAProxy route requirer application data.

Attributes

port
The port exposed on the provider.
backend_port
The port where the backend service is listening. Defaults to the provider port.
hosts
List of backend server addresses. Currently only support IP addresses.
sni
Server name identification. Used to route traffic to the service.
check
TCP health check configuration
load_balancing
Load balancing configuration.
rate_limit
Rate limit configuration.
bandwidth_limit
Bandwith limit configuration.
retry
Retry configuration.
timeout
Timeout configuration.
server_maxconn
Maximum connections per server.
ip_deny_list
List of source IP addresses to block.
enforce_tls
Whether to enforce TLS for all traffic coming to the backend.
tls_terminate
Whether to enable tls termination on the dedicated frontend.

Methods

TcpRequirerApplicationData. assign_default_backend_port( self )

Assign a default value to backend_port if not set.

Returns

The model with backend_port default value applied.

Description

The value is equal to the provider port.

TcpRequirerApplicationData. sni_set_when_not_enforcing_tls( self )

Check if sni is configured but TLS is disabled.

Returns

The validated model.

class HaproxyRouteTcpProviderAppData

haproxy-route provider databag schema.

Attributes

endpoints
The list of proxied endpoints that maps to the backend.

class TcpRequirerUnitData

haproxy-route requirer unit data.

Attributes

address
IP address of the unit.

class HaproxyRouteTcpRequirerData

haproxy-route requirer data.

Attributes

relation_id
Id of the relation.
application
Name of the requirer application.
application_data
Application data.
units_data
Units data

class HaproxyRouteTcpRequirersData

haproxy-route requirers data.

Attributes

requirers_data
List of requirer data.
relation_ids_with_invalid_data
List of relation ids that contains invalid data.

Methods

HaproxyRouteTcpRequirersData. check_ports_unique( self )

Check that requirers define unique ports.

Returns

The validated model, with invalid relation IDs updated in self.relation_ids_with_invalid_data

class HaproxyRouteTcpDataAvailableEvent

HaproxyRouteDataAvailableEvent custom event.

Description

This event indicates that the requirers data are available.

class HaproxyRouteTcpDataRemovedEvent

HaproxyRouteDataRemovedEvent custom event.

Description

This event indicates that one of the endpoints was removed.

class HaproxyRouteTcpProviderEvents

List of events that the TLS Certificates requirer charm can leverage.

Attributes

data_available
This event indicates that the haproxy-route endpoints are available.
data_removed
This event indicates that one of the endpoints was removed.

class HaproxyRouteTcpProvider

Haproxy-route interface provider implementation.

Attributes

on
Custom events of the provider.
relations
Related appliations.

Methods

HaproxyRouteTcpProvider. __init__( self , charm: CharmBase , relation_name: str , raise_on_validation_error: bool )

Initialize the HaproxyRouteProvider.

Arguments

charm

The charm that is instantiating the library.

relation_name

The name of the relation.

raise_on_validation_error

Whether the library should raise HaproxyRouteTcpInvalidRelationDataError when requirer data validation fails. If this is set to True the provider charm needs to also catch and handle the thrown exception.

HaproxyRouteTcpProvider. relations( self )

Description

The list of Relation instances associated with this endpoint. None

HaproxyRouteTcpProvider. get_data( self , relations )

Fetch requirer data.

Arguments

relations

A list of Relation instances to fetch data from.

Returns

HaproxyRouteRequirersData

Validated data from all haproxy-route requirers.

HaproxyRouteTcpProvider. publish_proxied_endpoints( self , endpoints , relation: Relation )

Publish to the app databag the proxied endpoints.

Arguments

endpoints

The list of proxied endpoints to publish.

relation

The relation with the requirer application.

class HaproxyRouteTcpEnpointsReadyEvent

Description

HaproxyRouteTcpEnpointsReadyEvent custom event. None

class HaproxyRouteTcpEndpointsRemovedEvent

Description

HaproxyRouteTcpEndpointsRemovedEvent custom event. None

class HaproxyRouteTcpRequirerEvents

List of events that the TLS Certificates requirer charm can leverage.

Attributes

ready
when the provider proxied endpoints are ready.
removed
when the provider

class HaproxyRouteTcpRequirer

haproxy-route interface requirer implementation.

Attributes

on
Custom events of the requirer.

Methods

HaproxyRouteTcpRequirer. __init__( self , charm: CharmBase , relation_name: str )

Initialize the HaproxyRouteRequirer.

Arguments

charm

The charm that is instantiating the library.

relation_name

The name of the relation to bind to.

port

The provider port.

backend_port

List of ports the service is listening on.

hosts

List of backend server addresses. Currently only support IP addresses.

sni

List of URL paths to route to this service.

check_interval

Interval between health checks in seconds.

check_rise

Number of successful health checks before server is considered up.

check_fall

Number of failed health checks before server is considered down.

check_type

Health check type, Can be “generic”, “mysql”, “postgres”, “redis” or “smtp”.

check_send

Only used in generic health checks, specify a string to send in the health check request.

check_expect

Only used in generic health checks, specify the expected response from a health check request.

check_db_user

Only used if type is postgres or mysql, specify the user name to enable HAproxy to send a Client Authentication packet.

load_balancing_algorithm

Algorithm to use for load balancing.

load_balancing_consistent_hashing

Whether to use consistent hashing.

rate_limit_connections_per_minute

Maximum connections allowed per minute.

rate_limit_policy

Policy to apply when rate limit is reached.

upload_limit

Maximum upload bandwidth in bytes per second.

download_limit

Maximum download bandwidth in bytes per second.

retry_count

Number of times to retry failed requests.

retry_redispatch

Whether to redispatch failed requests to another server.

server_timeout

Timeout for requests from haproxy to backend servers in seconds.

connect_timeout

Timeout for client requests to haproxy in seconds.

queue_timeout

Timeout for requests waiting in queue in seconds.

server_maxconn

Maximum connections per server.

ip_deny_list

List of source IP addresses to block.

enforce_tls

Whether to enforce TLS for all traffic coming to the backend.

tls_terminate

Whether to enable tls termination on the dedicated frontend.

unit_address

IP address of the unit (if not provided, will use binding address).

HaproxyRouteTcpRequirer. provide_haproxy_route_tcp_requirements( self )

Update haproxy-route requirements data in the relation.

Arguments

port

The provider port.

backend_port

List of ports the service is listening on.

hosts

List of backend server addresses. Currently only support IP addresses.

sni

List of URL paths to route to this service.

check_interval

Interval between health checks in seconds.

check_rise

Number of successful health checks before server is considered up.

check_fall

Number of failed health checks before server is considered down.

check_type

Health check type, Can be “generic”, “mysql”, “postgres”, “redis” or “smtp”.

check_send

Only used in generic health checks, specify a string to send in the health check request.

check_expect

Only used in generic health checks, specify the expected response from a health check request.

check_db_user

Only used if type is postgres or mysql, specify the user name to enable HAproxy to send a Client Authentication packet.

load_balancing_algorithm

Algorithm to use for load balancing.

load_balancing_consistent_hashing

Whether to use consistent hashing.

rate_limit_connections_per_minute

Maximum connections allowed per minute.

rate_limit_policy

Policy to apply when rate limit is reached.

upload_limit

Maximum upload bandwidth in bytes per second.

download_limit

Maximum download bandwidth in bytes per second.

retry_count

Number of times to retry failed requests.

retry_redispatch

Whether to redispatch failed requests to another server.

server_timeout

Timeout for requests from haproxy to backend servers in seconds.

connect_timeout

Timeout for client requests to haproxy in seconds.

queue_timeout

Timeout for requests waiting in queue in seconds.

server_maxconn

Maximum connections per server.

ip_deny_list

List of source IP addresses to block.

enforce_tls

Whether to enforce TLS for all traffic coming to the backend.

tls_terminate

Whether to enable tls termination on the dedicated frontend.

unit_address

IP address of the unit (if not provided, will use binding address).

HaproxyRouteTcpRequirer. update_relation_data( self )

Description

Update both application and unit data in the relation. None

HaproxyRouteTcpRequirer. get_proxied_endpoints( self )

The full ingress URL to reach the current unit.

Returns

The provider URL or None if the URL isn't available yet or is not valid.

HaproxyRouteTcpRequirer. configure_port( self , port: int )

Set the provider port.

Arguments

port

The provider port to set

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_backend_port( self , backend_port: int )

Set the backend port.

Arguments

backend_port

The backend port to set

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_hosts( self , hosts )

Set backend hosts.

Arguments

hosts

The hosts list to set

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_sni( self , sni: str )

Set the SNI.

Arguments

sni

The SNI to set

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_health_check( self , interval: int , rise: int , fall: int , check_type: TCPHealthCheckType , send , expect , db_user )

Configure server health check.

Description

Args: interval: Number of seconds between consecutive health check attempts. rise: Number of consecutive successful health checks required for up. fall: Number of consecutive failed health checks required for DOWN. check_type: Health check type, Can be "generic", "mysql", "postgres", "redis" or "smtp". send: Only used in generic health checks, specify a string to send in the health check request. expect: Only used in generic health checks, specify the expected response from a health check request. db_user: Only used if type is postgres or mysql, specify the user name to enable HAproxy to send a Client Authentication packet.

Returns: Self: The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_rate_limit( self , connections_per_minute: int , policy: TCPRateLimitPolicy )

Configure rate limit.

Arguments

connections_per_minute

The number of connections per minute allowed

policy

The rate limit policy to apply

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_bandwidth_limit( self , upload_bytes_per_second , download_bytes_per_second )

Configure bandwidth limit.

Arguments

upload_bytes_per_second

Upload bandwidth limit in bytes per second

download_bytes_per_second

Download bandwidth limit in bytes per second

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_retry( self , retry_count: int , retry_redispatch: bool )

Configure retry.

Arguments

retry_count

The number of retries to attempt

retry_redispatch

Whether to enable retry redispatch

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_timeout( self , server_timeout_in_seconds , connect_timeout_in_seconds , queue_timeout_in_seconds )

Configure timeout.

Arguments

server_timeout_in_seconds

Server timeout.

connect_timeout_in_seconds

Connect timeout.

queue_timeout_in_seconds

Queue timeout

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_server_max_connections( self , max_connections: int )

Set the server max connections.

Arguments

max_connections

The number of max connections to set

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. disable_tls_termination( self )

Disable TLS termination.

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. allow_http( self )

Do not enforce TLS.

Returns

Self

The HaproxyRouteTcpRequirer class

HaproxyRouteTcpRequirer. configure_deny_list( self , ip_deny_list )

Configure IP deny list.

Arguments

ip_deny_list

List of IP addresses to deny

Returns

Self

The HaproxyRouteTcpRequirer class