Updated how we handle passwords and host information so that its transparent to config caller.

This commit is contained in:
Joshua Harlow
2012-01-22 11:37:45 -08:00
parent 48f361c2d1
commit cb69a36dcc
10 changed files with 53 additions and 56 deletions

View File

@@ -27,16 +27,18 @@
[default] [default]
# Set api host endpoint
# If this is empty in code we will try to determine your network ip.
host_ip = ${HOST_IP:-}
# Where is rabbit located? # Where is rabbit located?
rabbit_host = ${RABBIT_HOST:-localhost} rabbit_host = ${RABBIT_HOST:-localhost}
# Sys log enabled or not # Sys log enabled or not
syslog = 0 syslog = 0
[host]
# Set api host endpoint
# If this is empty in code we will try to determine your network ip.
ip = ${HOST_IP:-}
[db] [db]
# Where you db is located at and how to access it. # Where you db is located at and how to access it.

View File

@@ -81,18 +81,37 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
parts = [section, option] parts = [section, option]
return "/".join(parts) return "/".join(parts)
def _resolve_special(self, section, option, value_gotten):
if(value_gotten and len(value_gotten)):
#you already got something, so no need to figure it out
return value_gotten
if(section == 'host' and option == 'ip'):
LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.")
host_ip = utils.get_host_ip()
LOG.debug("Determined host ip to be: \"%s\"" % (host_ip))
return host_ip
elif(section == 'passwords'):
key = self._makekey(section, option)
LOG.debug("Being forced to ask for password for \"%s\" since the configuration/environment value is empty.", key)
pw = sh.password(PW_TMPL % (key))
self.pws[key] = pw
return pw
else:
return value_gotten
def get(self, section, option): def get(self, section, option):
key = self._makekey(section, option) key = self._makekey(section, option)
v = None value = None
if(key in self.configs_fetched): if(key in self.configs_fetched):
v = self.configs_fetched.get(key) value = self.configs_fetched.get(key)
LOG.debug("Fetched cached value \"%s\" for param \"%s\"" % (v, key)) LOG.debug("Fetched cached value \"%s\" for param \"%s\"" % (value, key))
else: else:
LOG.debug("Fetching value for param \"%s\"" % (key)) LOG.debug("Fetching value for param \"%s\"" % (key))
v = self._get_special(section, option) gotten_value = self._get_special(section, option)
LOG.debug("Fetched \"%s\" for \"%s\"" % (v, key)) value = self._resolve_special(section, option, gotten_value)
self.configs_fetched[key] = v LOG.debug("Fetched \"%s\" for \"%s\"" % (value, key))
return v self.configs_fetched[key] = value
return value
def _extract_default(self, default_value): def _extract_default(self, default_value):
if(not SUB_MATCH.search(default_value)): if(not SUB_MATCH.search(default_value)):
@@ -112,6 +131,7 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
key = self._makekey(section, option) key = self._makekey(section, option)
parent_val = ConfigParser.RawConfigParser.get(self, section, option) parent_val = ConfigParser.RawConfigParser.get(self, section, option)
if(parent_val == None): if(parent_val == None):
#parent didn't have anything, we are unable to do anything with it then
return None return None
extracted_val = None extracted_val = None
mtch = ENV_PAT.match(parent_val) mtch = ENV_PAT.match(parent_val)
@@ -135,21 +155,11 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
extracted_val = parent_val extracted_val = parent_val
return extracted_val return extracted_val
def get_host_ip(self):
host_ip = self.get('default', 'host_ip')
if(not host_ip):
LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.")
host_ip = utils.get_host_ip()
key = self._makekey('default', 'host_ip')
self.configs_fetched[key] = host_ip
LOG.debug("Determined host ip to be: \"%s\"" % (host_ip))
return host_ip
def get_dbdsn(self, dbname): def get_dbdsn(self, dbname):
user = self.get("db", "sql_user") user = self.get("db", "sql_user")
host = self.get("db", "sql_host") host = self.get("db", "sql_host")
port = self.get("db", "port") port = self.get("db", "port")
pw = self.getpw("passwords", "sql") pw = self.get("passwords", "sql")
#check the dsn cache #check the dsn cache
if(dbname in self.db_dsns): if(dbname in self.db_dsns):
return self.db_dsns[dbname] return self.db_dsns[dbname]
@@ -180,19 +190,3 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
#store for later... #store for later...
self.db_dsns[dbname] = dsn self.db_dsns[dbname] = dsn
return dsn return dsn
def getpw(self, section, option):
key = self._makekey(section, option)
pw = self.pws.get(key)
if(pw != None):
return pw
pw = self.get(section, option)
if(pw == None):
pw = ""
if(len(pw) == 0):
LOG.debug("Being forced to ask for password for \"%s\" since the configuration/environment value is empty.", key)
while(len(pw) == 0):
pw = sh.password(PW_TMPL % (key))
LOG.debug("Password for \"%s\" will be \"%s\" %s" % (key, pw, CACHE_MSG))
self.pws[key] = pw
return pw

View File

@@ -63,11 +63,12 @@ class DBInstaller(comp.PkgInstallComponent):
#this dictionary will be used for parameter replacement #this dictionary will be used for parameter replacement
#in pre-install and post-install sections #in pre-install and post-install sections
out = dict() out = dict()
out['PASSWORD'] = self.cfg.getpw("passwords", "sql") out['PASSWORD'] = self.cfg.get("passwords", "sql")
out['BOOT_START'] = str(True).lower() out['BOOT_START'] = str(True).lower()
out['USER'] = self.cfg.get("db", "sql_user") out['USER'] = self.cfg.get("db", "sql_user")
out['SERVICE_HOST'] = self.cfg.get_host_ip() host_ip = self.cfg.get('host', 'ip')
out['HOST_IP'] = self.cfg.get_host_ip() out['SERVICE_HOST'] = host_ip
out['HOST_IP'] = host_ip
return out return out
def post_install(self): def post_install(self):
@@ -145,7 +146,7 @@ def drop_db(cfg, dbname):
if(dbactions and dbactions.get('drop_db')): if(dbactions and dbactions.get('drop_db')):
dropcmd = dbactions.get('drop_db') dropcmd = dbactions.get('drop_db')
params = dict() params = dict()
params['PASSWORD'] = cfg.getpw("passwords", "sql") params['PASSWORD'] = cfg.get("passwords", "sql")
params['USER'] = cfg.get("db", "sql_user") params['USER'] = cfg.get("db", "sql_user")
params['DB'] = dbname params['DB'] = dbname
cmds = list() cmds = list()
@@ -165,7 +166,7 @@ def create_db(cfg, dbname):
if(dbactions and dbactions.get('create_db')): if(dbactions and dbactions.get('create_db')):
createcmd = dbactions.get('create_db') createcmd = dbactions.get('create_db')
params = dict() params = dict()
params['PASSWORD'] = cfg.getpw("passwords", "sql") params['PASSWORD'] = cfg.get("passwords", "sql")
params['USER'] = cfg.get("db", "sql_user") params['USER'] = cfg.get("db", "sql_user")
params['DB'] = dbname params['DB'] = dbname
cmds = list() cmds = list()

View File

@@ -152,8 +152,8 @@ class GlanceInstaller(comp.PythonInstallComponent):
mp = dict() mp = dict()
mp['DEST'] = self.appdir mp['DEST'] = self.appdir
mp['SYSLOG'] = self.cfg.getboolean("default", "syslog") mp['SYSLOG'] = self.cfg.getboolean("default", "syslog")
mp['SERVICE_TOKEN'] = self.cfg.getpw("passwords", "service_token") mp['SERVICE_TOKEN'] = self.cfg.get("passwords", "service_token")
mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME) mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME)
mp['SERVICE_HOST'] = self.cfg.get_host_ip() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip')
mp['HOST_IP'] = self.cfg.get_host_ip() mp['HOST_IP'] = self.cfg.get('host', 'ip')
return mp return mp

View File

@@ -133,7 +133,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
else: else:
#Enable quantum in dashboard, if requested #Enable quantum in dashboard, if requested
mp['QUANTUM_ENABLED'] = "%s" % (constants.QUANTUM in self.all_components) mp['QUANTUM_ENABLED'] = "%s" % (constants.QUANTUM in self.all_components)
mp['OPENSTACK_HOST'] = self.cfg.get_host_ip() mp['OPENSTACK_HOST'] = self.cfg.get('host', 'ip')
return mp return mp

View File

@@ -161,10 +161,10 @@ class KeystoneInstaller(comp.PythonInstallComponent):
mp['DEST'] = self.appdir mp['DEST'] = self.appdir
mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME) mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME)
elif(config_fn == MANAGE_JSON_CONF): elif(config_fn == MANAGE_JSON_CONF):
host_ip = self.cfg.get_host_ip() host_ip = self.cfg.get('host', 'ip')
mp['ADMIN_PASSWORD'] = self.cfg.getpw('passwords', 'horizon_keystone_admin') mp['ADMIN_PASSWORD'] = self.cfg.get('passwords', 'horizon_keystone_admin')
mp['SERVICE_HOST'] = host_ip mp['SERVICE_HOST'] = host_ip
mp['SERVICE_TOKEN'] = self.cfg.getpw("passwords", "service_token") mp['SERVICE_TOKEN'] = self.cfg.get("passwords", "service_token")
mp['BIN_DIR'] = self.bindir mp['BIN_DIR'] = self.bindir
mp['CONFIG_FILE'] = sh.joinpths(self.cfgdir, ROOT_CONF) mp['CONFIG_FILE'] = sh.joinpths(self.cfgdir, ROOT_CONF)
keystone_auth_host = self.cfg.get('keystone', 'keystone_auth_host') keystone_auth_host = self.cfg.get('keystone', 'keystone_auth_host')

View File

@@ -45,7 +45,7 @@ class NovaClientInstaller(comp.PythonInstallComponent):
#params with actual values #params with actual values
mp = dict() mp = dict()
mp['DEST'] = self.appdir mp['DEST'] = self.appdir
mp['OPENSTACK_HOST'] = self.cfg.get_host_ip() mp['OPENSTACK_HOST'] = self.cfg.get('host', 'ip')
return mp return mp

View File

@@ -56,7 +56,7 @@ class NovaConfigurator():
#TODO split up into sections?? #TODO split up into sections??
nova_conf = NovaConf() nova_conf = NovaConf()
hostip = self.cfg.get_host_ip() hostip = self.cfg.get('host', 'ip')
#verbose on? #verbose on?
if(self._getbool('verbose')): if(self._getbool('verbose')):
@@ -148,7 +148,7 @@ class NovaConfigurator():
#how is your rabbit setup? #how is your rabbit setup?
nova_conf.add('rabbit_host', self.cfg.get('default', 'rabbit_host')) nova_conf.add('rabbit_host', self.cfg.get('default', 'rabbit_host'))
nova_conf.add('rabbit_password', self.cfg.getpw("passwords", "rabbit")) nova_conf.add('rabbit_password', self.cfg.get("passwords", "rabbit"))
#where is glance located? #where is glance located?
glance_api_server = self._getstr('glance_server') glance_api_server = self._getstr('glance_server')
@@ -204,7 +204,7 @@ class NovaConfigurator():
nova_conf.add('xenapi_connection_url', 'http://169.254.0.1') nova_conf.add('xenapi_connection_url', 'http://169.254.0.1')
nova_conf.add('xenapi_connection_username', 'root') nova_conf.add('xenapi_connection_username', 'root')
# TODO, check that this is the right way to get the password # TODO, check that this is the right way to get the password
nova_conf.add('xenapi_connection_password', self.cfg.getpw("passwords", "xenapi")) nova_conf.add('xenapi_connection_password', self.cfg.get("passwords", "xenapi"))
nova_conf.add_simple('noflat_injected') nova_conf.add_simple('noflat_injected')
nova_conf.add('flat_interface', 'eth1') nova_conf.add('flat_interface', 'eth1')
nova_conf.add('flat_network_bridge', 'xapi1') nova_conf.add('flat_network_bridge', 'xapi1')

View File

@@ -45,7 +45,7 @@ class RabbitInstaller(comp.PkgInstallComponent):
self.runtime = RabbitRuntime(*args, **kargs) self.runtime = RabbitRuntime(*args, **kargs)
def _setup_pw(self): def _setup_pw(self):
passwd = self.cfg.getpw("passwords", "rabbit") passwd = self.cfg.get("passwords", "rabbit")
cmd = PWD_CMD + [passwd] cmd = PWD_CMD + [passwd]
sh.execute(*cmd, run_as_root=True) sh.execute(*cmd, run_as_root=True)

View File

@@ -193,7 +193,7 @@ class ImageCreationService:
def __init__(self, cfg=None, flat_urls=None, token=None): def __init__(self, cfg=None, flat_urls=None, token=None):
if cfg: if cfg:
token = cfg.getpw("passwords", "service_token") token = cfg.get("passwords", "service_token")
flat_urls = cfg.get('img', 'image_urls') flat_urls = cfg.get('img', 'image_urls')
if flat_urls: if flat_urls: