have horizon use mysql instead of sqlite
This commit is contained in:
parent
524d2a736d
commit
4c94178ee9
@ -11,12 +11,15 @@ USE_SSL = False
|
||||
|
||||
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# FIXME: We need to change this to mysql, instead of sqlite.
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(LOCAL_PATH, 'dashboard_openstack.sqlite3'),
|
||||
'TEST_NAME': os.path.join(LOCAL_PATH, 'test.sqlite3'),
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': '%DB_NAME%',
|
||||
'USER': '%DB_USER%',
|
||||
'PASSWORD': '%DB_PASSWORD%',
|
||||
'HOST': '%DB_HOST%',
|
||||
'PORT': %DB_PORT%,
|
||||
'TEST_NAME': '%DB_NAME%test',
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -144,19 +144,31 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
"set by a previous process."))
|
||||
|
||||
# Ensure access granted
|
||||
if dbactions:
|
||||
grant_cmd = self.distro.get_command(dbtype, 'grant_all')
|
||||
if grant_cmd:
|
||||
user = self.cfg.getdefaulted("db", "sql_user", 'root')
|
||||
LOG.info("Updating the DB to give user %r full control of all databases." % (user))
|
||||
LOG.info("Ensuring your database is started before we operate on it.")
|
||||
self.runtime.restart()
|
||||
grant_permissions(self.cfg, self.pw_gen, self.distro, user, restart_func=self.runtime.restart)
|
||||
|
||||
|
||||
def grant_permissions(cfg, pw_gen, distro, user, restart_func=None):
|
||||
"""Grant permissions on the database.
|
||||
"""
|
||||
dbtype = cfg.get("db", "type")
|
||||
dbactions = distro.get_command_config(dbtype, quiet=True)
|
||||
if dbactions:
|
||||
grant_cmd = distro.get_command(dbtype, 'grant_all')
|
||||
if grant_cmd:
|
||||
if restart_func:
|
||||
LOG.info("Ensuring the database is started")
|
||||
restart_func()
|
||||
params = {
|
||||
'PASSWORD': self.pw_gen.get_password("sql", PASSWORD_PROMPT),
|
||||
'PASSWORD': pw_gen.get_password("sql", PASSWORD_PROMPT),
|
||||
'USER': user,
|
||||
}
|
||||
cmds = [{'cmd': grant_cmd}]
|
||||
LOG.info(
|
||||
"Giving user %r full control of all databases.",
|
||||
user)
|
||||
utils.execute_template(*cmds, params=params)
|
||||
return
|
||||
|
||||
|
||||
class DBRuntime(comp.EmptyRuntime):
|
||||
@ -248,6 +260,7 @@ def create_db(cfg, pw_gen, distro, dbname, utf8=False):
|
||||
else:
|
||||
createcmd = distro.get_command(dbtype, 'create_db_utf8', silent=True)
|
||||
if createcmd:
|
||||
LOG.debug('Creating %s database %s', dbtype, dbname)
|
||||
params = dict()
|
||||
params['PASSWORD'] = pw_gen.get_password("sql", PASSWORD_PROMPT)
|
||||
params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')
|
||||
|
@ -20,6 +20,8 @@ from devstack import log as logging
|
||||
from devstack import shell as sh
|
||||
from devstack import utils
|
||||
|
||||
from devstack.components import db
|
||||
|
||||
LOG = logging.getLogger("devstack.components.horizon")
|
||||
|
||||
# Actual dir names
|
||||
@ -53,6 +55,8 @@ BAD_APACHE_USERS = ['root']
|
||||
# Apache logs will go here
|
||||
LOGS_DIR = "logs"
|
||||
|
||||
DB_NAME = 'horizon'
|
||||
|
||||
|
||||
class HorizonUninstaller(comp.PythonUninstallComponent):
|
||||
def __init__(self, *args, **kargs):
|
||||
@ -122,16 +126,13 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
LOG.info("Initializing the horizon database.")
|
||||
sh.execute(*DB_SYNC_CMD, cwd=self.app_dir)
|
||||
|
||||
def _ensure_db_access(self):
|
||||
# Need db access:
|
||||
# openstack-dashboard/local needs to be writeable by the runtime user
|
||||
# since currently its storing the sql-lite databases there (TODO fix that)
|
||||
path = sh.joinpths(self.dash_dir, 'local')
|
||||
if sh.isdir(path):
|
||||
(user, group) = self._get_apache_user_group()
|
||||
LOG.debug("Changing ownership (recursively) of %r so that it can be used by %r/%r",
|
||||
path, group, user)
|
||||
sh.chown_r(path, sh.getuid(user), sh.getgid(group))
|
||||
def _setup_db(self):
|
||||
LOG.info("Fixing up database named %r", DB_NAME)
|
||||
db.drop_db(self.cfg, self.pw_gen, self.distro, DB_NAME)
|
||||
db.create_db(self.cfg, self.pw_gen, self.distro, DB_NAME, utf8=True)
|
||||
# db.grant_permissions(self.cfg, self.pw_gen, self.distro,
|
||||
# self.cfg.getdefaulted('db', 'sql_user', 'root')
|
||||
# )
|
||||
|
||||
def pre_install(self):
|
||||
comp.PythonInstallComponent.pre_install(self)
|
||||
@ -142,9 +143,9 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
|
||||
def post_install(self):
|
||||
comp.PythonInstallComponent.post_install(self)
|
||||
self._setup_db()
|
||||
self._sync_db()
|
||||
self._setup_blackhole()
|
||||
self._ensure_db_access()
|
||||
self._config_fixups()
|
||||
|
||||
def _get_apache_user_group(self):
|
||||
@ -167,6 +168,11 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
mp['VPN_DIR'] = sh.joinpths(self.app_dir, "vpn")
|
||||
else:
|
||||
mp['OPENSTACK_HOST'] = self.cfg.get('host', 'ip')
|
||||
mp['DB_NAME'] = DB_NAME
|
||||
mp['DB_USER'] = self.cfg.getdefaulted('db', 'sql_user', 'root')
|
||||
mp['DB_PASSWORD'] = self.pw_gen.get_password('sql', db.PASSWORD_PROMPT)
|
||||
mp['DB_HOST'] = self.cfg.get("db", "sql_host")
|
||||
mp['DB_PORT'] = self.cfg.get("db", "port")
|
||||
return mp
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user