Roles Core
chaos.lib.roles.role
Abstract base class definition for Ch-aOS execution roles.
Role
Bases: ABC
Abstract base class for roles in the Ch-aOS framework.
Notes
Each role must implement the "get_context", "delta" and "plan" methods to define its behavior and interactions for system management and orchestration.
get_context: This method should return the necessary data and information present in the system for the specific context of the role.
delta: This method should calculate what it needs to do to achieve its goals based on the current context and the desired state.
plan: This method should only stack the actions needed in pyinfra operations to achieve the desired state.
__init__(name, needs_secrets=False, necessary_chobolo_keys=[], necessary_secret_dict_keys=[])
Initializes a Role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the role. |
required |
needs_secrets
|
bool
|
Indicates if the role requires secrets to operate. Defaults to False. |
False
|
necessary_chobolo_keys
|
list[str]
|
The list of configuration keys required from the chobolo state. Defaults to []. |
[]
|
necessary_secret_dict_keys
|
list[str]
|
The list of secret keys required from the secrets store. Defaults to []. |
[]
|
delta(context={})
Optional method to implement for roles that require calculating a delta to achieve their goals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, Any]
|
The context for the role, as returned by the get_context method. Defaults to {}. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Delta |
Delta
|
A Delta object containing the actions needed to achieve the desired state. |
Notes
This method should be implemented by subclasses to calculate what it needs to do to achieve its goals based on the current context and the desired state.
get_context(state, host, chobolo={}, secrets={})
Optional method to implement for roles that require context data from the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Pyinfra state object. |
required |
host
|
Host
|
Pyinfra host object. |
required |
chobolo
|
dict
|
The desired state of the system as represented in the Chobolo. It contains only the keys specified in the "necessary_chobolo_keys" attribute of the role merged with the secret keys specified in the "necessary_secret_dict_keys" attribute of the role. Defaults to {}. |
{}
|
secrets
|
dict[str, Any]
|
The secrets required for the role, if any. Defaults to {}. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the context for the role. |
Notes
This method should be implemented by subclasses to return the necessary data and information present in the system for the specific context of the role.
plan(state, host, delta=Delta())
abstractmethod
Plan the actions needed to achieve the desired state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Pyinfra state object. |
required |
host
|
Host
|
Pyinfra host object. |
required |
delta
|
Delta
|
The delta for the role, as returned by the delta method. Defaults to Delta(). |
Delta()
|
Returns:
| Name | Type | Description |
|---|---|---|
ResultPayload |
ResultPayload
|
A ResultPayload object containing the result of the operation addition process including relevant data. |
Notes
This method should be implemented by subclasses to stack the actions needed in pyinfra operations to achieve the desired state.