lighthouse.service
¶lighthouse.service.
Service
[source]¶Bases: lighthouse.configurable.Configurable
Class representing a service provided by the current machine.
This is a straightforward Configurable subclass, it defines what a valid configuration for a service is and applies them.
config_subdirectory
= 'services'¶validate_config
(config)[source]¶Runs a check on the given config to make sure that port
/ports
and
discovery
is defined.
validate_check_configs
(config)[source]¶Config validation specific to the health check options.
Verifies that checks are defined along with an interval, and calls
out to the Check
class to make sure each individual check’s config
is valid.
apply_config
(config)[source]¶Takes a given validated config dictionary and sets an instance attribute for each one.
For check definitions, a Check instance is is created and a checks
attribute set to a dictionary keyed off of the checks’ names. If
the Check instance has some sort of error while being created an error
is logged and the check skipped.
reset_status
()[source]¶Sets the up/down status of the service ports to the default state.
Useful for when the configuration is updated and the checks involved in determining the status might have changed.
update_ports
()[source]¶Sets the ports
attribute to the set of valid port values set in
the configuration.
update_checks
(check_configs)[source]¶Maintains the values in the checks
attribute’s dictionary. Each
key in the dictionary is a port, and each value is a nested dictionary
mapping each check’s name to the Check instance.
This method makes sure the attribute reflects all of the properly
configured checks and ports. Removing no-longer-configured ports
is left to the run_checks
method.
run_checks
()[source]¶Iterates over the configured ports and runs the checks on each one.
Returns a two-element tuple: the first is the set of ports that transitioned from down to up, the second is the set of ports that transitioned from up to down.
Also handles the case where a check for a since-removed port is run, marking the port as down regardless of the check’s result and removing the check(s) for the port.