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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from dss.api import dss_error
19 SERVER_SECTION = "server"
20 PLUGIN_SECTION = "plugin"
21 DEFAULT_CONFIG_FILE="/etc/dss/dss-server/config.ini"
25 Read the ini file. The structure of the file is as follows:
28 logging_destination = console
30 listening_uds = /var/run/.dss-server
31 transport_type = dgram
33 plugin = /opt/dss-server/etcd.py
34 config = /etc/dss-server/etcd.ini
37 def __init__(self, config_file = DEFAULT_CONFIG_FILE):
40 self.logging_level = None
41 self.logging_destination = None
43 self.listening_uds = None
44 self.transport_type = None
48 self.plugin_config = None
50 config = ConfigParser.ConfigParser()
51 config.read([config_file])
53 self.logging_level = config.get(SERVER_SECTION, "logging_level")
54 self.logging_destination = config.get(SERVER_SECTION, "logging_destination")
55 self.verbose = config.get(SERVER_SECTION, "verbose")
56 self.listening_uds = config.get(SERVER_SECTION, "listening_uds")
57 self.transport_type = config.get(SERVER_SECTION, "transport_type")
59 self.plugin = config.get(PLUGIN_SECTION, "plugin")
60 self.plugin_config = config.get(PLUGIN_SECTION, "config")
63 except Exception as exp:
64 raise dss_error.Error(str(exp))
66 def get_logging_level(self):
67 return self.logging_level
69 def get_logging_destination(self):
70 return self.logging_destination
72 def get_verbose(self):
75 def get_listening_uds(self):
76 return self.listening_uds
81 def get_plugin_config(self):
82 return self.plugin_config
84 def get_transport_type(self):
85 return self.transport_type
88 if __name__ == "__main__":
91 config = Config(sys.argv[1])
92 except dss_error.Error as exp:
93 print("Got exception %s" % exp)