]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Advanced services support in neutron-db-manage
authorBrandon Logan <brandon.logan@rackspace.com>
Wed, 10 Dec 2014 00:22:27 +0000 (18:22 -0600)
committerBrandon Logan <brandon.logan@rackspace.com>
Tue, 16 Dec 2014 17:02:11 +0000 (09:02 -0800)
Partially-Implements: blueprint services-split

Change-Id: Ib8cd77e5e777be83c44b69edc0a6d2d2ba5d2ab1

neutron/db/migration/cli.py

index 96a0da705d08d324b41fb6d3717f62ea0cdbe3fa..d3eef00b36fe8959000b94afea8b9b0d272dda95 100644 (file)
@@ -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)