From: Brandon Logan Date: Wed, 10 Dec 2014 00:22:27 +0000 (-0600) Subject: Advanced services support in neutron-db-manage X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1abcead6040df1db87862c2383a145c41705906d;p=openstack-build%2Fneutron-build.git Advanced services support in neutron-db-manage Partially-Implements: blueprint services-split Change-Id: Ib8cd77e5e777be83c44b69edc0a6d2d2ba5d2ab1 --- diff --git a/neutron/db/migration/cli.py b/neutron/db/migration/cli.py index 96a0da705..d3eef00b3 100644 --- a/neutron/db/migration/cli.py +++ b/neutron/db/migration/cli.py @@ -19,9 +19,14 @@ from alembic import config as alembic_config from alembic import script as alembic_script from alembic import util as alembic_util from oslo.config import cfg +from oslo.utils import importutils HEAD_FILENAME = 'HEAD' +LBAAS_SERVICE = 'lbaas' +FWAAS_SERVICE = 'fwaas' +VPNAAS_SERVICE = 'vpnaas' +VALID_SERVICES = (LBAAS_SERVICE, FWAAS_SERVICE, VPNAAS_SERVICE) _core_opts = [ @@ -31,6 +36,10 @@ _core_opts = [ cfg.ListOpt('service_plugins', default=[], help=_("The service plugins Neutron will use")), + cfg.StrOpt('service', + choices=VALID_SERVICES, + help=_("The advanced service to execute the command against. " + "Can be one of '%s'.") % "', '".join(VALID_SERVICES)) ] _quota_opts = [ @@ -159,19 +168,32 @@ command_opt = cfg.SubCommandOpt('command', CONF.register_cli_opt(command_opt) +def validate_service_installed(service): + if not importutils.try_import('neutron_%s' % service): + alembic_util.err(_('Package neutron-%s not installed') % service) + + +def get_script_location(neutron_config): + location = '%s.db.migration:alembic_migrations' + if neutron_config.service: + validate_service_installed(neutron_config.service) + base = "neutron_%s" % neutron_config.service + else: + base = "neutron" + return location % base + + def get_alembic_config(): config = alembic_config.Config(os.path.join(os.path.dirname(__file__), 'alembic.ini')) - config.set_main_option('script_location', - 'neutron.db.migration:alembic_migrations') + config.set_main_option('script_location', get_script_location(CONF)) return config def main(): + CONF(project='neutron') config = get_alembic_config() - # attach the Neutron conf to the Alembic conf config.neutron_config = CONF - CONF(project='neutron') #TODO(gongysh) enable logging CONF.command.func(config, CONF.command.name)