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 = [
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 = [
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)