The xosconfig
module is used to read, validate and distribute configuration information for all XOS-related components.
The code for this module can be found in lib/xos-config
The xosconfig
module uses a combination of parameters provided via a .yaml
file and a service discovery mechanism.
This module needs to be initialized once (and only once) when you start the application. You can do it with:
from xosconfig import Config Config.init()
By default, xosconfig
looks for a configuration file in /opt/xos/config.yaml
. Passing a different config file can be done with:
from xosconfig import Config Config.init("/path/to/my/config.yaml")
Defaults are defined for some of the configuration items in lib/xos-config/xosconfig/default.py
.
To access static information defined in the config.yaml
file, use the following API:
from xosconfig import Config res = Config.get('database')
This call returns something like:
{ 'username': 'test', 'password': 'safe' }
Since the configuration supports a nested dictionary, it is possible to query directly nested values using dot
notation. For example:
from xosconfig import Config res = Config.get('database.username')
returns
"test"
The configuration schema is defined in /lib/xos-config/config-schema.yaml
XOS is composed of a set of services. To discover these services and their address, use the registrator tool.
Invoking
from xosconfig import Config Config.get_service_list()
returns an array of available services; by default:
[ "xos-ws", "xos-ui-deprecated", "xos-rest", "xos-gui", "xos-db", "consul-rest", "consul", ]
You can get the same information on the
head node
using:curl consul:8500/v1/catalog/services
Invoking
from xosconfig import Config Config.get_service_info('xos-db')
returns
{ 'name': 'xos-db', 'url': '172.18.0.4', 'port': 5432 }
You can get the same information on the
head node
using:curl consul:8500/v1/catalog/service/xos-db
Invoking
from xosconfig import Config Config.get_service_endpoint('xos-db')
returns
"http://172.18.0.4:5432"