Welcome to contrail-healer’s documentation!¶
contrail_healer package¶
contrail_healer.heal module¶
-
class
contrail_healer.heal.
Heal
(name)¶ Bases:
contrail_api_cli.command.Command
contrail-api-cli heal command.
Plug into the contrail-api RabbitMQ exchange and send notifications to registered healers.
Healers are discovered through the contrail_api_cli.healer entrypoint.
Healers must implement
contrail_healer.healer.Healer
class.Usage:
contrail-api-cli heal --rabbit-url user:pass@server:port --rabbit-vhost opencontrail
The url and vhost can also be sourced from the environment variables $CONTRAIL_HEALER_RABBIT_URL and $CONTRAIL_HEALER_RABBIT_VHOST.
contrail_healer.healer module¶
-
class
contrail_healer.healer.
Healer
(*args)¶ Bases:
contrail_api_cli.command.Command
Base class for Healers.
A Healer handles a resource type for one or multiple operations.
Resource and operation
The operation can be one of Operation.ALL, Operation.CREATE, Operation.DELETE, Operation.UPDATE or a combination of theses.
The resource type must be specified in a resource attribute of the class. The operation type must be specified in a on attribute of the class:
from contrail_healer.healer import Healer, Operation class MyHealer(Healer): resource = 'virtual-ip' on = Operation.CREATE
Healer queue and buffer
Each Healer has a public input queue and an internal buffer queue. Every message is taken from the input queue and put in the buffer queue. When the buffer queue is full (default: 10 items) or the buffer timeout is over (default: 5s) the buffer is empty and only unique elements are checked. For example if the buffer contains 3 UPDATE notifications on the same resource only one check will be made.
The buffer size and the buffer timeout can be adjusted per healer:
class MyHealer(Healer): buffer_size = 5 buffer_timeout = 10
Once the buffer is empty the check method will be run for each notification. The check can be delayed with the check_delay attribute (default: 0s):
class MyHealer(Healer): check_delay = 1
Healer check result
The
Healer.check()
method must return a tuple where the first element is the result of the check and the rest of the elements will be used as arguments to theHealer.fix()
method.The check result can be True, False or None. If True no fix is made. If False the
Healer.fix()
is run. If None the notification is put back in the queue so that the check will be run again on the current notification.The number of check retries for a single notification can be controlled by the max_check_retries attribute (default: 3):
class MyHealer(Healer): max_check_retries = 5
Each retry will be delayed by 1s on each iteration.
Healer configuration
Each Healer can use a configuration file for its own usage. The configuration file name can be specified in the config_file attribute. If defined the configuration will be loaded from /etc/contrail-healer/<config_file> or ~/.config/contrail-healer/<config_file>. When loaded the configuration is available in self.config which is a
ConfigParser
object.-
check
(oper, resource)¶ The actual check on the resource.
The method MUST return a tuple where the first element is the check result (True, False or None) and the rest of elements are arguments for the fix method.
Return type: (bool, arg, ...)
-
fix
(*args)¶ Fix method is run when the check has returned False. *args are provided in the return of the check method.
-
on
¶ Operation types the healer cares about.
Return type: Operation.TYPE
-
resource
¶ Type of resource the healer work on.
Return type: str
-
-
class
contrail_healer.healer.
Operation
¶ Operations to be notified about.
contrail_healer.pool module¶
Module used internally for tracking running greenlets.