slapos client: Cleanup + safety checks of Config

parent 59cfcf85
...@@ -115,7 +115,7 @@ def check_request_args(): ...@@ -115,7 +115,7 @@ def check_request_args():
class Config: class Config:
def setConfig(self, option_dict, configuration_file_path): def setConfig(self, option_dict, configuration_file_path=None):
""" """
Set options given by parameters. Set options given by parameters.
""" """
...@@ -125,10 +125,15 @@ class Config: ...@@ -125,10 +125,15 @@ class Config:
# Load configuration file # Load configuration file
configuration_parser = ConfigParser.SafeConfigParser() configuration_parser = ConfigParser.SafeConfigParser()
if configuration_file_path:
configuration_file_path = os.path.expanduser(configuration_file_path)
if not os.path.isfile(configuration_file_path):
raise OSError('Specified configuration file %s does not exist.'
' Exiting.' % configuration_file_path)
configuration_parser.read(configuration_file_path) configuration_parser.read(configuration_file_path)
# Merges the arguments and configuration # Merges the arguments and configuration
try: try:
configuration_dict = dict(configuration_parser.items("slapconsole")) configuration_dict = dict(configuration_parser.items('slapconsole'))
except ConfigParser.NoSectionError: except ConfigParser.NoSectionError:
pass pass
else: else:
...@@ -184,11 +189,13 @@ def init(config): ...@@ -184,11 +189,13 @@ def init(config):
return local return local
def request(): def request():
"""Ran when invoking slapos-request""" """Ran when invoking slapos request. Request an instance."""
# Parse arguments and inititate needed parameters # Parse arguments and inititate needed parameters
# XXX-Cedric: usage is different from what is specified in slapos doc.
usage = """usage: %s [options] CONFIGURATION_FILE INSTANCE_REFERENCE SOFTWARE_INSTANCE usage = """usage: %s [options] CONFIGURATION_FILE INSTANCE_REFERENCE SOFTWARE_INSTANCE
slapos-request allows you to request slapos instances.""" % sys.argv[0] slapos-request allows you to request slapos instances.""" % sys.argv[0]
config = Config() config = Config()
# XXX-Cedric: move argument parsing to main entry point
options = check_request_args() options = check_request_args()
config.setConfig(options, options.configuration_file) config.setConfig(options, options.configuration_file)
local = init(config) local = init(config)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment