Fixes bugs for integration with MON module
[osm/MON.git] / policy_module / osm_policy_module / core / config.py
1 """Global Configuration."""
2
3 import logging
4
5 from osm_policy_module.core.singleton import Singleton
6
7 try:
8 from configparser import ConfigParser
9 except ImportError:
10 from ConfigParser import ConfigParser
11
12 log = logging.getLogger(__name__)
13
14
15 @Singleton
16 class Config(object):
17 """Global configuration."""
18
19 def __init__(self):
20 # Default config values
21 self.config = {
22 'policy_module': {
23 'kafka_server_host': '127.0.0.1',
24 'kafka_server_port': '9092',
25 'log_dir': 'stdout',
26 'log_level': 'INFO'
27 },
28 }
29
30 def load_file(self, config_file_path):
31 if config_file_path:
32 config_parser = ConfigParser()
33 config_parser.read(config_file_path)
34 for section in config_parser.sections():
35 for key, value in config_parser.items(section):
36 if section not in self.config:
37 self.config[section] = {}
38 self.config[section][key] = value
39
40 def get(self, group, name=None, default=None):
41 if group in self.config:
42 if name is None:
43 return self.config[group]
44 return self.config[group].get(name, default)
45 return default