Adds license header to python files
[osm/MON.git] / policy_module / osm_policy_module / core / config.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
5
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
8
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
12
13 # http://www.apache.org/licenses/LICENSE-2.0
14
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
19 # under the License.
20
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: bdiaz@whitestack.com or glavado@whitestack.com
23 ##"""Global Configuration."""
24
25 import logging
26
27 from osm_policy_module.core.singleton import Singleton
28
29 try:
30 from configparser import ConfigParser
31 except ImportError:
32 from ConfigParser import ConfigParser
33
34 log = logging.getLogger(__name__)
35
36
37 @Singleton
38 class Config(object):
39 """Global configuration."""
40
41 def __init__(self):
42 # Default config values
43 self.config = {
44 'policy_module': {
45 'kafka_server_host': '127.0.0.1',
46 'kafka_server_port': '9092',
47 'log_dir': 'stdout',
48 'log_level': 'INFO'
49 },
50 }
51
52 def load_file(self, config_file_path):
53 if config_file_path:
54 config_parser = ConfigParser()
55 config_parser.read(config_file_path)
56 for section in config_parser.sections():
57 for key, value in config_parser.items(section):
58 if section not in self.config:
59 self.config[section] = {}
60 self.config[section][key] = value
61
62 def get(self, group, name=None, default=None):
63 if group in self.config:
64 if name is None:
65 return self.config[group]
66 return self.config[group].get(name, default)
67 return default