Added explicit db-sync command
This patch changes the way we initialize the DB with tables: * there is new command - 'murano-manage db_sync' * DB is no longer automatically populated Change-Id: I1ae06448ddf4a832740e9a2bfccbfd725cb6c3f7
This commit is contained in:
parent
d591d98b5e
commit
17afc0e0fd
@ -133,8 +133,7 @@ function init_murano() {
|
|||||||
# (re)create Murano database
|
# (re)create Murano database
|
||||||
recreate_database murano utf8
|
recreate_database murano utf8
|
||||||
|
|
||||||
# TODO(ruhe): run DB migration script. it doesn't exist yet!!!
|
$MURANO_BIN_DIR/murano-manage --config-file $MURANO_CONF_FILE db_sync
|
||||||
# $MURANO_BIN_DIR/murano-db-manage --config-file $MURANO_CONF_FILE upgrade head
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
65
muranoapi/cmd/manage.py
Normal file
65
muranoapi/cmd/manage.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Copyright (c) 2014 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""
|
||||||
|
CLI interface for murano management.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
import muranoapi
|
||||||
|
from muranoapi.db import session as db_session
|
||||||
|
from muranoapi.openstack.common import log
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
|
def do_db_sync():
|
||||||
|
"""
|
||||||
|
Place a database under migration control and upgrade,
|
||||||
|
creating first if necessary.
|
||||||
|
"""
|
||||||
|
db_session.db_sync()
|
||||||
|
|
||||||
|
|
||||||
|
def add_command_parsers(subparsers):
|
||||||
|
parser = subparsers.add_parser('db_sync')
|
||||||
|
parser.set_defaults(func=do_db_sync)
|
||||||
|
parser.add_argument('version', nargs='?')
|
||||||
|
parser.add_argument('current_version', nargs='?')
|
||||||
|
|
||||||
|
command_opt = cfg.SubCommandOpt('command',
|
||||||
|
title='Commands',
|
||||||
|
help='Show available commands.',
|
||||||
|
handler=add_command_parsers)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
CONF.register_cli_opt(command_opt)
|
||||||
|
try:
|
||||||
|
default_config_files = cfg.find_config_files('murano-api', 'murano')
|
||||||
|
CONF(sys.argv[1:], project='murano-api', prog='murano-manage',
|
||||||
|
version=muranoapi.__version__,
|
||||||
|
default_config_files=default_config_files)
|
||||||
|
log.setup("murano-api")
|
||||||
|
except RuntimeError as e:
|
||||||
|
sys.exit("ERROR: %s" % e)
|
||||||
|
|
||||||
|
try:
|
||||||
|
CONF.command.func()
|
||||||
|
except Exception as e:
|
||||||
|
sys.exit("ERROR: %s" % e)
|
@ -1,10 +1,4 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# Copyright (c) 2014 Mirantis, Inc.
|
||||||
|
|
||||||
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
|
|
||||||
# Copyright 2010 United States Government as represented by the
|
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
|
||||||
# Copyright 2011 Piston Cloud Computing, Inc.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
@ -17,6 +11,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
"""Session management functions."""
|
"""Session management functions."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -27,34 +22,10 @@ from migrate.versioning import api as versioning_api
|
|||||||
from muranoapi.common import config
|
from muranoapi.common import config
|
||||||
from muranoapi.db import migrate_repo
|
from muranoapi.db import migrate_repo
|
||||||
from muranoapi.openstack.common.db.sqlalchemy import session as db_session
|
from muranoapi.openstack.common.db.sqlalchemy import session as db_session
|
||||||
from muranoapi.openstack.common.gettextutils import _ # noqa
|
|
||||||
from muranoapi.openstack.common import log as logging
|
from muranoapi.openstack.common import log as logging
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
CONF = config.CONF
|
CONF = config.CONF
|
||||||
|
|
||||||
|
|
||||||
def get_session(autocommit=True, expire_on_commit=False):
|
|
||||||
s = _create_facade_lazily().get_session(autocommit=autocommit,
|
|
||||||
expire_on_commit=expire_on_commit)
|
|
||||||
if s:
|
|
||||||
if CONF.database.auto_create:
|
|
||||||
LOG.info(_('auto-creating DB'))
|
|
||||||
_auto_create_db()
|
|
||||||
else:
|
|
||||||
LOG.info(_('not auto-creating DB'))
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def _auto_create_db():
|
|
||||||
repo_path = os.path.abspath(os.path.dirname(migrate_repo.__file__))
|
|
||||||
try:
|
|
||||||
versioning_api.upgrade(CONF.database.connection, repo_path)
|
|
||||||
except versioning_exceptions.DatabaseNotControlledError:
|
|
||||||
versioning_api.version_control(CONF.database.connection, repo_path)
|
|
||||||
versioning_api.upgrade(CONF.database.connection, repo_path)
|
|
||||||
|
|
||||||
|
|
||||||
_FACADE = None
|
_FACADE = None
|
||||||
|
|
||||||
|
|
||||||
@ -67,3 +38,18 @@ def _create_facade_lazily():
|
|||||||
**dict(CONF.database.iteritems())
|
**dict(CONF.database.iteritems())
|
||||||
)
|
)
|
||||||
return _FACADE
|
return _FACADE
|
||||||
|
|
||||||
|
|
||||||
|
def get_session(autocommit=True, expire_on_commit=False):
|
||||||
|
s = _create_facade_lazily().get_session(autocommit=autocommit,
|
||||||
|
expire_on_commit=expire_on_commit)
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def db_sync():
|
||||||
|
repo_path = os.path.abspath(os.path.dirname(migrate_repo.__file__))
|
||||||
|
try:
|
||||||
|
versioning_api.upgrade(CONF.database.connection, repo_path)
|
||||||
|
except versioning_exceptions.DatabaseNotControlledError:
|
||||||
|
versioning_api.version_control(CONF.database.connection, repo_path)
|
||||||
|
versioning_api.upgrade(CONF.database.connection, repo_path)
|
||||||
|
@ -44,6 +44,7 @@ setup-hooks =
|
|||||||
console_scripts =
|
console_scripts =
|
||||||
murano-api = muranoapi.cmd.api:main
|
murano-api = muranoapi.cmd.api:main
|
||||||
murano-engine = muranoapi.cmd.engine:main
|
murano-engine = muranoapi.cmd.engine:main
|
||||||
|
murano-manage = muranoapi.cmd.manage:main
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
all_files = 1
|
all_files = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user