Exemple #1
0
def load_auth_methods():
    global AUTH_PLUGINS_LOADED

    if AUTH_PLUGINS_LOADED:
        # Only try and load methods a single time.
        return
    # config.setup_authentication should be idempotent, call it to ensure we
    # have setup all the appropriate configuration options we may need.
    config.setup_authentication()
    for plugin in CONF.auth.methods:
        if '.' in plugin:
            # NOTE(morganfainberg): if '.' is in the plugin name, it should be
            # imported rather than used as a plugin identifier.
            plugin_class = plugin
            driver = importutils.import_object(plugin)
            if not hasattr(driver, 'method'):
                raise ValueError(_('Cannot load an auth-plugin by class-name '
                                   'without a "method" attribute defined: %s'),
                                 plugin_class)

            LOG.info(_LI('Loading auth-plugins by class-name is deprecated.'))
            plugin_name = driver.method
        else:
            plugin_name = plugin
            plugin_class = CONF.auth.get(plugin)
            driver = importutils.import_object(plugin_class)
        if plugin_name in AUTH_METHODS:
            raise ValueError(_('Auth plugin %(plugin)s is requesting '
                               'previously registered method %(method)s') %
                             {'plugin': plugin_class, 'method': driver.method})
        AUTH_METHODS[plugin_name] = driver
    AUTH_PLUGINS_LOADED = True
Exemple #2
0
def load_auth_methods():
    global AUTH_PLUGINS_LOADED

    if AUTH_PLUGINS_LOADED:
        # Only try and load methods a single time.
        return
    # config.setup_authentication should be idempotent, call it to ensure we
    # have setup all the appropriate configuration options we may need.
    config.setup_authentication()
    for plugin in CONF.auth.methods:
        if '.' in plugin:
            # NOTE(morganfainberg): if '.' is in the plugin name, it should be
            # imported rather than used as a plugin identifier.
            plugin_class = plugin
            driver = importutils.import_object(plugin)
            if not hasattr(driver, 'method'):
                raise ValueError(_('Cannot load an auth-plugin by class-name '
                                   'without a "method" attribute defined: %s'),
                                 plugin_class)

            LOG.info(_LI('Loading auth-plugins by class-name is deprecated.'))
            plugin_name = driver.method
        else:
            plugin_name = plugin
            plugin_class = CONF.auth.get(plugin)
            driver = importutils.import_object(plugin_class)
        if plugin_name in AUTH_METHODS:
            raise ValueError(_('Auth plugin %(plugin)s is requesting '
                               'previously registered method %(method)s') %
                             {'plugin': plugin_class, 'method': driver.method})
        AUTH_METHODS[plugin_name] = driver
    AUTH_PLUGINS_LOADED = True
 def __init__(self):
     assert(CONF.tandem.primary is not None)
     self.primary   = importutils.import_object(CONF.tandem.primary)
     self.secondary = None
     if CONF.tandem.secondary is not None and \
             len(CONF.tandem.secondary) > 0:
         self.secondary = importutils.import_object(CONF.tandem.secondary)
Exemple #4
0
 def _assign_data_mainpulator(self):
     if self._data_manipulator is None:
         if self.son_manipulator:
             self._data_manipulator = importutils.import_object(
                 self.son_manipulator)
         else:
             self._data_manipulator = BaseTransform()
Exemple #5
0
 def _assign_data_mainpulator(self):
     if self._data_manipulator is None:
         if self.son_manipulator:
             self._data_manipulator = importutils.import_object(
                 self.son_manipulator)
         else:
             self._data_manipulator = BaseTransform()
Exemple #6
0
def _setup_logging_from_conf():
    log_root = getLogger(None).logger
    for handler in log_root.handlers:
        log_root.removeHandler(handler)

    if CONF.use_syslog:
        facility = _find_facility_from_conf()
        syslog = logging.handlers.SysLogHandler(address='/dev/log',
                                                facility=facility)
        log_root.addHandler(syslog)

    logpath = _get_log_file_path()
    if logpath:
        filelog = logging.handlers.WatchedFileHandler(logpath)
        log_root.addHandler(filelog)

    if CONF.use_stderr:
        streamlog = ColorHandler()
        log_root.addHandler(streamlog)

    elif not logpath:
        # pass sys.stdout as a positional argument
        # python2.6 calls the argument strm, in 2.7 it's stream
        streamlog = logging.StreamHandler(sys.stdout)
        log_root.addHandler(streamlog)

    if CONF.publish_errors:
        handler = importutils.import_object(
            "keystone.openstack.common.log_handler.PublishErrorsHandler",
            logging.ERROR)
        log_root.addHandler(handler)

    datefmt = CONF.log_date_format
    for handler in log_root.handlers:
        # NOTE(alaski): CONF.log_format overrides everything currently.  This
        # should be deprecated in favor of context aware formatting.
        if CONF.log_format:
            handler.setFormatter(logging.Formatter(fmt=CONF.log_format,
                                                   datefmt=datefmt))
            log_root.info('Deprecated: log_format is now deprecated and will '
                          'be removed in the next release')
        else:
            handler.setFormatter(ContextFormatter(datefmt=datefmt))

    if CONF.debug:
        log_root.setLevel(logging.DEBUG)
    elif CONF.verbose:
        log_root.setLevel(logging.INFO)
    else:
        log_root.setLevel(logging.WARNING)

    for pair in CONF.default_log_levels:
        mod, _sep, level_name = pair.partition('=')
        level = logging.getLevelName(level_name)
        logger = logging.getLogger(mod)
        logger.setLevel(level)
Exemple #7
0
def _setup_logging_from_conf():
    log_root = getLogger(None).logger
    for handler in log_root.handlers:
        log_root.removeHandler(handler)

    if CONF.use_syslog:
        facility = _find_facility_from_conf()
        syslog = logging.handlers.SysLogHandler(address='/dev/log',
                                                facility=facility)
        log_root.addHandler(syslog)

    logpath = _get_log_file_path()
    if logpath:
        filelog = logging.handlers.WatchedFileHandler(logpath)
        log_root.addHandler(filelog)

    if CONF.use_stderr:
        streamlog = ColorHandler()
        log_root.addHandler(streamlog)

    elif not logpath:
        # pass sys.stdout as a positional argument
        # python2.6 calls the argument strm, in 2.7 it's stream
        streamlog = logging.StreamHandler(sys.stdout)
        log_root.addHandler(streamlog)

    if CONF.publish_errors:
        handler = importutils.import_object(
            "keystone.openstack.common.log_handler.PublishErrorsHandler",
            logging.ERROR)
        log_root.addHandler(handler)

    datefmt = CONF.log_date_format
    for handler in log_root.handlers:
        # NOTE(alaski): CONF.log_format overrides everything currently.  This
        # should be deprecated in favor of context aware formatting.
        if CONF.log_format:
            handler.setFormatter(
                logging.Formatter(fmt=CONF.log_format, datefmt=datefmt))
            log_root.info('Deprecated: log_format is now deprecated and will '
                          'be removed in the next release')
        else:
            handler.setFormatter(ContextFormatter(datefmt=datefmt))

    if CONF.debug:
        log_root.setLevel(logging.DEBUG)
    elif CONF.verbose:
        log_root.setLevel(logging.INFO)
    else:
        log_root.setLevel(logging.WARNING)

    for pair in CONF.default_log_levels:
        mod, _sep, level_name = pair.partition('=')
        level = logging.getLevelName(level_name)
        logger = logging.getLogger(mod)
        logger.setLevel(level)
Exemple #8
0
def _get_matchmaker(*args, **kwargs):
    global matchmaker
    if not matchmaker:
        mm = CONF.rpc_zmq_matchmaker
        if mm.endswith('matchmaker.MatchMakerRing'):
            mm.replace('matchmaker', 'matchmaker_ring')
            LOG.warn(_('rpc_zmq_matchmaker = %(orig)s is deprecated; use'
                       ' %(new)s instead') % dict(
                     orig=CONF.rpc_zmq_matchmaker, new=mm))
        matchmaker = importutils.import_object(mm, *args, **kwargs)
    return matchmaker
Exemple #9
0
def _get_matchmaker(*args, **kwargs):
    global matchmaker
    if not matchmaker:
        mm = CONF.rpc_zmq_matchmaker
        if mm.endswith('matchmaker.MatchMakerRing'):
            mm.replace('matchmaker', 'matchmaker_ring')
            LOG.warn(
                _('rpc_zmq_matchmaker = %(orig)s is deprecated; use'
                  ' %(new)s instead') %
                dict(orig=CONF.rpc_zmq_matchmaker, new=mm))
        matchmaker = importutils.import_object(mm, *args, **kwargs)
    return matchmaker
Exemple #10
0
def load_auth_methods():
    global AUTH_PLUGINS_LOADED

    if AUTH_PLUGINS_LOADED:
        # Only try and load methods a single time.
        return
    # config.setup_authentication should be idempotent, call it to ensure we
    # have setup all the appropriate configuration options we may need.
    config.setup_authentication()
    for plugin in CONF.auth.methods:
        if "." in plugin:
            # NOTE(morganfainberg): if '.' is in the plugin name, it should be
            # imported rather than used as a plugin identifier.
            plugin_class = plugin
            driver = importutils.import_object(plugin)
            if not hasattr(driver, "method"):
                raise ValueError(
                    _("Cannot load an auth-plugin by class-name " 'without a "method" attribute defined: %s'),
                    plugin_class,
                )
        else:
            plugin_class = CONF.auth.get(plugin)
            driver = importutils.import_object(plugin_class)
            if hasattr(driver, "method"):
                if driver.method != plugin:
                    raise ValueError(
                        _("Driver requested method %(req)s does " "not match plugin name %(plugin)s.")
                        % {"req": driver.method, "plugin": plugin}
                    )
            else:
                LOG.warning(_('Auth Plugin %s does not have a "method" ' "attribute."), plugin)
                setattr(driver, "method", plugin)
        if driver.method in AUTH_METHODS:
            raise ValueError(
                _("Auth plugin %(plugin)s is requesting " "previously registered method %(method)s")
                % {"plugin": plugin_class, "method": driver.method}
            )
        AUTH_METHODS[driver.method] = driver
    AUTH_PLUGINS_LOADED = True
Exemple #11
0
 def _load_driver(self, domain_config, assignment_api):
     domain_config_driver = (
         importutils.import_object(
             domain_config['cfg'].identity.driver, domain_config['cfg']))
     domain_config_driver.assignment_api = assignment_api
     return domain_config_driver
Exemple #12
0
 def _load_driver(self, assignment_api, domain_id):
     domain_config = self[domain_id]
     domain_config['driver'] = (
         importutils.import_object(
             domain_config['cfg'].identity.driver, domain_config['cfg']))
     domain_config['driver'].assignment_api = assignment_api
Exemple #13
0
 def load_backends(self):
     """Hacky shortcut to load the backends for data manipulation."""
     self.identity_api = importutils.import_object(CONF.identity.driver)
     self.token_api = importutils.import_object(CONF.token.driver)
     self.catalog_api = importutils.import_object(CONF.catalog.driver)
Exemple #14
0
def load_auth_method(method_name):
    if method_name not in CONF.auth.methods:
        raise exception.AuthMethodNotSupported()
    driver = CONF.auth.get(method_name)
    return importutils.import_object(driver)
Exemple #15
0
 def load_backends(self):
     """Hacky shortcut to load the backends for data manipulation."""
     self.identity_api = importutils.import_object(CONF.identity.driver)
     self.token_api = importutils.import_object(CONF.token.driver)
     self.catalog_api = importutils.import_object(CONF.catalog.driver)
Exemple #16
0
def load_auth_method(method_name):
    if method_name not in CONF.auth.methods:
        raise exception.AuthMethodNotSupported()
    driver = CONF.auth.get(method_name)
    return importutils.import_object(driver)
Exemple #17
0
 def _load_driver(self, domain_config, assignment_api):
     domain_config_driver = (importutils.import_object(
         domain_config['cfg'].identity.driver, domain_config['cfg']))
     domain_config_driver.assignment_api = assignment_api
     return domain_config_driver
Exemple #18
0
def _setup_logging_from_conf(project, version):
    log_root = getLogger(None).logger
    for handler in log_root.handlers:
        log_root.removeHandler(handler)

    if CONF.use_syslog:
        facility = _find_facility_from_conf()
        # TODO(bogdando) use the format provided by RFCSysLogHandler
        #   after existing syslog format deprecation in J
        if CONF.use_syslog_rfc_format:
            syslog = RFCSysLogHandler(address='/dev/log',
                                      facility=facility)
        else:
            syslog = logging.handlers.SysLogHandler(address='/dev/log',
                                                    facility=facility)
        log_root.addHandler(syslog)

    logpath = _get_log_file_path()
    if logpath:
        filelog = logging.handlers.WatchedFileHandler(logpath)
        log_root.addHandler(filelog)

    if CONF.use_stderr:
        streamlog = ColorHandler()
        log_root.addHandler(streamlog)

    elif not logpath:
        # pass sys.stdout as a positional argument
        # python2.6 calls the argument strm, in 2.7 it's stream
        streamlog = logging.StreamHandler(sys.stdout)
        log_root.addHandler(streamlog)

    if CONF.publish_errors:
        try:
            handler = importutils.import_object(
                "keystone.openstack.common.log_handler.PublishErrorsHandler",
                logging.ERROR)
        except ImportError:
            handler = importutils.import_object(
                "oslo.messaging.notify.log_handler.PublishErrorsHandler",
                logging.ERROR)
        log_root.addHandler(handler)

    datefmt = CONF.log_date_format
    for handler in log_root.handlers:
        # NOTE(alaski): CONF.log_format overrides everything currently.  This
        # should be deprecated in favor of context aware formatting.
        if CONF.log_format:
            handler.setFormatter(logging.Formatter(fmt=CONF.log_format,
                                                   datefmt=datefmt))
            log_root.info('Deprecated: log_format is now deprecated and will '
                          'be removed in the next release')
        else:
            handler.setFormatter(ContextFormatter(project=project,
                                                  version=version,
                                                  datefmt=datefmt))

    if CONF.debug:
        log_root.setLevel(logging.DEBUG)
    elif CONF.verbose:
        log_root.setLevel(logging.INFO)
    else:
        log_root.setLevel(logging.WARNING)

    for pair in CONF.default_log_levels:
        mod, _sep, level_name = pair.partition('=')
        logger = logging.getLogger(mod)
        # NOTE(AAzza) in python2.6 Logger.setLevel doesn't convert string name
        # to integer code.
        if sys.version_info < (2, 7):
            level = logging.getLevelName(level_name)
            logger.setLevel(level)
        else:
            logger.setLevel(level_name)
Exemple #19
0
 def _load_driver(self, assignment_api, domain_id):
     domain_config = self[domain_id]
     domain_config["driver"] = importutils.import_object(domain_config["cfg"].identity.driver, domain_config["cfg"])
     domain_config["driver"].assignment_api = assignment_api
Exemple #20
0
 def main(self):
     for k in ['identity', 'catalog', 'policy', 'token']:
         driver = importutils.import_object(getattr(CONF, k).driver)
         if hasattr(driver, 'db_sync'):
             driver.db_sync()
Exemple #21
0
def _setup_logging_from_conf(project, version):
    log_root = getLogger(None).logger
    for handler in log_root.handlers:
        log_root.removeHandler(handler)

    if CONF.use_syslog:
        facility = _find_facility_from_conf()
        # TODO(bogdando) use the format provided by RFCSysLogHandler
        #   after existing syslog format deprecation in J
        if CONF.use_syslog_rfc_format:
            syslog = RFCSysLogHandler(address='/dev/log', facility=facility)
        else:
            syslog = logging.handlers.SysLogHandler(address='/dev/log',
                                                    facility=facility)
        log_root.addHandler(syslog)

    logpath = _get_log_file_path()
    if logpath:
        filelog = logging.handlers.WatchedFileHandler(logpath)
        log_root.addHandler(filelog)

    if CONF.use_stderr:
        streamlog = ColorHandler()
        log_root.addHandler(streamlog)

    elif not logpath:
        # pass sys.stdout as a positional argument
        # python2.6 calls the argument strm, in 2.7 it's stream
        streamlog = logging.StreamHandler(sys.stdout)
        log_root.addHandler(streamlog)

    if CONF.publish_errors:
        try:
            handler = importutils.import_object(
                "keystone.openstack.common.log_handler.PublishErrorsHandler",
                logging.ERROR)
        except ImportError:
            handler = importutils.import_object(
                "oslo.messaging.notify.log_handler.PublishErrorsHandler",
                logging.ERROR)
        log_root.addHandler(handler)

    datefmt = CONF.log_date_format
    for handler in log_root.handlers:
        # NOTE(alaski): CONF.log_format overrides everything currently.  This
        # should be deprecated in favor of context aware formatting.
        if CONF.log_format:
            handler.setFormatter(
                logging.Formatter(fmt=CONF.log_format, datefmt=datefmt))
            log_root.info('Deprecated: log_format is now deprecated and will '
                          'be removed in the next release')
        else:
            handler.setFormatter(
                ContextFormatter(project=project,
                                 version=version,
                                 datefmt=datefmt))

    if CONF.debug:
        log_root.setLevel(logging.DEBUG)
    elif CONF.verbose:
        log_root.setLevel(logging.INFO)
    else:
        log_root.setLevel(logging.WARNING)

    for pair in CONF.default_log_levels:
        mod, _sep, level_name = pair.partition('=')
        logger = logging.getLogger(mod)
        # NOTE(AAzza) in python2.6 Logger.setLevel doesn't convert string name
        # to integer code.
        if sys.version_info < (2, 7):
            level = logging.getLevelName(level_name)
            logger.setLevel(level)
        else:
            logger.setLevel(level_name)
Exemple #22
0
 def main():
     for k in ['identity', 'catalog', 'policy', 'token', 'credential']:
         driver = importutils.import_object(getattr(CONF, k).driver)
         if hasattr(driver, 'db_sync'):
             driver.db_sync(CONF.command.version)
Exemple #23
0
 def _load_driver(self, assignment_api, domain_id):
     domain_config = self[domain_id]
     domain_config['driver'] = (importutils.import_object(
         domain_config['cfg'].identity.driver, domain_config['cfg']))
     domain_config['driver'].assignment_api = assignment_api
Exemple #24
0
 def __init__(self, driver_name):
     self.driver = importutils.import_object(driver_name)
Exemple #25
0
 def main():
     for k in ['identity', 'catalog', 'policy', 'token']:
         driver = importutils.import_object(getattr(CONF, k).driver)
         if hasattr(driver, 'db_sync'):
             driver.db_sync()
Exemple #26
0
 def main():
     for k in ["identity", "catalog", "policy", "token"]:
         driver = importutils.import_object(getattr(CONF, k).driver)
         if hasattr(driver, "db_sync"):
             driver.db_sync()