---
title: Charmhub | Deploy HAProxy using Charmhub - The Open Operator Collection
description: Deploy the latest version of HAProxy on any cloud.
url: https://charmhub.io/haproxy/libraries/haproxy_route_tcp
---

# HAProxy

[haproxy-team](https://charmhub.io/publisher/haproxy-team "View all packages from haproxy-team")

* [haproxy-team](https://charmhub.io/publisher/haproxy-team "View all packages from haproxy-team")
* [Networking](https://charmhub.io/?filter=networking)

Platform:

24.04

22.04

20.04

18.04

16.04

14.04

stable 147

```
juju deploy haproxy
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#drawer)

## charms.haproxy.v1.haproxy\_route\_tcp

* [*Docstrings*Docstrings](https://charmhub.io/haproxy/libraries/haproxy_route_tcp)
  [*Code*Source code](https://charmhub.io/haproxy/libraries/haproxy_route_tcp/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.haproxy.v1.haproxy_route_tcp
    ```

    [Download haproxy\_route\_tcp.py](https://charmhub.io/haproxy/libraries/haproxy_route_tcp/download)
  + *Last updated* 11 Sep 2026
  + *Revision* Library version 1.7

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
```

###### Dependencies

This library requires the `validators` Python package for domain validation.
Add it to your charm's dependencies in `charmcraft.yaml`:

```
parts:
  charm:
    charm-python-packages:
      - validators
```

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.v1.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.v1.haproxy_route_tcp 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
  )](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#value_contains_invalid_characters)
* [def valid\_domain\_with\_wildcard(
  value
  )](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#valid_domain_with_wildcard)
* [class DataValidationError](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#datavalidationerror)
* [class HaproxyRouteTcpInvalidRelationDataError](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpinvalidrelationdataerror)
* [class TCPHealthCheckType](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcphealthchecktype)
* [class TCPServerHealthCheck](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcpserverhealthcheck)
* + [def check\_all\_required\_fields\_set(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcpserverhealthcheck-check_all_required_fields_set)
* [class TCPRateLimitPolicy](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcpratelimitpolicy)
* [class RateLimit](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#ratelimit)
* [class LoadBalancingAlgorithm](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#loadbalancingalgorithm)
* [class TCPLoadBalancingConfiguration](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcploadbalancingconfiguration)
* + [def validate\_attributes(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcploadbalancingconfiguration-validate_attributes)
* [class BandwidthLimit](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#bandwidthlimit)
* [class Retry](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#retry)
* [class TimeoutConfiguration](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#timeoutconfiguration)
* [class PortRange](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange)
* + [def from\_string(
    cls,
    value)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange-from_string)
* + [def port\_count(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange-port_count)
* + [def \_\_str\_\_(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange-__str__)
* + [def \_\_eq\_\_(
    self,
    other)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange-__eq__)
* + [def overlaps\_with(
    self,
    other)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portrange-overlaps_with)
* [class PortMapping](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portmapping)
* + [def from\_string(
    cls,
    value)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portmapping-from_string)
* + [def \_\_str\_\_(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portmapping-__str__)
* + [def offset(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#portmapping-offset)
* [class TcpRequirerApplicationData](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata)
* + [def validate\_port\_mapping(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-validate_port_mapping)
* + [def assign\_default\_backend\_port(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-assign_default_backend_port)
* + [def sni\_set\_when\_not\_enforcing\_tls(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-sni_set_when_not_enforcing_tls)
* + [def effective\_port\_mapping(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-effective_port_mapping)
* + [def port\_range(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-port_range)
* + [def backend\_port\_range(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-backend_port_range)
* + [def is\_port\_range(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerapplicationdata-is_port_range)
* [class HaproxyRouteTcpProviderAppData](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpproviderappdata)
* [class TcpRequirerUnitData](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#tcprequirerunitdata)
* [class HaproxyRouteTcpRequirerData](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirerdata)
* [class HaproxyRouteTcpRequirersData](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirersdata)
* [class HaproxyRouteTcpDataAvailableEvent](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpdataavailableevent)
* [class HaproxyRouteTcpDataRemovedEvent](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpdataremovedevent)
* [class HaproxyRouteTcpProviderEvents](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpproviderevents)
* [class HaproxyRouteTcpProvider](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpprovider)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name,
    raise\_on\_validation\_error)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpprovider-__init__)
* + [def relations(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpprovider-relations)
* + [def get\_data(
    self,
    relations)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpprovider-get_data)
* + [def publish\_proxied\_endpoints(
    self,
    endpoints,
    relation)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpprovider-publish_proxied_endpoints)
* [class HaproxyRouteTcpEnpointsReadyEvent](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpenpointsreadyevent)
* [class HAProxyRouteTcpBackendsRemovedEvent](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcpbackendsremovedevent)
* [class HaproxyRouteTcpRequirerEvents](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirerevents)
* [class HaproxyRouteTcpRequirer](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-__init__)
* + [def provide\_haproxy\_route\_tcp\_requirements(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-provide_haproxy_route_tcp_requirements)
* + [def update\_relation\_data(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-update_relation_data)
* + [def get\_proxied\_endpoints(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-get_proxied_endpoints)
* + [def configure\_port(
    self,
    port)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_port)
* + [def configure\_backend\_port(
    self,
    backend\_port)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_backend_port)
* + [def configure\_port\_mapping(
    self,
    port\_mapping)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_port_mapping)
* + [def configure\_hosts(
    self,
    hosts)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_hosts)
* + [def configure\_sni(
    self,
    sni)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_sni)
* + [def configure\_health\_check(
    self,
    interval,
    rise,
    fall,
    check\_type,
    send,
    expect,
    db\_user)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_health_check)
* + [def configure\_rate\_limit(
    self,
    connections\_per\_minute,
    policy)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_rate_limit)
* + [def configure\_bandwidth\_limit(
    self,
    upload\_bytes\_per\_second,
    download\_bytes\_per\_second)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_bandwidth_limit)
* + [def configure\_retry(
    self,
    retry\_count,
    retry\_redispatch)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_retry)
* + [def configure\_timeout(
    self,
    server\_timeout\_in\_seconds,
    connect\_timeout\_in\_seconds,
    queue\_timeout\_in\_seconds)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_timeout)
* + [def configure\_server\_max\_connections(
    self,
    max\_connections)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_server_max_connections)
* + [def disable\_tls\_termination(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-disable_tls_termination)
* + [def allow\_http(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-allow_http)
* + [def configure\_deny\_list(
    self,
    ip\_deny\_list)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-configure_deny_list)
* + [def enable\_proxy\_protocol(
    self)](https://charmhub.io/haproxy/libraries/haproxy_route_tcp#haproxyroutetcprequirer-enable_proxy_protocol)

#### def value\_contains\_invalid\_characters(value)

Validate if value contains invalid haproxy config characters.

Arguments

value

The value to validate.

Returns

The validated value.

#### def valid\_domain\_with\_wildcard(value: str)

Validate if value is a valid domain that can include a wildcard.

Arguments

value

The value to validate.

Returns

The validated value.

Description

The wildcard character (\*) can't be at the TLD level, for example \*.com is not valid.
This is supported natively by the library ( e.g domain("com") will raise a ValidationError ).

#### 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 PortRange

Represents a range of TCP ports.

Attributes

start

The starting port of the range (1-65535).

end

The ending port of the range (1-65535).

Methods

PortRange.
from\_string(

cls

,
value: str
)

Parse a port range from a string.

Arguments

value

The port range string to parse.

Returns

PortRange

The parsed port range.

Description

Accepts either a single port (`"8080"`) or a range (`"8080-8090"`).

PortRange.
port\_count(

*self*
)

Get the number of ports covered by this range.

Returns

int

The number of ports (inclusive of both ends).

PortRange.
\_\_str\_\_(

*self*
)

Return a string representation of the port range.

Description

A single port is rendered as a plain number, a range as "start-end".

PortRange.
\_\_eq\_\_(

*self*

,
other: object
)

Description

Check if this port range is the same as another port range. None

PortRange.
overlaps\_with(

*self*

,
other
)

Check if this port range overlaps with another port range.

Arguments

other

The other PortRange to check overlap with.

Returns

bool

True if the port ranges overlap, False otherwise.

#### class PortMapping

A mapping between a frontend port range and a backend port range.

Attributes

frontend

The port range exposed on the provider (frontend).

backend

The port range of the backend service.

Methods

PortMapping.
from\_string(

cls

,
value: str
)

Parse a port mapping from its string representation.

Arguments

value

The port mapping string to parse.

Returns

PortMapping

The parsed port mapping.

Description

The expected format is
`frontend_start-frontend_end:backend_start-backend_end`. A single port on
either side (e.g. `8080:9090`) is also accepted.

PortMapping.
\_\_str\_\_(

*self*
)

Description

Return the canonical string representation of the mapping. None

PortMapping.
offset(

*self*
)

Get the offset to translate a frontend port to its backend port.

Returns

int

backend\_port = frontend\_port + offset.

#### 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.

port\_mapping

Port mapping in the form
"frontend\_start-frontend\_end:backend\_start-backend\_end". Cannot be set at
the same time as port or backend\_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.

proxy\_protocol

Whether to enable PROXY protocol when connecting to backend servers.

Methods

TcpRequirerApplicationData.
validate\_port\_mapping(

*self*
)

Validate the port configuration.

Returns

The validated model.

Description

Either port or port\_mapping must be set, and port\_mapping is mutually
exclusive with both port and backend\_port.

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. This only applies when the
requirer uses the port/backend\_port attributes (not port\_mapping).

TcpRequirerApplicationData.
sni\_set\_when\_not\_enforcing\_tls(

*self*
)

Check if sni is configured but TLS is disabled.

Returns

The validated model.

TcpRequirerApplicationData.
effective\_port\_mapping(

*self*
)

Get the effective port mapping for this requirer.

Returns

The effective PortMapping.

Description

When port\_mapping is not set explicitly, it is derived from port and
backend\_port as "{port}:{backend\_port}".

TcpRequirerApplicationData.
port\_range(

*self*
)

Get the frontend port range.

Returns

The frontend PortRange.

TcpRequirerApplicationData.
backend\_port\_range(

*self*
)

Get the backend port range.

Returns

The backend PortRange.

TcpRequirerApplicationData.
is\_port\_range(

*self*
)

Indicate whether this requirer requests a multi-port range.

Returns

bool

True if the frontend exposes more than one port.

#### 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

Set of relation ids that contains 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 for the haproxy-route TCP provider.

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 HAProxyRouteTcpBackendsRemovedEvent

Description

HAProxyRouteTcpBackendsRemovedEvent 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 port exposed on the provider.

backend\_port

The port where the backend service is listening.

port\_mapping

A PortMapping object specifying the frontend and backend port ranges.

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.

proxy\_protocol

Whether to enable PROXY protocol when connecting to backend servers.

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 port exposed on the provider.

backend\_port

The port where the backend service is listening.

port\_mapping

A PortMapping object specifying the frontend and backend port ranges.

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.

proxy\_protocol

Whether to enable PROXY protocol when connecting to backend servers.

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\_port\_mapping(

*self*

,
port\_mapping
)

Set the port mapping.

Arguments

port\_mapping

A PortMapping object or string specifying the port mapping.

Returns

Self

The HaproxyRouteTcpRequirer class

Description

The mapping is of the form
"frontend\_start-frontend\_end:backend\_start-backend\_end". When setting a port
mapping, port and backend\_port are cleared.

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

HaproxyRouteTcpRequirer.
enable\_proxy\_protocol(

*self*
)

Enable PROXY protocol when connecting to backend servers.

Returns

Self

The HaproxyRouteTcpRequirer class
