Open Kilda Java Documentation
config.py
Go to the documentation of this file.
1 # Copyright 2017 Telstra Open Source
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 
16 import ConfigParser
17 import os
18 
19 
20 _root = os.path.dirname(__file__)
21 
22 config = ConfigParser.RawConfigParser()
23 path = os.path.join(_root, os.pardir, 'topology_engine.ini')
24 config.read(path)
25 
26 _dummy = object()
27 
28 
29 def read_option(section, name, conv=None, default=_dummy):
30  try:
31  value = config.get(section, name)
32  except ConfigParser.NoOptionError:
33  if default is _dummy:
34  raise ValueError('Option [{}]{} - not found'.format(section, name))
35  value = default
36 
37  if conv is not None:
38  value = conv(value)
39 
40  return value
41 
42 
43 def get(section, option):
44  return config.get(section, option)
45 
46 
47 def getint(section, option):
48  return config.getint(section, option)
49 
50 
51 def getboolean(section, option):
52  return config.getboolean(section, option)
53 
54 
55 def _get_bootstrap_servers():
56  bootstrap_servers_property = config.get('kafka', 'bootstrap.servers')
57  return [x.strip() for x in bootstrap_servers_property.split(',')]
58 
59 try:
60  ENVIRONMENT_NAMING_PREFIX = config.get('kafka',
61  'environment.naming.prefix')
62  if not ENVIRONMENT_NAMING_PREFIX.strip():
63  ENVIRONMENT_NAMING_PREFIX = None
64 
65 except ConfigParser.NoOptionError:
66  ENVIRONMENT_NAMING_PREFIX = None
67 
68 
70  topic_config_name = read_option('kafka', name)
71  if ENVIRONMENT_NAMING_PREFIX is None:
72  return topic_config_name
73  return '_'.join([ENVIRONMENT_NAMING_PREFIX, topic_config_name])
74 
75 
76 KAFKA_BOOTSTRAP_SERVERS = _get_bootstrap_servers()
77 KAFKA_FLOW_TOPIC = read_and_format_with_env_name('flow.topic')
78 KAFKA_CACHE_TOPIC = read_and_format_with_env_name('cache.topic')
79 KAFKA_SPEAKER_TOPIC = read_and_format_with_env_name('speaker.topic')
80 KAFKA_TOPO_ENG_TOPIC = read_and_format_with_env_name('topo.eng.topic')
81 KAFKA_NORTHBOUND_TOPIC = read_and_format_with_env_name('northbound.topic')
82 KAFKA_CONSUMER_GROUP = read_and_format_with_env_name('consumer.group')
83 
84 ZOOKEEPER_HOSTS = config.get('zookeeper', 'hosts')
85 
86 NEO4J_SOCKET_TIMEOUT = read_option(
87  'neo4j', 'socket.timeout', conv=float, default=30.0)
88 
89 ISL_COST_WHEN_PORT_DOWN = read_option(
90  'isl', 'cost_when_port_down', conv=int, default=10000)
def read_option(section, name, conv=None, default=_dummy)
Definition: config.py:29
def get(section, option)
Definition: config.py:43
def read_and_format_with_env_name(name)
Definition: config.py:69
def getboolean(section, option)
Definition: config.py:51
def getint(section, option)
Definition: config.py:47