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.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
2012-01-18 13:51:51 -08:00
|
|
|
import io
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-13 15:08:48 -08:00
|
|
|
import Pip
|
2012-01-17 22:09:40 -08:00
|
|
|
import Logger
|
|
|
|
import Db
|
2012-01-18 13:51:51 -08:00
|
|
|
import Config
|
2012-01-17 22:09:40 -08:00
|
|
|
|
|
|
|
#TODO fix these
|
2012-01-13 19:04:26 -08:00
|
|
|
from Util import (KEYSTONE,
|
2012-01-13 18:39:05 -08:00
|
|
|
CONFIG_DIR,
|
2012-01-13 12:07:41 -08:00
|
|
|
NOVA, GLANCE, SWIFT,
|
2012-01-13 18:39:05 -08:00
|
|
|
get_host_ip,
|
2012-01-17 15:24:57 -08:00
|
|
|
execute_template,
|
|
|
|
param_replace)
|
2012-01-17 17:32:13 -08:00
|
|
|
from Component import (PythonUninstallComponent,
|
2012-01-17 15:24:57 -08:00
|
|
|
PythonInstallComponent, PythonRuntime)
|
2012-01-13 18:39:05 -08:00
|
|
|
from Shell import (mkdirslist, unlink, touch_file, joinpths)
|
2012-01-17 22:09:40 -08:00
|
|
|
|
2012-01-11 12:47:33 -08:00
|
|
|
LOG = Logger.getLogger("install.keystone")
|
2012-01-12 17:35:41 -08:00
|
|
|
|
2012-01-11 12:47:33 -08:00
|
|
|
TYPE = KEYSTONE
|
|
|
|
ROOT_CONF = "keystone.conf"
|
|
|
|
CONFIGS = [ROOT_CONF]
|
|
|
|
BIN_DIR = "bin"
|
|
|
|
DB_NAME = "keystone"
|
2012-01-18 13:51:51 -08:00
|
|
|
CFG_SECTION = 'DEFAULT'
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-17 15:24:57 -08:00
|
|
|
#what to start
|
|
|
|
APP_OPTIONS = {
|
|
|
|
'keystone': ['--config-file', joinpths('%ROOT%', "config", ROOT_CONF), "--verbose"],
|
|
|
|
}
|
|
|
|
|
2012-01-13 19:04:26 -08:00
|
|
|
|
2012-01-13 18:39:05 -08:00
|
|
|
class KeystoneUninstaller(PythonUninstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-13 18:39:05 -08:00
|
|
|
PythonUninstallComponent.__init__(self, TYPE, *args, **kargs)
|
2012-01-13 12:07:41 -08:00
|
|
|
self.cfgdir = joinpths(self.appdir, CONFIG_DIR)
|
2012-01-11 12:47:33 -08:00
|
|
|
self.bindir = joinpths(self.appdir, BIN_DIR)
|
|
|
|
|
2012-01-13 19:04:26 -08:00
|
|
|
|
2012-01-13 18:39:05 -08:00
|
|
|
class KeystoneInstaller(PythonInstallComponent):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-13 18:39:05 -08:00
|
|
|
PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
|
2012-01-11 12:47:33 -08:00
|
|
|
self.gitloc = self.cfg.get("git", "keystone_repo")
|
|
|
|
self.brch = self.cfg.get("git", "keystone_branch")
|
2012-01-13 18:39:05 -08:00
|
|
|
self.cfgdir = joinpths(self.appdir, CONFIG_DIR)
|
|
|
|
self.bindir = joinpths(self.appdir, BIN_DIR)
|
2012-01-11 12:47:33 -08:00
|
|
|
|
2012-01-13 18:39:05 -08:00
|
|
|
def _get_download_location(self):
|
2012-01-17 17:04:51 -08:00
|
|
|
return (self.gitloc, self.brch)
|
2012-01-12 20:30:48 -08:00
|
|
|
|
2012-01-18 13:51:51 -08:00
|
|
|
def post_install(self):
|
|
|
|
parent_result = 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-12 17:35:41 -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-13 19:04:26 -08:00
|
|
|
params = self._get_param_map()
|
2012-01-12 23:42:25 -08:00
|
|
|
cmds = _keystone_setup_cmds(self.othercomponents)
|
2012-01-12 20:35:25 -08:00
|
|
|
execute_template(*cmds, params=params, ignore_missing=True)
|
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
|
|
|
|
#use config parser and
|
|
|
|
#then extract known configs that
|
|
|
|
#will need locations/directories/files made (or touched)...
|
|
|
|
with io.BytesIO(contents) as stream:
|
|
|
|
config = Config.IgnoreMissingConfigParser()
|
|
|
|
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))
|
|
|
|
log_dir = os.path.dirname(log_filename)
|
|
|
|
if(log_dir):
|
|
|
|
LOG.info("Ensuring log directory %s exists" % (log_dir))
|
|
|
|
dirsmade = mkdirslist(log_dir)
|
|
|
|
#this trace is used to remove the dirs created
|
2012-01-11 12:47:33 -08:00
|
|
|
self.tracewriter.dir_made(*dirsmade)
|
2012-01-18 13:51:51 -08:00
|
|
|
#destroy then recreate it (the log file)
|
|
|
|
unlink(log_filename)
|
|
|
|
touch_file(log_filename)
|
|
|
|
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-13 18:39:05 -08:00
|
|
|
def _get_param_map(self, fn=None):
|
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()
|
|
|
|
mp['DEST'] = self.appdir
|
2012-01-17 15:24:57 -08:00
|
|
|
mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME)
|
2012-01-12 17:35:41 -08:00
|
|
|
mp['ADMIN_PASSWORD'] = self.cfg.getpw('passwords', 'horizon_keystone_admin')
|
2012-01-13 12:07:41 -08:00
|
|
|
mp['HOST_IP'] = get_host_ip(self.cfg)
|
|
|
|
mp['SERVICE_TOKEN'] = self.cfg.getpw("passwords", "service_token")
|
|
|
|
mp['BIN_DIR'] = self.bindir
|
2012-01-13 15:08:48 -08:00
|
|
|
mp['CONFIG_FILE'] = joinpths(self.cfgdir, ROOT_CONF)
|
2012-01-11 12:47:33 -08:00
|
|
|
return mp
|
|
|
|
|
|
|
|
|
2012-01-17 15:24:57 -08:00
|
|
|
class KeystoneRuntime(PythonRuntime):
|
2012-01-11 12:47:33 -08:00
|
|
|
def __init__(self, *args, **kargs):
|
2012-01-17 15:24:57 -08:00
|
|
|
PythonRuntime.__init__(self, TYPE, *args, **kargs)
|
2012-01-13 18:39:05 -08:00
|
|
|
self.cfgdir = joinpths(self.appdir, CONFIG_DIR)
|
|
|
|
self.bindir = 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):
|
|
|
|
return sorted(APP_OPTIONS.keys())
|
|
|
|
|
|
|
|
def _get_app_options(self, app):
|
|
|
|
return APP_OPTIONS.get(app)
|
|
|
|
|
2012-01-12 23:42:25 -08:00
|
|
|
|
|
|
|
# Keystone setup commands are the the following
|
|
|
|
def _keystone_setup_cmds(components):
|
|
|
|
|
|
|
|
# See http://keystone.openstack.org/man/keystone-manage.html
|
|
|
|
|
2012-01-13 15:08:48 -08:00
|
|
|
root_cmd = ["%BIN_DIR%/keystone-manage", '--config-file=%CONFIG_FILE%']
|
|
|
|
|
2012-01-12 23:42:25 -08:00
|
|
|
# Tenants
|
|
|
|
tenant_cmds = [
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["tenant", "add", "admin"],
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["tenant", "add", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["tenant", "add", "invisible_to_admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
# Users
|
|
|
|
user_cmds = [
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["user", "add", "admin", "%ADMIN_PASSWORD%"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["user", "add", "demo", "%ADMIN_PASSWORD%"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
# Roles
|
|
|
|
role_cmds = [
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "Admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-17 17:32:13 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "Member"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "KeystoneAdmin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "KeystoneServiceAdmin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "sysadmin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "add", "netadmin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "Admin", "admin", "admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "Member", "demo", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "sysadmin", "demo", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "netadmin", "demo", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "Member", "demo", "invisible_to_admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "Admin", "admin", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "Admin", "admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "KeystoneAdmin", "admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["role", "grant", "KeystoneServiceAdmin", "admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
# Services
|
|
|
|
services = []
|
|
|
|
services.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["service", "add", "keystone", "identity", "Keystone Identity Service"]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(NOVA in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
services.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["service", "add", "nova", "compute", "Nova Compute Service"]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
services.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["service", "add", "ec2", "ec2", "EC2 Compatability Layer"]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(GLANCE in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
services.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["service", "add", "glance", "image", "Glance Image Service"]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(SWIFT in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
services.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["service", "add", "swift", "object-store", "Swift Service"]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
# Endpoint templates
|
|
|
|
endpoint_templates = list()
|
|
|
|
endpoint_templates.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["endpointTemplates", "add",
|
2012-01-12 23:42:25 -08:00
|
|
|
"RegionOne", "keystone",
|
|
|
|
"http://%HOST_IP%:5000/v2.0",
|
|
|
|
"http://%HOST_IP%:35357/v2.0",
|
|
|
|
"http://%HOST_IP%:5000/v2.0",
|
|
|
|
"1",
|
|
|
|
"1"
|
2012-01-13 15:08:48 -08:00
|
|
|
]
|
2012-01-12 23:42:25 -08:00
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(NOVA in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
endpoint_templates.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["endpointTemplates", "add",
|
2012-01-12 23:42:25 -08:00
|
|
|
"RegionOne", "nova",
|
|
|
|
"http://%HOST_IP%:8774/v1.1/%tenant_id%",
|
|
|
|
"http://%HOST_IP%:8774/v1.1/%tenant_id%",
|
|
|
|
"http://%HOST_IP%:8774/v1.1/%tenant_id%",
|
|
|
|
"1",
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
endpoint_templates.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["endpointTemplates", "add",
|
2012-01-12 23:42:25 -08:00
|
|
|
"RegionOne", "ec2",
|
|
|
|
"http://%HOST_IP%:8773/services/Cloud",
|
|
|
|
"http://%HOST_IP%:8773/services/Admin",
|
|
|
|
"http://%HOST_IP%:8773/services/Cloud",
|
|
|
|
"1",
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(GLANCE in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
endpoint_templates.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["endpointTemplates", "add",
|
2012-01-12 23:42:25 -08:00
|
|
|
"RegionOne", "glance",
|
|
|
|
"http://%HOST_IP%:9292/v1.1/%tenant_id%",
|
|
|
|
"http://%HOST_IP%:9292/v1.1/%tenant_id%",
|
|
|
|
"http://%HOST_IP%:9292/v1.1/%tenant_id%",
|
|
|
|
"1",
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2012-01-13 12:07:41 -08:00
|
|
|
if(SWIFT in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
endpoint_templates.append({
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["endpointTemplates", "add",
|
2012-01-12 23:42:25 -08:00
|
|
|
"RegionOne", "swift",
|
|
|
|
"http://%HOST_IP%:8080/v1/AUTH_%tenant_id%",
|
|
|
|
"http://%HOST_IP%:8080/",
|
|
|
|
"http://%HOST_IP%:8080/v1/AUTH_%tenant_id%",
|
|
|
|
"1",
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
# Tokens
|
|
|
|
tokens = [
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["token", "add", "%SERVICE_TOKEN%", "admin", "admin", "2015-02-05T00:00"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
# EC2 related creds - note we are setting the secret key to ADMIN_PASSWORD
|
|
|
|
# but keystone doesn't parse them - it is just a blob from keystone's
|
|
|
|
# point of view
|
|
|
|
ec2_creds = []
|
2012-01-13 12:07:41 -08:00
|
|
|
if(NOVA in components):
|
2012-01-12 23:42:25 -08:00
|
|
|
ec2_creds = [
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["credentials", "add",
|
2012-01-13 19:04:26 -08:00
|
|
|
"admin", "EC2", "admin", "%ADMIN_PASSWORD%", "admin"]
|
2012-01-12 23:42:25 -08:00
|
|
|
},
|
|
|
|
{
|
2012-01-13 15:08:48 -08:00
|
|
|
"cmd": root_cmd + ["credentials", "add",
|
|
|
|
"demo", "EC2", "demo", "%ADMIN_PASSWORD%", "demo"]
|
2012-01-12 23:42:25 -08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2012-01-13 15:08:48 -08:00
|
|
|
# Order matters here...
|
2012-01-13 19:04:26 -08:00
|
|
|
all_cmds = tenant_cmds + user_cmds + role_cmds + services + endpoint_templates + tokens + ec2_creds
|
2012-01-12 23:42:25 -08:00
|
|
|
return all_cmds
|