Exemplo n.º 1
0
def get_extensions_path():
    paths = neutron.extensions.__path__

    neutron_mods = repos.NeutronModules()
    for x in neutron_mods.installed_list():
        try:
            paths += neutron_mods.module(x).extensions.__path__
        except AttributeError:
            # Occurs normally if module has no extensions sub-module
            pass

    if cfg.CONF.api_extensions_path:
        paths.append(cfg.CONF.api_extensions_path)

    # If the path has dups in it, from discovery + conf file, the duplicate
    # import of the same module and super() do not play nicely, so weed
    # out the duplicates, preserving search order.

    z = collections.OrderedDict()
    for x in paths:
        z[x] = 1
    paths = z.keys()

    LOG.debug("get_extension_paths = %s", paths)

    path = ':'.join(paths)
    return path
def parse_service_provider_opt():
    """Parse service definition opts and returns result."""
    def validate_name(name):
        if len(name) > 255:
            raise n_exc.Invalid(
                _("Provider name is limited by 255 characters: %s") % name)

    # Main neutron config file
    try:
        svc_providers_opt = cfg.CONF.service_providers.service_provider
    except cfg.NoSuchOptError:
        svc_providers_opt = []

    # Add in entries from the *aas conf files
    neutron_mods = repos.NeutronModules()
    for x in neutron_mods.installed_list():
        svc_providers_opt += neutron_mods.service_providers(x)

    LOG.debug("Service providers = %s", svc_providers_opt)

    res = []
    for prov_def in svc_providers_opt:
        split = prov_def.split(':')
        try:
            svc_type, name, driver = split[:3]
        except ValueError:
            raise n_exc.Invalid(_("Invalid service provider format"))
        validate_name(name)
        name = normalize_provider_name(name)
        default = False
        if len(split) == 4 and split[3]:
            if split[3] == 'default':
                default = True
            else:
                msg = (_("Invalid provider format. "
                         "Last part should be 'default' or empty: %s") %
                       prov_def)
                LOG.error(msg)
                raise n_exc.Invalid(msg)
        if svc_type not in constants.ALLOWED_SERVICES:
            msg = (_("Service type '%(svc_type)s' is not allowed, "
                     "allowed types: %(allowed)s") % {
                         'svc_type': svc_type,
                         'allowed': constants.ALLOWED_SERVICES
                     })
            LOG.error(msg)
            raise n_exc.Invalid(msg)
        driver = get_provider_driver_class(driver)
        res.append({
            'service_type': svc_type,
            'name': name,
            'driver': driver,
            'default': default
        })
    return res
Exemplo n.º 3
0
def get_extensions_path():
    paths = neutron.extensions.__path__

    neutron_mods = repos.NeutronModules()
    for x in neutron_mods.installed_list():
        try:
            paths += neutron_mods.module(x).extensions.__path__
        except AttributeError:
            # Occurs normally if module has no extensions sub-module
            pass

    if cfg.CONF.api_extensions_path:
        paths.append(cfg.CONF.api_extensions_path)

    LOG.debug("get_extension_paths = %s", paths)

    path = ':'.join(paths)
    return path
def parse_service_provider_opt():
    """Parse service definition opts and returns result."""
    def validate_name(name):
        if len(name) > 255:
            raise n_exc.Invalid(
                _("Provider name is limited by 255 characters: %s") % name)

    # TODO(dougwig) - phase out the neutron.conf location for service
    # providers a cycle or two after Kilo.

    # Look in neutron.conf for service providers first (legacy mode)
    try:
        svc_providers_opt = cfg.CONF.service_providers.service_provider
    except cfg.NoSuchOptError:
        svc_providers_opt = []

    # Look in neutron-*aas.conf files for service provider configs
    if svc_providers_opt:
        LOG.warning(
            _LW("Reading service_providers from legacy location in "
                "neutron.conf, and ignoring values in "
                "neutron_*aas.conf files; this override will be "
                "going away soon."))
    else:
        neutron_mods = repos.NeutronModules()
        for x in neutron_mods.installed_list():
            svc_providers_opt += neutron_mods.service_providers(x)

    LOG.debug("Service providers = %s", svc_providers_opt)

    res = []
    for prov_def in svc_providers_opt:
        split = prov_def.split(':')
        try:
            svc_type, name, driver = split[:3]
        except ValueError:
            raise n_exc.Invalid(_("Invalid service provider format"))
        validate_name(name)
        name = normalize_provider_name(name)
        default = False
        if len(split) == 4 and split[3]:
            if split[3] == 'default':
                default = True
            else:
                msg = (_("Invalid provider format. "
                         "Last part should be 'default' or empty: %s") %
                       prov_def)
                LOG.error(msg)
                raise n_exc.Invalid(msg)
        if svc_type not in constants.ALLOWED_SERVICES:
            msg = (_("Service type '%(svc_type)s' is not allowed, "
                     "allowed types: %(allowed)s") % {
                         'svc_type': svc_type,
                         'allowed': constants.ALLOWED_SERVICES
                     })
            LOG.error(msg)
            raise n_exc.Invalid(msg)
        driver = get_provider_driver_class(driver)
        res.append({
            'service_type': svc_type,
            'name': name,
            'driver': driver,
            'default': default
        })
    return res
Exemplo n.º 5
0
def parse_service_provider_opt():
    """Parse service definition opts and returns result."""
    def validate_name(name):
        if len(name) > 255:
            raise n_exc.Invalid(
                _("Provider name is limited by 255 characters: %s") % name)

    # Main neutron config file
    try:
        svc_providers_opt = cfg.CONF.service_providers.service_provider
    except cfg.NoSuchOptError:
        svc_providers_opt = []

    # Add in entries from the *aas conf files
    neutron_mods = repos.NeutronModules()
    for x in neutron_mods.installed_list():
        ini = neutron_mods.ini(x)
        if ini is None:
            continue

        try:
            sp = ini.items('service_providers')
            for name, value in sp:
                if name == 'service_provider':
                    svc_providers_opt.append(value)
        except Exception:
            continue

    # TODO(dougwig) - remove this next bit after we've migrated all entries
    # to the service repo config files. Some tests require a default driver
    # to be present, but not two, which leads to a cross-repo breakage
    # issue.  uniq the list as a short-term workaround.
    svc_providers_opt = list(set(svc_providers_opt))

    LOG.debug("Service providers = %s", svc_providers_opt)

    res = []
    for prov_def in svc_providers_opt:
        split = prov_def.split(':')
        try:
            svc_type, name, driver = split[:3]
        except ValueError:
            raise n_exc.Invalid(_("Invalid service provider format"))
        validate_name(name)
        name = normalize_provider_name(name)
        default = False
        if len(split) == 4 and split[3]:
            if split[3] == 'default':
                default = True
            else:
                msg = (_("Invalid provider format. "
                         "Last part should be 'default' or empty: %s") %
                       prov_def)
                LOG.error(msg)
                raise n_exc.Invalid(msg)
        if svc_type not in constants.ALLOWED_SERVICES:
            msg = (_("Service type '%(svc_type)s' is not allowed, "
                     "allowed types: %(allowed)s") % {
                         'svc_type': svc_type,
                         'allowed': constants.ALLOWED_SERVICES
                     })
            LOG.error(msg)
            raise n_exc.Invalid(msg)
        driver = get_provider_driver_class(driver)
        res.append({
            'service_type': svc_type,
            'name': name,
            'driver': driver,
            'default': default
        })
    return res
Exemplo n.º 6
0
from alembic import environment
from alembic import script as alembic_script
from alembic import util as alembic_util
from oslo_config import cfg
from oslo_utils import importutils

from neutron.common import repos
from neutron.common import utils

# TODO(ihrachyshka): maintain separate HEAD files per branch
HEAD_FILENAME = 'HEAD'
HEADS_FILENAME = 'HEADS'
CURRENT_RELEASE = "liberty"
MIGRATION_BRANCHES = ('expand', 'contract')

mods = repos.NeutronModules()
VALID_SERVICES = list(map(mods.alembic_name, mods.installed_list()))

_core_opts = [
    cfg.StrOpt('core_plugin',
               default='',
               help=_('Neutron plugin provider module')),
    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)),
    cfg.BoolOpt('split_branches',
                default=False,