blazar/climate/db/migration/cli.py
Nikolaj Starodubtsev bc8cfb861b Implement climate db api
And make sqlalchemy implementation

Change-Id: I2f52b4ebd4bc5937e45c34c78f56864f3e91b7ae
2013-09-26 21:30:53 +04:00

52 lines
1.3 KiB
Python

# Copyright (c) 2013 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.
from oslo.config import cfg
from climate.db import api as db_api
CONF = cfg.CONF
def map_status(status):
return 'Success' if status else 'Fail'
def db_sync():
drop_status = db_api.drop_db()
print("Dropping database: %s" % map_status(drop_status))
start_status = db_api.setup_db()
print("Creating database: %s" % map_status(start_status))
def add_command_parsers(subparsers):
parser = subparsers.add_parser('db-sync')
parser.set_defaults(func=db_sync)
command_opt = cfg.SubCommandOpt('command',
title='Command',
help='Available commands',
handler=add_command_parsers)
CONF.register_cli_opt(command_opt)
def main():
CONF()
CONF.command.func()