From: Simo Sorce Date: Tue, 27 May 2014 22:02:29 +0000 (-0400) Subject: Add support for passing configuration profile X-Git-Tag: v0.2.5~7 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=8fa20c6c81aab558cd00bf1e4ac87ec8ee5a8556 Add support for passing configuration profile The new option --config-profile accepts a INI style file, so that installation options are passed in via a file. this is useful for testing and automated installs. This file can have 2 sections: globals, arguments. The globals section can change global variable in the install script like: TEMPLATES, CONFDIR, DATADIR, HTTPDCONFD and so on, so that an installation can use non-standad directories. The argumets section accepts any argument option. The config profile file is parsed after all arguments have parsed and can override any plugin argument. Signed-off-by: Simo Sorce --- diff --git a/ipsilon/install/ipsilon-client-install b/ipsilon/install/ipsilon-client-install index 2b3d2f2..484c462 100755 --- a/ipsilon/install/ipsilon-client-install +++ b/ipsilon/install/ipsilon-client-install @@ -23,6 +23,7 @@ from ipsilon.tools.saml2metadata import SAML2_SERVICE_MAP from ipsilon.tools.certs import Certificate from ipsilon.tools import files import argparse +import ConfigParser import logging import os import pwd @@ -178,6 +179,42 @@ def log_exception(e): logger.error(e) +def parse_config_profile(args): + config = ConfigParser.ConfigParser() + files = config.read(args['config_profile']) + if len(files) == 0: + raise ConfigurationError('Config Profile file %s not found!' % + args['config_profile']) + + if 'globals' in config.sections(): + G = config.options('globals') + for g in G: + val = config.get('globals', g) + if val == 'False': + val = False + elif val == 'True': + val = True + if g in globals(): + globals()[g] = val + else: + for k in globals().keys(): + if k.lower() == g.lower(): + globals()[k] = val + break + + if 'arguments' in config.sections(): + A = config.options('arguments') + for a in A: + val = config.get('arguments', a) + if val == 'False': + val = False + elif val == 'True': + val = True + args[a] = val + + return args + + def parse_args(): global args @@ -212,11 +249,16 @@ def parse_args(): default=True, help="Turn on all security checks") parser.add_argument('--debug', action='store_true', default=False, help="Turn on script debugging") + parser.add_argument('--config-profile', default=None, + help="File containing install options") parser.add_argument('--uninstall', action='store_true', help="Uninstall the server and all data") args = vars(parser.parse_args()) + if args['config_profile']: + args = parse_config_profile(args) + if len(args['hostname'].split('.')) < 2: raise ValueError('Hostname: %s is not a FQDN.') diff --git a/ipsilon/install/ipsilon-server-install b/ipsilon/install/ipsilon-server-install index b56ded5..430087e 100755 --- a/ipsilon/install/ipsilon-server-install +++ b/ipsilon/install/ipsilon-server-install @@ -22,6 +22,7 @@ from ipsilon.providers.common import ProvidersInstall from ipsilon.helpers.common import EnvHelpersInstall from ipsilon.util.data import Store from ipsilon.tools import files +import ConfigParser import argparse import cherrypy import logging @@ -163,6 +164,33 @@ def find_plugins(): return plugins +def parse_config_profile(args): + config = ConfigParser.ConfigParser() + files = config.read(args['config_profile']) + if len(files) == 0: + raise ConfigurationError('Config Profile file %s not found!' % + args['config_profile']) + + if 'globals' in config.sections(): + G = config.options('globals') + for g in G: + val = config.get('globals', g) + if g in globals(): + globals()[g] = val + else: + for k in globals().keys(): + if k.lower() == g.lower(): + globals()[k] = val + break + + if 'arguments' in config.sections(): + A = config.options('arguments') + for a in A: + args[a] = config.get('arguments', a) + + return args + + def parse_args(plugins): parser = argparse.ArgumentParser(description='Ipsilon Install Options') parser.add_argument('--version', @@ -177,6 +205,8 @@ def parse_args(plugins): help="User account used to run the server") parser.add_argument('--admin-user', default='admin', help="User account that is assigned admin privileges") + parser.add_argument('--config-profile', default=None, + help="File containing install options") parser.add_argument('--uninstall', action='store_true', help="Uninstall the server and all data") @@ -192,6 +222,9 @@ def parse_args(plugins): args = vars(parser.parse_args()) + if args['config_profile']: + args = parse_config_profile(args) + if not args['hostname']: args['hostname'] = socket.getfqdn()