Configuration handling

The configuration module is the central place where the clacks configuration can be queried. Using the configuration module requires the presence of the clacks configuration file - commonly /etc/clacks/config and the subdirectory /etc/clacks/config.d. All these configurations will be merged into one ‘virtual’ configuration so that certain packages can provide their own config file without knowing how to read it.

Additionally to reading the configuration file, it merges that information with potential command line parameters.

Here is an example on how to use the common module:

>>> from clacks.common import Environment
>>> cfg = Environment.getInstance().config
>>> cfg.get('core.id')
amqp

If no configuration is present, the system will raise a clacks.common.config.ConfigNoFile exception.


class clacks.common.config.Config(config=None, noargs=False)

Construct a new Config object using the provided configuration file and parse the sys.argv information.

Parameter Description
config Path to the configuration file.
noargs Don’t parse sys.argv information
get(path, default=None)

get allows dot-separated access to the configuration structure. If the desired value is not defined, you can specify a default value.

For example, if you want to access the id option located in the section [core], the path is:

core.id
Parameter Description
path dot-separated path to the configuration option
default default value if the desired option is not set

Return: value or default

getOptions(section)

Return the list of provided option names in the specified section of the ini file.

Parameter Description
str section name in the ini file

Return: list of options

getSections()

Return the list of available sections of the ini file. There should be at least ‘core’ available.

Return: list of sections

exception clacks.common.config.ConfigNoFile

Exception to inform about non existing or not accessible configuration files.


The configuration module handles a couple of default configuration values of the [core] section:

Key Description
foreground Run in daemon mode or not
pidfile Path to the PID file when running in daemon mode
umask Umask when running in daemon mode
user User to become when running in daemon mode
group Group to become when running in daemon mode
workdir Change to this directory when running in daemon mode
loglevel Level where logging starts
profile Save profiling information
log Log target (stderr, syslog, file)
logfile If log=”file” this is the path to the logfile
id Unique ID of this node
domain Which domain this node will be part of

Here is an example:

[core]
loglevel = DEBUG
log = file
logfile = /var/log/clacks/agent.log
profile = False
id = amqp
user = clacks
group = clacks