Cleaning up cfg so that others can know the difference between empty vars and vars that don't exist
This commit is contained in:
parent
358969812f
commit
2d99e9ecca
@ -46,7 +46,7 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
||||
DEF_INT = 0
|
||||
DEF_FLOAT = 0.0
|
||||
DEF_BOOLEAN = False
|
||||
DEF_STRING = ''
|
||||
DEF_BASE = None
|
||||
|
||||
def __init__(self):
|
||||
ConfigParser.RawConfigParser.__init__(self)
|
||||
@ -54,7 +54,7 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
||||
self.optionxform = str
|
||||
|
||||
def get(self, section, option):
|
||||
value = IgnoreMissingConfigParser.DEF_STRING
|
||||
value = IgnoreMissingConfigParser.DEF_BASE
|
||||
try:
|
||||
value = ConfigParser.RawConfigParser.get(self, section, option)
|
||||
except ConfigParser.NoSectionError:
|
||||
@ -86,7 +86,7 @@ class StackConfigParser(IgnoreMissingConfigParser):
|
||||
self.configs_fetched = dict()
|
||||
self.db_dsns = dict()
|
||||
|
||||
def _makekey(self, section, option):
|
||||
def _make_key(self, section, option):
|
||||
joinwhat = []
|
||||
if section is not None:
|
||||
joinwhat.append(str(section))
|
||||
@ -94,76 +94,74 @@ class StackConfigParser(IgnoreMissingConfigParser):
|
||||
joinwhat.append(str(option))
|
||||
return "/".join(joinwhat)
|
||||
|
||||
def _resolve_special(self, section, option, value_gotten, auto_pw):
|
||||
key = self._makekey(section, option)
|
||||
if section in PW_SECTIONS and key not in self.pws:
|
||||
def _resolve_value(self, section, option, value_gotten, auto_pw):
|
||||
key = self._make_key(section, option)
|
||||
if section in PW_SECTIONS and key not in self.pws and value_gotten:
|
||||
self.pws[key] = value_gotten
|
||||
if section == 'host' and option == 'ip':
|
||||
LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.")
|
||||
value_gotten = utils.get_host_ip()
|
||||
LOG.debug("Determined your host ip to be: \"%s\"" % (value_gotten))
|
||||
if section in PW_SECTIONS and auto_pw and len(value_gotten) == 0:
|
||||
LOG.debug("Being forced to ask for password for \"%s\" since the configuration value is empty.", key)
|
||||
LOG.debug("Determined your host ip to be: [%s]" % (value_gotten))
|
||||
if section in PW_SECTIONS and auto_pw and not value_gotten:
|
||||
LOG.debug("Being forced to ask for password for [%s] since the configuration value is empty.", key)
|
||||
value_gotten = sh.password(PW_PROMPTS.get(option, PW_TMPL % (key)))
|
||||
self.pws[key] = value_gotten
|
||||
return value_gotten
|
||||
|
||||
def getdefaulted(self, section, option, default_val, auto_pw=True):
|
||||
val = self.get(section, option, auto_pw=auto_pw)
|
||||
if not val:
|
||||
val = self.get(section, option, auto_pw)
|
||||
if not val or not val.strip():
|
||||
LOG.debug("Value [%s] found was not good enough, returning provided default [%s]" % (val, default_val))
|
||||
return default_val
|
||||
return val
|
||||
|
||||
def get(self, section, option, auto_pw=True):
|
||||
key = self._makekey(section, option)
|
||||
key = self._make_key(section, option)
|
||||
if key in self.configs_fetched:
|
||||
value = self.configs_fetched.get(key)
|
||||
LOG.debug("Fetched cached value \"%s\" for param \"%s\"" % (value, key))
|
||||
LOG.debug("Fetched cached value [%s] for param [%s]" % (value, key))
|
||||
else:
|
||||
LOG.debug("Fetching value for param \"%s\"" % (key))
|
||||
gotten_value = self._get_special(section, option, auto_pw)
|
||||
value = self._resolve_special(section, option, gotten_value, auto_pw)
|
||||
LOG.debug("Fetched \"%s\" for \"%s\"" % (value, key))
|
||||
LOG.debug("Fetching value for param [%s]" % (key))
|
||||
gotten_value = self._get_bashed(section, option, auto_pw)
|
||||
value = self._resolve_value(section, option, gotten_value, auto_pw)
|
||||
LOG.debug("Fetched [%s] for [%s] %s" % (value, key, CACHE_MSG))
|
||||
self.configs_fetched[key] = value
|
||||
return value
|
||||
|
||||
def _extract_default(self, default_value, auto_pw):
|
||||
if not SUB_MATCH.search(default_value):
|
||||
return default_value
|
||||
|
||||
LOG.debug("Performing simple replacement on %s", default_value)
|
||||
def _resolve_replacements(self, value, auto_pw):
|
||||
LOG.debug("Performing simple replacement on [%s]", value)
|
||||
|
||||
#allow for our simple replacement to occur
|
||||
def replacer(match):
|
||||
section = match.group(1)
|
||||
option = match.group(2)
|
||||
return self.get(section, option, auto_pw)
|
||||
return self.getdefaulted(section, option, '', auto_pw)
|
||||
|
||||
return SUB_MATCH.sub(replacer, default_value)
|
||||
return SUB_MATCH.sub(replacer, value)
|
||||
|
||||
def _get_special(self, section, option, auto_pw):
|
||||
key = self._makekey(section, option)
|
||||
def _get_bashed(self, section, option, auto_pw):
|
||||
value = IgnoreMissingConfigParser.get(self, section, option)
|
||||
if value is None:
|
||||
return value
|
||||
extracted_val = ''
|
||||
mtch = ENV_PAT.match(value)
|
||||
if mtch:
|
||||
env_key = mtch.group(1).strip()
|
||||
def_val = mtch.group(2)
|
||||
def_val = mtch.group(2).strip()
|
||||
if not def_val and not env_key:
|
||||
msg = "Invalid bash-like value \"%s\" for \"%s\"" % (value, key)
|
||||
msg = "Invalid bash-like value [%s]" % (value)
|
||||
raise excp.BadParamException(msg)
|
||||
if not env_key or env.get_key(env_key) is None:
|
||||
LOG.debug("Extracting default value from config provided default value \"%s\" for \"%s\"" % (def_val, key))
|
||||
actual_def_val = self._extract_default(def_val, auto_pw)
|
||||
LOG.debug("Using config provided default value \"%s\" for \"%s\" (no environment key)" % (actual_def_val, key))
|
||||
extracted_val = actual_def_val
|
||||
env_value = env.get_key(env_key)
|
||||
if env_value is None:
|
||||
LOG.debug("Extracting value from config provided default value [%s]" % (def_val))
|
||||
extracted_val = self._resolve_replacements(def_val, auto_pw)
|
||||
LOG.debug("Using config provided default value [%s] (no environment key)" % (extracted_val))
|
||||
else:
|
||||
env_val = env.get_key(env_key)
|
||||
LOG.debug("Using enviroment provided value \"%s\" for \"%s\"" % (env_val, key))
|
||||
extracted_val = env_val
|
||||
extracted_val = env_value
|
||||
LOG.debug("Using enviroment provided value [%s]" % (extracted_val))
|
||||
else:
|
||||
LOG.debug("Using raw config provided value \"%s\" for \"%s\"" % (value, key))
|
||||
extracted_val = value
|
||||
LOG.debug("Using raw config provided value [%s]" % (extracted_val))
|
||||
return extracted_val
|
||||
|
||||
def get_dbdsn(self, dbname):
|
||||
@ -197,7 +195,7 @@ class StackConfigParser(IgnoreMissingConfigParser):
|
||||
dsn += "/" + dbname
|
||||
else:
|
||||
dsn += "/"
|
||||
LOG.debug("For database \"%s\" fetched dsn \"%s\" %s" % (dbname, dsn, CACHE_MSG))
|
||||
LOG.debug("For database [%s] fetched dsn [%s] %s" % (dbname, dsn, CACHE_MSG))
|
||||
#store for later...
|
||||
self.db_dsns[dbname] = dsn
|
||||
return dsn
|
||||
|
@ -108,12 +108,10 @@ class DBUninstaller(comp.PkgUninstallComponent):
|
||||
if pwd_cmd:
|
||||
LOG.info("Ensuring your database is started before we operate on it.")
|
||||
self.runtime.restart()
|
||||
user = self.cfg.get("db", "sql_user")
|
||||
old_pw = self.cfg.get("passwords", 'sql')
|
||||
params = {
|
||||
'OLD_PASSWORD': old_pw,
|
||||
'OLD_PASSWORD': self.cfg.get("passwords", 'sql'),
|
||||
'NEW_PASSWORD': RESET_BASE_PW,
|
||||
'USER': user,
|
||||
'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
|
||||
}
|
||||
cmds = [{'cmd': pwd_cmd}]
|
||||
utils.execute_template(*cmds, params=params, shell=True)
|
||||
@ -135,7 +133,7 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
out = {
|
||||
'PASSWORD': self.cfg.get("passwords", "sql"),
|
||||
'BOOT_START': ("%s" % (True)).lower(),
|
||||
'USER': self.cfg.get("db", "sql_user"),
|
||||
'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
|
||||
'SERVICE_HOST': host_ip,
|
||||
'HOST_IP': host_ip
|
||||
}
|
||||
@ -197,7 +195,7 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
self.runtime.restart()
|
||||
params = {
|
||||
'NEW_PASSWORD': self.cfg.get("passwords", "sql"),
|
||||
'USER': self.cfg.get("db", "sql_user"),
|
||||
'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
|
||||
'OLD_PASSWORD': RESET_BASE_PW,
|
||||
}
|
||||
cmds = [{'cmd': pwd_cmd}]
|
||||
@ -210,7 +208,7 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
if dbactions:
|
||||
grant_cmd = dbactions.get('grant_all')
|
||||
if grant_cmd:
|
||||
user = self.cfg.get("db", "sql_user")
|
||||
user = self.cfg.getdefaulted("db", "sql_user", 'root')
|
||||
LOG.info("Updating the DB to give user '%s' full control of all databases." % (user))
|
||||
LOG.info("Ensuring your database is started before we operate on it.")
|
||||
self.runtime.restart()
|
||||
@ -300,7 +298,7 @@ def drop_db(cfg, dbname):
|
||||
dropcmd = dbactions.get('drop_db')
|
||||
params = dict()
|
||||
params['PASSWORD'] = cfg.get("passwords", "sql")
|
||||
params['USER'] = cfg.get("db", "sql_user")
|
||||
params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')
|
||||
params['DB'] = dbname
|
||||
cmds = list()
|
||||
cmds.append({
|
||||
@ -320,7 +318,7 @@ def create_db(cfg, dbname):
|
||||
createcmd = dbactions.get('create_db')
|
||||
params = dict()
|
||||
params['PASSWORD'] = cfg.get("passwords", "sql")
|
||||
params['USER'] = cfg.get("db", "sql_user")
|
||||
params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')
|
||||
params['DB'] = dbname
|
||||
cmds = list()
|
||||
cmds.append({
|
||||
|
@ -225,12 +225,8 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
self._config_fixups()
|
||||
|
||||
def _get_apache_user_group(self):
|
||||
user = self.cfg.get('horizon', 'apache_user')
|
||||
if not user:
|
||||
user = sh.getuser()
|
||||
group = self.cfg.get('horizon', 'apache_group')
|
||||
if not group:
|
||||
group = sh.getgroupname()
|
||||
user = self.cfg.getdefaulted('horizon', 'apache_user', sh.getuser())
|
||||
group = self.cfg.getdefaulted('horizon', 'apache_group', sh.getgroupname())
|
||||
return (user, group)
|
||||
|
||||
def _get_param_map(self, config_fn):
|
||||
|
@ -45,6 +45,9 @@ ROOT_CONF_REAL_NAME = 'melange.conf'
|
||||
CONFIGS = [ROOT_CONF]
|
||||
CFG_LOC = ['etc', 'melange']
|
||||
|
||||
#sensible defaults
|
||||
DEF_CIDR_RANGE = 'FE-EE-DD-00-00-00/24'
|
||||
|
||||
#how we sync melange with the db
|
||||
DB_SYNC_CMD = [
|
||||
{'cmd': ['%BINDIR%/melange-manage', '--config-file=%CFG_FILE%', 'db_sync']},
|
||||
@ -168,5 +171,5 @@ class MelangeRuntime(comp.PythonRuntime):
|
||||
LOG.info("Waiting %s seconds so that the melange server can start up before cidr range creation." % (WAIT_ONLINE_TO))
|
||||
time.sleep(WAIT_ONLINE_TO)
|
||||
mp = dict()
|
||||
mp['CIDR_RANGE'] = self.cfg.get('melange', 'm_mac_range')
|
||||
mp['CIDR_RANGE'] = self.cfg.getdefaulted('melange', 'm_mac_range', DEF_CIDR_RANGE)
|
||||
utils.execute_template(*CIDR_CREATE_CMD, params=mp)
|
||||
|
@ -402,11 +402,11 @@ class NovaInstaller(comp.PythonInstallComponent):
|
||||
if config_fn == NET_INIT_CONF:
|
||||
mp['NOVA_DIR'] = self.appdir
|
||||
mp['CFG_FILE'] = sh.joinpths(self.cfgdir, API_CONF)
|
||||
mp['FLOATING_RANGE'] = self.cfg.get('nova', 'floating_range')
|
||||
mp['TEST_FLOATING_RANGE'] = self.cfg.get('nova', 'test_floating_range')
|
||||
mp['TEST_FLOATING_POOL'] = self.cfg.get('nova', 'test_floating_pool')
|
||||
mp['FIXED_NETWORK_SIZE'] = self.cfg.get('nova', 'fixed_network_size')
|
||||
mp['FIXED_RANGE'] = self.cfg.get('nova', 'fixed_range')
|
||||
mp['FLOATING_RANGE'] = self.cfg.getdefaulted('nova', 'floating_range', '172.24.4.224/28')
|
||||
mp['TEST_FLOATING_RANGE'] = self.cfg.getdefaulted('nova', 'test_floating_range', '192.168.253.0/29')
|
||||
mp['TEST_FLOATING_POOL'] = self.cfg.getdefaulted('nova', 'test_floating_pool', 'test')
|
||||
mp['FIXED_NETWORK_SIZE'] = self.cfg.getdefaulted('nova', 'fixed_network_size', '256')
|
||||
mp['FIXED_RANGE'] = self.cfg.getdefaulted('nova', 'fixed_range', '10.0.0.0/24')
|
||||
else:
|
||||
mp.update(keystone.get_shared_params(self.cfg, 'nova'))
|
||||
return mp
|
||||
@ -515,12 +515,9 @@ class NovaVolumeConfigurator(object):
|
||||
def _setup_vol_groups(self):
|
||||
LOG.info("Attempting to setup volume groups for nova volume management.")
|
||||
mp = dict()
|
||||
backing_file = self.cfg.get('nova', 'volume_backing_file')
|
||||
# check if we need to have a default backing file
|
||||
if not backing_file:
|
||||
backing_file = sh.joinpths(self.appdir, 'nova-volumes-backing-file')
|
||||
vol_group = self.cfg.get('nova', 'volume_group')
|
||||
backing_file_size = utils.to_bytes(self.cfg.get('nova', 'volume_backing_file_size'))
|
||||
backing_file = self.cfg.getdefaulted('nova', 'volume_backing_file', sh.joinpths(self.appdir, 'nova-volumes-backing-file'))
|
||||
vol_group = self.cfg.getdefaulted('nova', 'volume_group', 'nova-volumes')
|
||||
backing_file_size = utils.to_bytes(self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M'))
|
||||
mp['VOLUME_GROUP'] = vol_group
|
||||
mp['VOLUME_BACKING_FILE'] = backing_file
|
||||
mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size
|
||||
@ -676,7 +673,7 @@ class NovaConfConfigurator(object):
|
||||
nova_conf.add('s3_host', hostip)
|
||||
|
||||
#how is your rabbit setup?
|
||||
nova_conf.add('rabbit_host', self.cfg.get('default', 'rabbit_host'))
|
||||
nova_conf.add('rabbit_host', self.cfg.getdefaulted('default', 'rabbit_host', hostip))
|
||||
nova_conf.add('rabbit_password', self.cfg.get("passwords", "rabbit"))
|
||||
|
||||
#where instances will be stored
|
||||
@ -782,16 +779,17 @@ class NovaConfConfigurator(object):
|
||||
#TODO this might not be right....
|
||||
if utils.service_enabled(settings.QUANTUM, self.instances, False):
|
||||
nova_conf.add('network_manager', QUANTUM_MANAGER)
|
||||
nova_conf.add('quantum_connection_host', self.cfg.get('quantum', 'q_host'))
|
||||
nova_conf.add('quantum_connection_port', self.cfg.get('quantum', 'q_port'))
|
||||
hostip = self.cfg.get('host', 'ip')
|
||||
nova_conf.add('quantum_connection_host', self.cfg.getdefaulted('quantum', 'q_host', hostip))
|
||||
nova_conf.add('quantum_connection_port', self.cfg.getdefaulted('quantum', 'q_port', '9696'))
|
||||
if self.cfg.get('quantum', 'q_plugin') == 'openvswitch':
|
||||
for (key, value) in QUANTUM_OPENSWITCH_OPS.items():
|
||||
nova_conf.add(key, value)
|
||||
if utils.service_enabled(settings.MELANGE_CLIENT, self.instances, False):
|
||||
nova_conf.add('quantum_ipam_lib', QUANTUM_IPAM_LIB)
|
||||
nova_conf.add('use_melange_mac_generation', True)
|
||||
nova_conf.add('melange_host', self.cfg.get('melange', 'm_host'))
|
||||
nova_conf.add('melange_port', self.cfg.get('melange', 'm_port'))
|
||||
nova_conf.add('melange_host', self.cfg.getdefaulted('melange', 'm_host', hostip))
|
||||
nova_conf.add('melange_port', self.cfg.getdefaulted('melange', 'm_port', '9898'))
|
||||
else:
|
||||
nova_conf.add('network_manager', NET_MANAGER_TEMPLATE % (self._getstr('network_manager', DEF_NET_MANAGER)))
|
||||
|
||||
|
@ -85,7 +85,7 @@ class QuantumInstaller(comp.PkgInstallComponent):
|
||||
comp.PkgInstallComponent.__init__(self, TYPE, *args, **kargs)
|
||||
self.q_vswitch_agent = False
|
||||
self.q_vswitch_service = False
|
||||
plugin = self.cfg.get("quantum", "q_plugin")
|
||||
plugin = self.cfg.getdefaulted("quantum", "q_plugin", VSWITCH_PLUGIN)
|
||||
if plugin == VSWITCH_PLUGIN:
|
||||
if len(self.component_opts) == 0:
|
||||
#default to on if not specified
|
||||
@ -174,7 +174,7 @@ class QuantumInstaller(comp.PkgInstallComponent):
|
||||
return comp.PkgInstallComponent._config_adjust(self, contents, config_fn)
|
||||
|
||||
def _setup_bridge(self):
|
||||
bridge = self.cfg.get("quantum", "ovs_bridge")
|
||||
bridge = self.cfg.getdefaulted("quantum", "ovs_bridge", 'br-int')
|
||||
if bridge:
|
||||
LOG.info("Fixing up ovs bridge named %s.", bridge)
|
||||
external_id = self.cfg.getdefaulted("quantum", 'ovs_bridge_external_name', bridge)
|
||||
@ -222,7 +222,7 @@ class QuantumRuntime(comp.ProgramRuntime):
|
||||
comp.ProgramRuntime.__init__(self, TYPE, *args, **kargs)
|
||||
self.q_vswitch_agent = False
|
||||
self.q_vswitch_service = False
|
||||
plugin = self.cfg.get("quantum", "q_plugin")
|
||||
plugin = self.cfg.getdefaulted("quantum", "q_plugin", VSWITCH_PLUGIN)
|
||||
if plugin == VSWITCH_PLUGIN:
|
||||
if len(self.component_opts) == 0:
|
||||
#default to on if not specified
|
||||
|
@ -74,7 +74,7 @@ WARMUP_PWS = ['service_token', 'swift_hash']
|
||||
class SwiftUninstaller(comp.PythonUninstallComponent):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonUninstallComponent.__init__(self, TYPE, *args, **kargs)
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.get('swift', 'data_location'))
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.getdefaulted('swift', 'data_location', 'data'))
|
||||
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
||||
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
||||
self.logdir = sh.joinpths(self.datadir, LOG_DIR)
|
||||
@ -93,7 +93,7 @@ class SwiftInstaller(comp.PythonInstallComponent):
|
||||
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
|
||||
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
||||
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.get('swift', 'data_location'))
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.getdefaulted('swift', 'data_location', 'data'))
|
||||
self.logdir = sh.joinpths(self.datadir, LOG_DIR)
|
||||
self.startmain_file = sh.joinpths(self.bindir, SWIFT_STARTMAIN)
|
||||
self.makerings_file = sh.joinpths(self.bindir, SWIFT_MAKERINGS)
|
||||
@ -121,15 +121,15 @@ class SwiftInstaller(comp.PythonInstallComponent):
|
||||
|
||||
def _get_param_map(self, config_fn):
|
||||
return {
|
||||
'USER': self.cfg.get('swift', 'swift_user'),
|
||||
'GROUP': self.cfg.get('swift', 'swift_group'),
|
||||
'USER': self.cfg.getdefaulted('swift', 'swift_user', sh.getuser()),
|
||||
'GROUP': self.cfg.getdefaulted('swift', 'swift_group', sh.getgroupname()),
|
||||
'SWIFT_DATA_LOCATION': self.datadir,
|
||||
'SWIFT_CONFIG_LOCATION': self.cfgdir,
|
||||
'SERVICE_TOKEN': self.cfg.get('passwords', 'service_token'),
|
||||
'AUTH_SERVER': self.auth_server,
|
||||
'SWIFT_HASH': self.cfg.get('passwords', 'swift_hash'),
|
||||
'SWIFT_LOGDIR': self.logdir,
|
||||
'SWIFT_PARTITION_POWER_SIZE': self.cfg.get('swift', 'partition_power_size'),
|
||||
'SWIFT_PARTITION_POWER_SIZE': self.cfg.getdefaulted('swift', 'partition_power_size', '9'),
|
||||
#leave these alone, will be adjusted later
|
||||
'NODE_PATH': '%NODE_PATH%',
|
||||
'BIND_PORT': '%BIND_PORT%',
|
||||
@ -208,7 +208,7 @@ class SwiftInstaller(comp.PythonInstallComponent):
|
||||
class SwiftRuntime(comp.PythonRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonRuntime.__init__(self, TYPE, *args, **kargs)
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.get('swift', 'data_location'))
|
||||
self.datadir = sh.joinpths(self.appdir, self.cfg.getdefaulted('swift', 'data_location', 'data'))
|
||||
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
||||
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
||||
self.logdir = sh.joinpths(self.datadir, LOG_DIR)
|
||||
|
@ -35,11 +35,13 @@ def set(key, value):
|
||||
|
||||
|
||||
def get_key(key, default_value=None):
|
||||
LOG.debug("Looking up environment variable \"%s\"" % (key))
|
||||
if not key:
|
||||
return default_value
|
||||
LOG.debug("Looking up environment variable [%s]" % (key))
|
||||
value = get().get(key)
|
||||
if value is None:
|
||||
LOG.debug("Could not find anything in environment variable \"%s\"" % (key))
|
||||
LOG.debug("Could not find anything in environment variable [%s]" % (key))
|
||||
value = default_value
|
||||
else:
|
||||
LOG.debug("Found \"%s\" in environment variable \"%s\"" % (value, key))
|
||||
LOG.debug("Found [%s] in environment variable [%s]" % (value, key))
|
||||
return value
|
||||
|
@ -55,17 +55,12 @@ class RcWriter(object):
|
||||
escaped_val = sh.shellquote(value)
|
||||
full_line = "export %s=%s" % (export_name, escaped_val)
|
||||
return full_line
|
||||
|
||||
def _valid_value(self, value):
|
||||
if not value:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _make_dict_export(self, kvs):
|
||||
lines = list()
|
||||
for var_name in sorted(kvs.keys()):
|
||||
var_value = kvs.get(var_name)
|
||||
if self._valid_value(var_value):
|
||||
if var_value is not None:
|
||||
lines.append(self._make_export(var_name, str(var_value)))
|
||||
return lines
|
||||
|
||||
@ -76,8 +71,8 @@ class RcWriter(object):
|
||||
to_set['EC2_URL'] = self.cfg.getdefaulted('extern', 'ec2_url', ec2_url_default, auto_pw=False)
|
||||
s3_url_default = urlunparse(('http', "%s:%s" % (ip, S3_PORT), "services/Cloud", '', '', ''))
|
||||
to_set['S3_URL'] = self.cfg.getdefaulted('extern', 's3_url', s3_url_default, auto_pw=False)
|
||||
to_set['EC2_CERT'] = self.cfg.getdefaulted('extern', 'ec2_cert_fn', '', auto_pw=False)
|
||||
to_set['EC2_USER_ID'] = self.cfg.getdefaulted('extern', 'ec2_user_id', '', auto_pw=False)
|
||||
to_set['EC2_CERT'] = self.cfg.get('extern', 'ec2_cert_fn', auto_pw=False)
|
||||
to_set['EC2_USER_ID'] = self.cfg.get('extern', 'ec2_user_id', auto_pw=False)
|
||||
return to_set
|
||||
|
||||
def _generate_ec2_env(self):
|
||||
@ -91,7 +86,7 @@ class RcWriter(object):
|
||||
to_set = dict()
|
||||
for (out_name, cfg_data) in CFG_MAKE.items():
|
||||
(section, key) = (cfg_data)
|
||||
to_set[out_name] = self.cfg.getdefaulted(section, key, '', auto_pw=False)
|
||||
to_set[out_name] = self.cfg.get(section, key, auto_pw=False)
|
||||
return to_set
|
||||
|
||||
def _generate_general(self):
|
||||
@ -125,7 +120,7 @@ class RcWriter(object):
|
||||
new_vars = dict()
|
||||
updated_vars = dict()
|
||||
for (key, value) in possible_vars.items():
|
||||
if self._valid_value(value):
|
||||
if value is not None:
|
||||
if key in current_vars and (current_vars.get(key) != value):
|
||||
updated_vars[key] = value
|
||||
elif key not in current_vars:
|
||||
@ -184,7 +179,7 @@ alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_
|
||||
|
||||
def _get_euca_envs(self):
|
||||
to_set = dict()
|
||||
to_set['EUCALYPTUS_CERT'] = self.cfg.getdefaulted('extern', 'nova_cert_fn', '', auto_pw=False)
|
||||
to_set['EUCALYPTUS_CERT'] = self.cfg.get('extern', 'nova_cert_fn', auto_pw=False)
|
||||
return to_set
|
||||
|
||||
def _generate_euca_env(self):
|
||||
@ -196,8 +191,8 @@ alias ec2-upload-bundle="ec2-upload-bundle -a ${EC2_ACCESS_KEY} -s ${EC2_SECRET_
|
||||
|
||||
def _get_nova_envs(self):
|
||||
to_set = dict()
|
||||
to_set['NOVA_VERSION'] = self.cfg.getdefaulted('nova', 'nova_version', '', auto_pw=False)
|
||||
to_set['NOVA_CERT'] = self.cfg.getdefaulted('extern', 'nova_cert_fn', '', auto_pw=False)
|
||||
to_set['NOVA_VERSION'] = self.cfg.get('nova', 'nova_version', auto_pw=False)
|
||||
to_set['NOVA_CERT'] = self.cfg.get('extern', 'nova_cert_fn', auto_pw=False)
|
||||
return to_set
|
||||
|
||||
def _generate_nova_env(self):
|
||||
|
@ -269,12 +269,11 @@ class ImageCreationService:
|
||||
|
||||
#extract them from the config
|
||||
try:
|
||||
flat_urls = self.cfg.get('img', 'image_urls')
|
||||
if flat_urls:
|
||||
expanded_urls = [x.strip() for x in flat_urls.split(',')]
|
||||
for url in expanded_urls:
|
||||
if url:
|
||||
urls.append(url)
|
||||
flat_urls = self.cfg.getdefaulted('img', 'image_urls', [])
|
||||
expanded_urls = [x.strip() for x in flat_urls.split(',')]
|
||||
for url in expanded_urls:
|
||||
if url:
|
||||
urls.append(url)
|
||||
except(ConfigParser.Error):
|
||||
LOG.warn("No image configuration keys found, skipping glance image install!")
|
||||
|
||||
|
@ -82,8 +82,8 @@ class UpstartRunner(base.RunnerBase):
|
||||
params['RESPAWN'] = ""
|
||||
params['SHORT_NAME'] = program_name
|
||||
params['MADE_DATE'] = date.rcf8222date()
|
||||
params['START_EVENT'] = self.cfg.get('upstart', 'start_event')
|
||||
params['STOP_EVENT'] = self.cfg.get('upstart', 'stop_event')
|
||||
params['START_EVENT'] = self.cfg.getdefaulted('upstart', 'start_event', 'all_os_start')
|
||||
params['STOP_EVENT'] = self.cfg.getdefaulted('upstart', 'stop_event', 'all_os_stop')
|
||||
params['COMPONENT_START_EVENT'] = self.component_name + START_EVENT_SUFFIX
|
||||
params['COMPONENT_STOP_EVENT'] = self.component_name + STOP_EVENT_SUFFIX
|
||||
params['PROGRAM_NAME'] = app_pth
|
||||
|
Loading…
x
Reference in New Issue
Block a user