This class is used to load configuration from the Persistent Configuration Repository, taking into account the Service Discovery and command line options parsed by the click module.
More...
|
| | __init__ (self, CommonConfigurationParameters param_definitions, DataPointPath base_path) |
| | Create an instance of a configuration manager to handle the specified definition of configuration parameters of the client tool.
|
| |
| | register_converter (self, cls, function) |
| | This registers a data conversion function that converts a datapoint value read from the Persistent Configuration Repository into the type indicated by 'cls'.
|
| |
| | get_config_defaults (self) |
| | Returns an object with the default configuration parameter values.
|
| |
| | get_config_defaults_as_dataclass (self) |
| | Returns the default configuration parameters in an instance of the configuration dataclass registered with the ConfigurationManager when it was created.
|
| |
| | get_config_defaults_as_dict (self) |
| | Returns the default configuration parameters as a dictionary of key value pairs.
|
| |
| | get_active_config (self) |
| | Returns the currently active configuration parameters that should actually be used by the tool's operational logic.
|
| |
| | get_active_config_as_dataclass (self) |
| | Returns the currently active configuration parameters in a dataclass of the same type as returned by get_config_defaults_as_dataclass.
|
| |
| | get_active_config_as_dict (self) |
| | Returns the currently active configuration parameters as a dictionary of key value pairs.
|
| |
| | update_config_from_cli (self, **kwargs) |
| | Updates the configuration with options parsed from the command line by click.
|
| |
| | load_config (self) |
| | Loads the tool's configuration values from the Persistent Configuration Repository.
|
| |
|
| | _convert (self, value, target_type) |
| | Helper method to convert a value to the target type, using a registered data converter function if available.
|
| |
| | _load_from_persistent_repository (self, Uri uri) |
| | Loads the configuration parameters from the provided URI using the PersistentRepoIf.
|
| |
| | _load_endpoints_from_service_discovery (self, Uri uri) |
| | Loads endpoints that are available from the service discovery indicated by the given URI.
|
| |
| | _dump_config_to_logs (self) |
| | Logs the current configuration values in a single log message.
|
| |
| | _init_logger_config (self) |
| | Initialise the logger configuration to log to console and optionally to file.
|
| |
This class is used to load configuration from the Persistent Configuration Repository, taking into account the Service Discovery and command line options parsed by the click module.
- Warning
- The loading of the configuration and setting up the logging subsystems is a bit subtle. Things need to be done in the correct order. This is taken care of by this class. Therefore, do not attempt to setup the logging system yourself. Rather let ConfigurationManager handle it and follow the usage pattern described below.
Usage The typical approach for using this class is to instantiate it once in the top
level entry point script for the tool. Within the methods decorated as click commands, the method update_config_from_cli should be invoked to update the configuration with the options parsed by click. Then in the leaf sub-commands, just before beginning executing the operational logic of the tool, the load_config method should be called once, to load the configuration from the repository. One can typically also pass the ConfigurationManager instance to the operational logic class and add the load_config call there, e.g. in init.
◆ __init__()
Create an instance of a configuration manager to handle the specified definition of configuration parameters of the client tool.
The param_definitions argument must be CommonConfigurationParameters or a child class of CommonConfigurationParameters. This is a dataclass that defines the configuration parameters of the client tool that can also be loaded from the Persistent Configuration Repository. For any typed attribute defined in param_definitions, the configuration manager will attempt to find and load the parameter under the base_path folder in the repository. For example, assuming base_path is "/mytool" and a configuration parameter is called "myparam", the path checked is "/mytool/myparam".
- Parameters
-
| param_definitions | A class type defining the configuration parameters for the tool. |
| base_path | The base repository path under which configuration is looked for. |
◆ _convert()
| cli.config.ConfigurationManager._convert |
( |
| self, |
|
|
| value, |
|
|
| target_type ) |
|
protected |
Helper method to convert a value to the target type, using a registered data converter function if available.
◆ _dump_config_to_logs()
| cli.config.ConfigurationManager._dump_config_to_logs |
( |
| self | ) |
|
|
protected |
Logs the current configuration values in a single log message.
◆ _init_logger_config()
| cli.config.ConfigurationManager._init_logger_config |
( |
| self | ) |
|
|
protected |
Initialise the logger configuration to log to console and optionally to file.
This sets up the log4cplus subsystem and redirects all Python logging to it.
◆ _load_endpoints_from_service_discovery()
| cli.config.ConfigurationManager._load_endpoints_from_service_discovery |
( |
| self, |
|
|
Uri | uri ) |
|
protected |
Loads endpoints that are available from the service discovery indicated by the given URI.
Any endpoint that was already set from the configuration or command line will not be updated.
◆ _load_from_persistent_repository()
| cli.config.ConfigurationManager._load_from_persistent_repository |
( |
| self, |
|
|
Uri | uri ) |
|
protected |
Loads the configuration parameters from the provided URI using the PersistentRepoIf.
The URI scheme can either be 'file:' for loading from a local file or 'cii.config:' to load from the central configuration repository.
Configuration parameters are only updated if they have not been set in any other way yet, e.g. from the command line. For any missing datapoints we simply ignore them. However, an exception is raised if there was an error while trying to access the repository or reading an existing datapoint.
◆ get_active_config()
| cli.config.ConfigurationManager.get_active_config |
( |
| self | ) |
|
Returns the currently active configuration parameters that should actually be used by the tool's operational logic.
If update_config_from_cli was not called first then None is returned instead.
◆ get_active_config_as_dataclass()
| cli.config.ConfigurationManager.get_active_config_as_dataclass |
( |
| self | ) |
|
Returns the currently active configuration parameters in a dataclass of the same type as returned by get_config_defaults_as_dataclass.
If update_config_from_cli was not called first then None is returned instead.
◆ get_active_config_as_dict()
| cli.config.ConfigurationManager.get_active_config_as_dict |
( |
| self | ) |
|
Returns the currently active configuration parameters as a dictionary of key value pairs.
If update_config_from_cli was not called first then an empty dictionary is returned instead.
◆ get_config_defaults()
| cli.config.ConfigurationManager.get_config_defaults |
( |
| self | ) |
|
Returns an object with the default configuration parameter values.
i.e. the values used when not overridden by configuration or command line options.
◆ get_config_defaults_as_dataclass()
| cli.config.ConfigurationManager.get_config_defaults_as_dataclass |
( |
| self | ) |
|
Returns the default configuration parameters in an instance of the configuration dataclass registered with the ConfigurationManager when it was created.
◆ get_config_defaults_as_dict()
| cli.config.ConfigurationManager.get_config_defaults_as_dict |
( |
| self | ) |
|
Returns the default configuration parameters as a dictionary of key value pairs.
◆ load_config()
| cli.config.ConfigurationManager.load_config |
( |
| self | ) |
|
Loads the tool's configuration values from the Persistent Configuration Repository.
- Note
- update_config_from_cli must be called first, before calling this method.
If there is a problem to load any configuration parameters then we simply log any failures, instead of raising an exception.
Also load endpoints from the Service Discovery. These take precedence over values from the Persistent Configuration Repository if the service discovery location was explicitly given on the command line, otherwise the ones from Persistent Configuration Repository are used. Lastly, any options that were provided on the command line, environment variables or from an interactive prompt take precedence over both the Persistent Configuration Repository and Service Discovery.
◆ register_converter()
| cli.config.ConfigurationManager.register_converter |
( |
| self, |
|
|
| cls, |
|
|
| function ) |
This registers a data conversion function that converts a datapoint value read from the Persistent Configuration Repository into the type indicated by 'cls'.
The registered conversion function will be used whenever assigning a configuration parameter with type 'cls' to a datapoint value loaded from the repository.
The registered function should raise a RuntimeError if the datapoint value cannot be converted correctly.
- Parameters
-
| cls | The configuration parameter type to convert to. |
| function | A function taking a single data argument that performs the conversion. |
◆ update_config_from_cli()
| cli.config.ConfigurationManager.update_config_from_cli |
( |
| self, |
|
|
** | kwargs ) |
Updates the configuration with options parsed from the command line by click.
The initial configuration uses the internal defaults provided through the configuration definition dataclass when the ConfigurationManager instance is created. These are updated with the values passed to this method. Specifically, each keyword argument given to this method is assigned to a configuration parameter with the same name, i.e. the name must match an attribute from the definition dataclass. Any configuration parameter not indicated in the keyword arguments is left unchanged.
◆ _active_config
| cli.config.ConfigurationManager._active_config = None |
|
protected |
◆ _config_defaults
| cli.config.ConfigurationManager._config_defaults = _prepare_defaults() |
|
protected |
◆ _data_converter
| dict cli.config.ConfigurationManager._data_converter |
|
protected |
Initial value:= {
LogLevel: convert_to_log_level,
Uri: convert_to_uri,
}
◆ _logger
| cli.config.ConfigurationManager._logger = None |
|
protected |
◆ _options_map
| dict cli.config.ConfigurationManager._options_map = {} |
|
protected |
◆ Configuration
| cli.config.ConfigurationManager.Configuration |
Initial value:= NamedTuple(
"Configuration",
[(x.name, ConfigurationValue) for x in dataclasses.fields(param_definitions())],
)
◆ ConfigurationParameters
| cli.config.ConfigurationManager.ConfigurationParameters = param_definitions |
The documentation for this class was generated from the following file:
- clients/common/src/rtctk/common/cli/config.py