Lifecycle anatomy

Lifecycle is an automaton with a set of State and transitions between these states.

The state machine represents differents steps (called states) for deploying a service. For example the installation, the configuration, the activation of the service.

When a state is reached, it is added in a stack managed by Lifecycle. This permits to know which states have been applied in order to be able to unapplied them. This stack in internally managed and thus not exposed.

State

A State describes the actions to do in a particular state of a Lifecycle. It can be actions when entering in the state or actions available when the state is applied (in the stack).

States are pure python classes and actions are the methods of the class. The actions are called provides. Methods must be decorated to be used as provides.

To create a state you just need to subclass State:

from armonic import State

class MyState(State):
    pass

More about State.

Provide

A Provide describes a State method of a Lifecycle. The Provide defines the list of requires to be provided in order to call a state method like it was arguments of the method.

For example a state provide (method) with no requires (arguments) can be declared like this:

from armonic import State

class MyState(State):

    @Provide()
    def my_provide(self):
        # actions here
        pass

Each state has at least the Provide enter. This method is called when entering the state.

To other methods are also reserved: leave and cross. You can override leave if actions must be done when leaving the state. leave cannot take any arguments. cross is used when the state is traversed.

Flags

Flags can be defined on a Provide. These flags are propagated to upper states when the Provide is called.

When a provide is called the state that contains the provide is applied (in the Lifecycle stack). It can be a state that is not the current state (ie the last state applied). In that case the provide flags will be propagated to the cross methods of each state that was applied after the provide’s state.

See Flags usage.

Require

Require describes the arguments needed to call a Provide. A require is a group of Variable with some context (name, extra information...)

Different of types of requires can be used:

  • Require defines arguments that should be provided.
  • RequireLocal defines that another Provide must be called on the same host before. The result of this call can be used if needed.
  • RequireExternal defines that another Provide must be called on a different host before. The result of this call can be used if needed.

More about Requires.

Variable

Variable describes a Provide argument with some context (name, default value, optional, validation and more).

Variables are grouped in Require.

More about Variables.