From: Ondrej Lichtner <olichtne(a)redhat.com>
The Config class now accepts an argument which specifies which
configuration scheme should be used. Currently I added a scheme
'controller', which was used until now as the configuration for the
controller, and 'slave' which will be used by the slave. The details of
the slave scheme will be added later.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
Common/Config.py | 35 ++++++++++++++++++++++++++++++++---
nettestctl.py | 2 +-
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/Common/Config.py b/Common/Config.py
index 297ebea..5376f35 100644
--- a/Common/Config.py
+++ b/Common/Config.py
@@ -23,10 +23,22 @@ class ConfigError(Exception):
class Config():
options = None
+ _scheme = None
- def __init__(self):
+ def __init__(self, scheme):
self.options = dict()
+ self._scheme = scheme
+ if self._scheme == "controller":
+ self.init_controller()
+ elif self._scheme == "slave":
+ self.init_slave()
+ else:
+ msg = "Unknow scheme: '%s', can't set up
configuration"\
+ % self._scheme
+ raise ConfigError(msg)
+
+ def init_controller(self):
self.options['log'] = dict()
self.options['log']['path'] = os.path.join(
os.path.dirname(sys.argv[0]), './Logs')
@@ -37,6 +49,9 @@ class Config():
self.options['environment']['rpcport'] = DefaultRPCPort
self.options['environment']['pool_dirs'] = []
+ def init_slave(self):
+ pass
+
def get_config(self):
return self.options
@@ -61,15 +76,29 @@ class Config():
parser.read(abs_path)
sections = parser._sections
+
+ if self._scheme == "controller":
+ self.sectionsCntl(sections, abs_path)
+ elif self._scheme == "slave":
+ self.sectionsSlave(sections, abs_path)
+ else:
+ msg = "Unknow scheme: '%s', can't parse sections." \
+ % self._scheme
+ raise ConfigError(msg)
+
+ def sectionsCntl(self, sections, path):
for section in sections:
if section == "log":
- self.sectionLogs(sections[section], abs_path)
+ self.sectionLogs(sections[section], path)
elif section == "environment":
- self.sectionEnvironment(sections[section], abs_path)
+ self.sectionEnvironment(sections[section], path)
else:
msg = "Unknown section: %s" % section
raise ConfigError(msg)
+ def sectionsSlave(self, sections, path):
+ pass
+
def sectionLogs(self, config, cfg_path):
section = self.options['log']
diff --git a/nettestctl.py b/nettestctl.py
index d4178f4..6da53f2 100755
--- a/nettestctl.py
+++ b/nettestctl.py
@@ -99,7 +99,7 @@ def main():
usage()
sys.exit()
- config = Config()
+ config = Config("controller")
config.load_config('~/.lnst/lnst.conf')
debug = 0
--
1.7.11.7