---
title: Charmhub | Deploy Microcluster Token Distributor using Charmhub - The Open
  Operator Collection
description: Deploy the latest version of Microcluster Token Distributor on any cloud.
url: https://charmhub.io/microcluster-token-distributor/libraries/token_distributor
---

# Microcluster Token Distributor

[mj ponsonby](https://charmhub.io/publisher/crypticcoder "View all packages from mj ponsonby")

* [mj ponsonby](https://charmhub.io/publisher/crypticcoder "View all packages from mj ponsonby")

Platform:

26.04

24.04

v1/stable 9

```
juju deploy microcluster-token-distributor --channel v1/stable
```

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

[Toggle side navigation](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#drawer)

## charms.microcluster\_token\_distributor.v0.token\_distributor

* [*Docstrings*Docstrings](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor)
  [*Code*Source code](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.microcluster_token_distributor.v0.token_distributor
    ```

    [Download token\_distributor.py](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor/download)
  + *Last updated* 14 Aug 2026
  + *Revision* Library version 0.7

Microcluster token distributor library.

This is a library for the microcluster-token-distributor operator charm and
charms that aim to integrate with it. It allows for distribution generation and
usage of tokens using the token distributor units as a sort of mirror for key
data that the units of the actual microcluster charm expose allowing
communication without the usage of the peer relation.

---

Index

* [def mirror\_id(
  hostname
  )](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#mirror_id)
* [def get\_hostname(
  )](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#get_hostname)
* [def corroborate(
  items,
  default
  )](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#corroborate)
* [class TokenDistributorProvides](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokendistributorprovides)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokendistributorprovides-__init__)
* [class ClusterBootstrappedEvent](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#clusterbootstrappedevent)
* [class TokenGeneratedEvent](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokengeneratedevent)
* [class ClusterJoinedEvent](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#clusterjoinedevent)
* + [def \_\_init\_\_(
    self,
    handle,
    bootstrapper)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#clusterjoinedevent-__init__)
* [class ClusterPreBootstrapEvent](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#clusterprebootstrapevent)
* [class ClusterPreJoinEvent](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#clusterprejoinevent)
* [class TokenConsumerEvents](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumerevents)
* [class TokenConsumer](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer)
* + [def add\_to\_mirror(
    self,
    relation,
    data)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-add_to_mirror)
* + [def find\_value(
    self,
    relation,
    key,
    keep\_empty)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-find_value)
* + [def any\_data\_exists(
    self,
    relation)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-any_data_exists)
* + [def find\_mirrors(
    self,
    relation)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-find_mirrors)
* + [def get\_relevant\_mirror\_data(
    self,
    relation,
    keep\_empty)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-get_relevant_mirror_data)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name,
    command\_name)](https://charmhub.io/microcluster-token-distributor/libraries/token_distributor#tokenconsumer-__init__)

#### def mirror\_id(hostname)

Return the mirror id for the specified hostname.

Returns

the mirror id for the specified hostname

#### def get\_hostname()

Description

Return the hostname. None

#### def corroborate(     items: list,     default )

Return the most frequent value in a list.

Description

Iterate through the list finding the most frequent value, while ignoring
default. However if no non-default values are found return default.

NOTE: In the event of two non default values with equal frequency we return
the first one, this is not ideal however, it is also not a use case that
should come up when using token distributor

#### class TokenDistributorProvides

Token Distributor Provider class.

Description

The provides side of the token distributor library.
It exposes the hostnames found in the connected cluster and copies any data
put up to be mirrored (typically tokens) in the leader units mirror for
consumption by units in the connected cluster.

Methods

TokenDistributorProvides.
\_\_init\_\_(

*self*

,
charm

,
relation\_name: str
)

#### class ClusterBootstrappedEvent

Description

Event for when this unit bootstraps the cluster. None

#### class TokenGeneratedEvent

Description

Event for when a token is generated for a unit. None

#### class ClusterJoinedEvent

Event for when a the unit joins the cluster.

Description

bootstrapper: True if the unit bootstrapped the cluster

Methods

ClusterJoinedEvent.
\_\_init\_\_(

*self*

,
handle

,
bootstrapper: bool
)

#### class ClusterPreBootstrapEvent

Description

Event for when this unit bootstraps the cluster. None

#### class ClusterPreJoinEvent

Description

Event for when this unit bootstraps the cluster. None

#### class TokenConsumerEvents

Description

Events class for `on`. None

#### class TokenConsumer

Token Consumer class.

Description

This uses the token distributor relation as a mirror to get information about
the cluster such as hostnames that need tokens generated. It then generates
neccicary tokens, which are then consumed by the respective units
allowing easy cluster management.

Methods

TokenConsumer.
add\_to\_mirror(

*self*

,
relation

,
data
)

Description

Add data into the units databag in a mirrorable form. None

TokenConsumer.
find\_value(

*self*

,
relation

,
key: str

,
keep\_empty
)

Find corresponding value in mirror.

Description

Return false if value not found, if keep\_empty is enabled 'empty' an
empty value will be accepted.

TokenConsumer.
any\_data\_exists(

*self*

,
relation
)

Description

Check if there is any non empty value on the remote side of the mirror. None

TokenConsumer.
find\_mirrors(

*self*

,
relation
)

Description

Find all remote mirror units. None

TokenConsumer.
get\_relevant\_mirror\_data(

*self*

,
relation

,
keep\_empty
)

Return data in the mirror, where the key is of the form mirror-key.

Description

Return a dictionary of the relevant data in the mirror, with the mirror
prefix stripped from the key.
If keep\_empty is true treat a value of empty as a valid value.

TokenConsumer.
\_\_init\_\_(

*self*

,
charm

,
relation\_name: str

,
command\_name: list
)
