Juju charm Leadership layer. Links the Juju leadership hook environment and tools with the charms.reactive framework, allowing you to write handlers that are triggered by leadership related states.
# Leadership Layer for Juju Charms
The Leadership layer is for charm-tools and 'charm build', making it
easier for layered charms to deal with Juju leadership.
This layer will initialize charms.reactive states, allowing you to
write handlers that will be activated by these states. It allows you
to completely avoid writing leader-elected and leader-
hooks. As a simple example, these two handlers are all that is required
to make the leader unit generate a password if it is not already set,
and have the shared password stored in a file on all units:
```python
import charms.leadership
from charmhelpers.
@when('
@when_not(
def generate_secret():
charms.
@when('
def store_secret():
write_
```
## States
The following states are set appropriately on startup, before any @hook
decorated methods are invoked:
* `leadership.
This state is set when the unit is the leader. The unit will remain
the leader for the remainder of the hook, but may not be leader in
future hooks.
* `leadership.
This state is set for each leadership setting (ie. the
`leadership.
the foo leadership setting to any value). It will remain
set for the remainder of the hook, unless the unit is the leader
and calls `reactive.
to None.
* `leadership.
This state is set for each leadership setting that has changed
since the last hook. It will remain set for the remainder of the
hook. It will not be set in the next hook, unless the leader has
changed the leadership setting yet again.
* `leadership.
One or more leadership settings has changed since the last hook.
This state will remain set for the remainder of the hook. It will
not be set in the next hook, unless the leader has made further
changes.
## Methods
The `charms.leadership` module exposes the `leader_set()` and
`leader_get()` methods, which match the methods found in the
`charmhelpers.
should be used instead of the charmhelpers function to ensure that
the reactive state is updated when the leadership settings are. If you
do not do this, then you risk handlers waiting on these states to not
be run on the leader (because when the leader changes settings, it
triggers leader-
no hooks on itself).
## Support
This layer is maintained on Launchpad by
Stuart Bishop (stuart.
Code is available using git at git+ssh:
Bug reports can be made at https:/
Queries and comments can be made on the Juju mailing list, Juju IRC
channels, or at https:/
Project information
- Licence:
- GNU GPL v3
View full history Series and milestones
trunk series is the current focus of development.