config: enable to read 'known_nodes' in toml file. convert environment...

config: enable to read 'known_nodes' in toml file. convert environment variables to appropriate data types
parent 773f7494
......@@ -41,6 +41,7 @@ DEFAULTS = {
'CACHE_DIR': '/var/cache/beiran',
'RUN_DIR': '/var/run',
'DISCOVERY_METHOD': 'zeroconf',
'KNOWN_NODES': [],
}
......@@ -103,8 +104,16 @@ class Config(metaclass=ConfigMeta):
if not any([ckey, ekey]):
return None
env_value = os.getenv("BEIRAN_{}".format(ekey))
if env_value:
if isinstance(DEFAULTS[ekey], list):
return env_value.split(',')
if isinstance(DEFAULTS[ekey], int):
return int(env_value)
return \
os.getenv("BEIRAN_{}".format(ekey)) or \
env_value or \
self.get_config_from_file(ckey) or \
DEFAULTS.get(ekey, None)
......@@ -253,6 +262,19 @@ class Config(metaclass=ConfigMeta):
"""
return self.get_config('beiran.listen_port', 'LISTEN_PORT')
@property
def known_nodes(self):
"""
List of URLs of known nodes. Beiran daemon tries to communicate with
them. The default value is ``[]``
config.toml: section ``beiran``, key ``known_nodes``
Environment variable: ``BEIRAN_KNOWN_NODES``
"""
return self.get_config('beiran.known_nodes', 'KNOWN_NODES')
@property
def plugin_types(self):
"""Return the list of supported plugin types"""
......
......@@ -312,8 +312,7 @@ class BeiranDaemon(EventEmitter):
)
# Probe Known Nodes
known_nodes = os.getenv("KNOWN_NODES")
known_urls = known_nodes.split(',') if known_nodes else []
known_urls = config.known_nodes
Services.get_logger().info("KNOWN_NODES are: %s", known_urls)
for known_url in known_urls:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment