2012-01-11 12:47:33 -08:00
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
import io
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
from devstack import cfg
|
|
|
|
from devstack import component as comp
|
|
|
|
from devstack import log as logging
|
2012-01-22 16:09:47 -08:00
|
|
|
from devstack import settings
|
2012-01-20 14:12:20 -08:00
|
|
|
from devstack import shell as sh
|
|
|
|
from devstack import utils
|
|
|
|
from devstack.components import db
|
|
|
|
|
|
|
|
LOG = logging.getLogger("devstack.components.keystone")
|
|
|
|
|
2012-01-24 18:10:38 -08:00
|
|
|
#id
|
2012-01-22 16:09:47 -08:00
|
|
|
TYPE = settings.KEYSTONE
|
2012-01-24 18:10:38 -08:00
|
|
|
|
|
|
|
#this db will be dropped then created
|
2012-01-24 18:03:42 -08:00
|
|
|
DB_NAME = "keystone"
|
|
|
|
|
|
|
|
#subdirs of the git checkout
|
2012-01-11 12:47:33 -08:00
|
|
|
BIN_DIR = "bin"
|
2012-01-24 17:38:06 -08:00
|
|
|
CONFIG_DIR = "etc"
|
2012-01-24 18:03:42 -08:00
|
|
|
|
|
|
|
#simple confs
|
|
|
|
ROOT_CONF = "keystone.conf"
|
|
|
|
CONFIGS = [ROOT_CONF]
|
2012-01-18 13:51:51 -08:00
|
|
|
CFG_SECTION = 'DEFAULT'
|
2012-01-24 18:03:42 -08:00
|
|
|
|
|
|
|
#this is a special conf
|
2012-01-24 17:38:06 -08:00
|
|
|
MANAGE_DATA_CONF = 'keystone_data.sh'
|
2012-01-24 18:03:42 -08:00
|
|
|
MANAGER_CMD_ROOT = [sh.joinpths("/", "bin", 'bash')]
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-17 15:24:57 -08:00
|
|
|
#what to start
|
|
|
|
APP_OPTIONS = {
|
2012-01-24 17:38:06 -08:00
|
|
|
'keystone': ['-c', sh.joinpths('%ROOT%', CONFIG_DIR, ROOT_CONF),
|
2012-01-24 18:03:42 -08:00
|
|
|
"--verbose", '-d',
|
2012-01-24 17:38:06 -08:00
|
|
|
'--log-config=' + sh.joinpths('%ROOT%', CONFIG_DIR, 'logging.cnf')]
|
2012-01-17 15:24:57 -08:00
|
|
|
}
|
|
|
|
|
2012-01-21 21:24:41 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class KeystoneUninstaller(comp.PythonUninstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonUninstallComponent.__init__(self, TYPE, *args, **kargs)
|
|
|
|
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
|
|
|
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-13 19:04:26 -08:00
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class KeystoneInstaller(comp.PythonInstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
|
2012-01-18 22:54:13 -08:00
|
|
|
self.git_loc = self.cfg.get("git", "keystone_repo")
|
|
|
|
self.git_branch = self.cfg.get("git", "keystone_branch")
|
2012-01-20 14:12:20 -08:00
|
|
|
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
|
|
|
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-18 15:49:01 -08:00
|
|
|
def _get_download_locations(self):
|
2012-01-20 14:12:20 -08:00
|
|
|
places = comp.PythonInstallComponent._get_download_locations(self)
|
2012-01-18 15:49:01 -08:00
|
|
|
places.append({
|
2012-01-18 22:54:13 -08:00
|
|
|
'uri': self.git_loc,
|
|
|
|
'branch': self.git_branch,
|
2012-01-18 15:49:01 -08:00
|
|
|
})
|
|
|
|
return places
|
2012-01-12 20:30:48 -08:00
|
|
|
|
2012-01-18 13:51:51 -08:00
|
|
|
def post_install(self):
|
2012-01-20 14:12:20 -08:00
|
|
|
parent_result = comp.PythonInstallComponent.post_install(self)
|
2012-01-11 12:47:33 -08:00
|
|
|
self._setup_db()
|
|
|
|
self._setup_data()
|
2012-01-18 13:51:51 -08:00
|
|
|
return parent_result
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-13 18:39:05 -08:00
|
|
|
def _get_config_files(self):
|
|
|
|
return list(CONFIGS)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
|
|
|
def _setup_db(self):
|
2012-01-20 14:12:20 -08:00
|
|
|
db.drop_db(self.cfg, DB_NAME)
|
|
|
|
db.create_db(self.cfg, DB_NAME)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
|
|
|
def _setup_data(self):
|
2012-01-24 22:29:14 -08:00
|
|
|
LOG.info("Configuring data setup template %s", MANAGE_DATA_CONF)
|
|
|
|
(src_fn, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF)
|
2012-01-24 17:38:06 -08:00
|
|
|
params = self._get_param_map(MANAGE_DATA_CONF)
|
|
|
|
contents = utils.param_replace(contents, params, True)
|
|
|
|
tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF)
|
|
|
|
sh.write_file(tgt_fn, contents)
|
2012-01-24 18:03:42 -08:00
|
|
|
# This environment additions are important
|
2012-01-24 22:29:14 -08:00
|
|
|
# in that they eventually affect how this script runs
|
2012-01-24 17:38:06 -08:00
|
|
|
env = dict()
|
|
|
|
env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
|
|
|
|
env['BIN_DIR'] = self.bindir
|
2012-01-24 18:03:42 -08:00
|
|
|
setup_cmd = MANAGER_CMD_ROOT + [tgt_fn]
|
2012-01-24 17:38:06 -08:00
|
|
|
LOG.info("Running (%s) command to setup keystone." % (" ".join(setup_cmd)))
|
|
|
|
sh.execute(*setup_cmd, env_overrides=env)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-18 13:51:51 -08:00
|
|
|
def _config_adjust(self, contents, name):
|
|
|
|
if(name not in CONFIGS):
|
|
|
|
return contents
|
2012-01-18 20:12:04 -08:00
|
|
|
#use config parser and
|
|
|
|
#then extract known configs that
|
2012-01-18 13:51:51 -08:00
|
|
|
#will need locations/directories/files made (or touched)...
|
|
|
|
with io.BytesIO(contents) as stream:
|
2012-01-20 14:12:20 -08:00
|
|
|
config = cfg.IgnoreMissingConfigParser()
|
2012-01-18 13:51:51 -08:00
|
|
|
config.readfp(stream)
|
|
|
|
log_filename = config.get('log_file', CFG_SECTION)
|
|
|
|
if(log_filename):
|
|
|
|
LOG.info("Ensuring log file %s exists and is empty" % (log_filename))
|
2012-01-21 10:58:09 -08:00
|
|
|
log_dir = sh.dirname(log_filename)
|
2012-01-18 13:51:51 -08:00
|
|
|
if(log_dir):
|
|
|
|
LOG.info("Ensuring log directory %s exists" % (log_dir))
|
2012-01-19 21:36:49 -08:00
|
|
|
self.tracewriter.make_dir(log_dir)
|
2012-01-18 13:51:51 -08:00
|
|
|
#destroy then recreate it (the log file)
|
2012-01-20 14:12:20 -08:00
|
|
|
sh.unlink(log_filename)
|
|
|
|
sh.touch_file(log_filename)
|
2012-01-18 13:51:51 -08:00
|
|
|
self.tracewriter.file_touched(log_filename)
|
|
|
|
#we might need to handle more in the future...
|
|
|
|
#nothing modified so just return the original
|
2012-01-13 18:39:05 -08:00
|
|
|
return contents
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-19 16:21:27 -08:00
|
|
|
def _get_param_map(self, config_fn):
|
2012-01-13 15:08:48 -08:00
|
|
|
#these be used to fill in the configuration/cmds +
|
2012-01-12 10:49:25 -08:00
|
|
|
#params with actual values
|
2012-01-11 12:47:33 -08:00
|
|
|
mp = dict()
|
2012-01-21 19:36:00 -08:00
|
|
|
if(config_fn == ROOT_CONF):
|
2012-01-24 15:42:32 -08:00
|
|
|
host_ip = self.cfg.get('host', 'ip')
|
2012-01-21 19:36:00 -08:00
|
|
|
mp['DEST'] = self.appdir
|
|
|
|
mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME)
|
2012-01-24 15:42:32 -08:00
|
|
|
mp['SERVICE_HOST'] = host_ip
|
|
|
|
mp['ADMIN_HOST'] = host_ip
|
2012-01-24 17:38:06 -08:00
|
|
|
elif(config_fn == MANAGE_DATA_CONF):
|
2012-01-22 11:37:45 -08:00
|
|
|
host_ip = self.cfg.get('host', 'ip')
|
|
|
|
mp['ADMIN_PASSWORD'] = self.cfg.get('passwords', 'horizon_keystone_admin')
|
2012-01-21 19:36:00 -08:00
|
|
|
mp['SERVICE_HOST'] = host_ip
|
2012-01-24 15:42:32 -08:00
|
|
|
mp.update(get_shared_params(self.cfg))
|
2012-01-21 19:36:00 -08:00
|
|
|
else:
|
|
|
|
mp['DEST'] = self.appdir
|
|
|
|
mp['BIN_DIR'] = self.bindir
|
|
|
|
mp['CONFIG_FILE'] = sh.joinpths(self.cfgdir, ROOT_CONF)
|
2012-01-11 12:47:33 -08:00
|
|
|
return mp
|
|
|
|
|
|
|
|
|
2012-01-20 14:12:20 -08:00
|
|
|
class KeystoneRuntime(comp.PythonRuntime):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-20 14:12:20 -08:00
|
|
|
comp.PythonRuntime.__init__(self, TYPE, *args, **kargs)
|
|
|
|
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
|
|
|
|
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
|
2012-01-12 23:42:25 -08:00
|
|
|
|
2012-01-17 15:24:57 -08:00
|
|
|
def _get_apps_to_start(self):
|
2012-01-18 17:24:19 -08:00
|
|
|
apps = list()
|
|
|
|
for app_name in APP_OPTIONS.keys():
|
|
|
|
apps.append({
|
|
|
|
'name': app_name,
|
2012-01-20 14:12:20 -08:00
|
|
|
'path': sh.joinpths(self.bindir, app_name),
|
2012-01-18 17:24:19 -08:00
|
|
|
})
|
|
|
|
return apps
|
2012-01-17 15:24:57 -08:00
|
|
|
|
|
|
|
def _get_app_options(self, app):
|
|
|
|
return APP_OPTIONS.get(app)
|
2012-01-24 18:03:42 -08:00
|
|
|
|
|
|
|
|
2012-01-24 15:42:32 -08:00
|
|
|
def get_shared_params(cfg):
|
|
|
|
mp = dict()
|
|
|
|
host_ip = cfg.get('host', 'ip')
|
|
|
|
keystone_auth_host = cfg.get('keystone', 'keystone_auth_host')
|
|
|
|
if(not keystone_auth_host):
|
|
|
|
keystone_auth_host = host_ip
|
|
|
|
mp['KEYSTONE_AUTH_HOST'] = keystone_auth_host
|
|
|
|
mp['KEYSTONE_AUTH_PORT'] = cfg.get('keystone', 'keystone_auth_port')
|
|
|
|
mp['KEYSTONE_AUTH_PROTOCOL'] = cfg.get('keystone', 'keystone_auth_protocol')
|
|
|
|
keystone_service_host = cfg.get('keystone', 'keystone_service_host')
|
|
|
|
if(not keystone_service_host):
|
|
|
|
keystone_service_host = host_ip
|
|
|
|
mp['KEYSTONE_SERVICE_HOST'] = keystone_service_host
|
|
|
|
mp['KEYSTONE_SERVICE_PORT'] = cfg.get('keystone', 'keystone_service_port')
|
|
|
|
mp['KEYSTONE_SERVICE_PROTOCOL'] = cfg.get('keystone', 'keystone_service_protocol')
|
|
|
|
mp['SERVICE_TOKEN'] = cfg.get("passwords", "service_token")
|
|
|
|
return mp
|