d3490339df
Sync the following changes from oslo-incubator: 479f19c Add deprecated --logdir common opt 27b2ff4 Add deprecated --logfile common opt. 9b81289 Allow nova and others to override some logging defaults 3557d84 Fix ListOpt to trim whitespace 01ab910 Fix set_default() with boolean CLI options af18eaa Improve cfg's argparse sub-parsers support f21e1d9 Fix regression with cfg CLI arguments ceb4aa7 Fix broken --help with CommonConfigOpts 5e9503b Hide the GroupAttr conf and group attributes b6d24bb updating sphinx documentation 403509e Don't reference argparse._StoreAction e17deb8 Fix minor coding style issue 0c29e1d Remove ConfigCliParser class 5b9cb41 Add support for positional arguments dbc72a6 Use stock argparse behaviour for optional args 768a147 Use stock argparse --usage behaviour ac180b9 Use stock argparse --version behaviour 0787e38 Remove add_option() method 5afead0 Completely remove cfg's disable_interspersed_args() 5f564b2 argparse support for cfg d7b6397 Add a missing comma in a docstring. aca1805 cfg: fix required if option has a dash Changing glance-manage to use argparse sub-parsers does result in an incompatible change. This no longer works: $> glance-manage db_sync --config-file=... because --config-file is interpreted as an argument to the db_sync command rather than a global argument. Instead you now have to do: $> glance-manage --config-file=... db_sync The incompatibility is unfortunate, but the new behaviour is pretty standard. Change-Id: Ifd43fe6bea4abd7f85ea75e5ae65678b679acd8d
133 lines
4.2 KiB
Python
Executable File
133 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2010 United States Government as represented by the
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
# Copyright 2011 OpenStack LLC.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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.
|
|
|
|
"""
|
|
Glance Management Utility
|
|
"""
|
|
|
|
# FIXME(sirp): When we have glance-admin we can consider merging this into it
|
|
# Perhaps for consistency with Nova, we would then rename glance-admin ->
|
|
# glance-manage (or the other way around)
|
|
|
|
import gettext
|
|
import os
|
|
import sys
|
|
|
|
# If ../glance/__init__.py exists, add ../ to Python search path, so that
|
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
|
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
|
os.pardir,
|
|
os.pardir))
|
|
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
|
|
sys.path.insert(0, possible_topdir)
|
|
|
|
gettext.install('glance', unicode=1)
|
|
|
|
from glance.common import config
|
|
from glance.common import exception
|
|
from glance.openstack.common import cfg
|
|
import glance.db.sqlalchemy.api
|
|
import glance.db.sqlalchemy.migration
|
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
def do_db_version():
|
|
"""Print database's current migration level"""
|
|
print glance.db.sqlalchemy.migration.db_version()
|
|
|
|
|
|
def do_upgrade():
|
|
"""Upgrade the database's migration level"""
|
|
glance.db.sqlalchemy.migration.upgrade(CONF.command.version)
|
|
|
|
|
|
def do_downgrade():
|
|
"""Downgrade the database's migration level"""
|
|
glance.db.sqlalchemy.migration.downgrade(CONF.command.version)
|
|
|
|
|
|
def do_version_control():
|
|
"""Place a database under migration control"""
|
|
glance.db.sqlalchemy.migration.version_control(CONF.command.version)
|
|
|
|
|
|
def do_db_sync():
|
|
"""
|
|
Place a database under migration control and upgrade,
|
|
creating first if necessary.
|
|
"""
|
|
glance.db.sqlalchemy.migration.db_sync(CONF.command.version,
|
|
CONF.command.current_version)
|
|
|
|
|
|
def add_command_parsers(subparsers):
|
|
parser = subparsers.add_parser('db_version')
|
|
parser.set_defaults(func=do_db_version)
|
|
|
|
parser = subparsers.add_parser('upgrade')
|
|
parser.set_defaults(func=do_upgrade)
|
|
parser.add_argument('version', nargs='?')
|
|
|
|
parser = subparsers.add_parser('downgrade')
|
|
parser.set_defaults(func=do_downgrade)
|
|
parser.add_argument('version')
|
|
|
|
parser = subparsers.add_parser('version_control')
|
|
parser.set_defaults(func=do_version_control)
|
|
parser.add_argument('version', nargs='?')
|
|
|
|
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='Available commands',
|
|
handler=add_command_parsers)
|
|
|
|
|
|
def main():
|
|
CONF.register_cli_opt(command_opt)
|
|
try:
|
|
# We load the glance-registry config section because
|
|
# sql_connection is only part of the glance registry.
|
|
glance.db.add_cli_options()
|
|
|
|
default_cfg_files = cfg.find_config_files(project='glance',
|
|
prog='glance-registry')
|
|
|
|
config.parse_args(default_config_files=default_cfg_files,
|
|
usage="%(prog)s [options] <cmd>")
|
|
config.setup_logging()
|
|
except RuntimeError, e:
|
|
sys.exit("ERROR: %s" % e)
|
|
|
|
try:
|
|
CONF.command.func()
|
|
except exception.GlanceException, e:
|
|
sys.exit("ERROR: %s" % e)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|