當前位置: 首頁>>代碼示例>>Python>>正文


Python cfg.ConfigFilesNotFoundError方法代碼示例

本文整理匯總了Python中oslo_config.cfg.ConfigFilesNotFoundError方法的典型用法代碼示例。如果您正苦於以下問題:Python cfg.ConfigFilesNotFoundError方法的具體用法?Python cfg.ConfigFilesNotFoundError怎麽用?Python cfg.ConfigFilesNotFoundError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_config.cfg的用法示例。


在下文中一共展示了cfg.ConfigFilesNotFoundError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_paste_app

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises ConfigFilesNotFoundError when config file cannot be located
    :raises RuntimeError when application cannot be loaded from config file
    """

    config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
    if not config_path:
        raise cfg.ConfigFilesNotFoundError(
            config_files=[cfg.CONF.api_paste_config])
    config_path = os.path.abspath(config_path)
    LOG.info(_LI("Config paste file: %s"), config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") %
               {'app_name': app_name,
                'config_path': config_path})
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app 
開發者ID:platform9,項目名稱:openstack-omni,代碼行數:27,代碼來源:config.py

示例2: test_main_sudo_failed

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def test_main_sudo_failed(self, register_cli_opt, log_setup,
                              register_log_opts, config_opts_call):
        script_name = 'manila-manage'
        sys.argv = [script_name, 'fake_category', 'fake_action']
        config_opts_call.side_effect = cfg.ConfigFilesNotFoundError(
            mock.sentinel._namespace)

        exit = self.assertRaises(SystemExit, manila_manage.main)

        self.assertTrue(register_cli_opt.called)
        register_log_opts.assert_called_once_with(CONF)
        config_opts_call.assert_called_once_with(
            sys.argv[1:], project='manila',
            version=version.version_string())
        self.assertFalse(log_setup.called)
        self.assertEqual(2, exit.code) 
開發者ID:openstack,項目名稱:manila,代碼行數:18,代碼來源:test_manage.py

示例3: handle_config_exception

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def handle_config_exception(exc):
    msg = ""

    if not any(LOG.handlers):
        logging.basicConfig(level=logging.DEBUG)

    if isinstance(exc, cfg.RequiredOptError):
        msg = "Missing option '{opt}'".format(opt=exc.opt_name)
        if exc.group:
            msg += " in group '{}'".format(exc.group)
        CONF.print_help()

    elif isinstance(exc, cfg.ConfigFilesNotFoundError):
        if CONF._args[0] == "init":
            return

        msg = (_("Configuration file specified ('%s') wasn't "
                 "found or was unreadable.") % ",".join(
            CONF.config_file))

    if msg:
        LOG.warning(msg)
        print(syntribos.SEP)
    else:
        LOG.exception(exc) 
開發者ID:openstack-archive,項目名稱:syntribos,代碼行數:27,代碼來源:config.py

示例4: load_app

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def load_app():
    global APPCONFIGS
    # Build the WSGI app
    cfg_path = CONF.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = CONF.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        raise cfg.ConfigFilesNotFoundError([CONF.api.paste_config])

    config = dict(conf=CONF)
    configkey = uuidutils.generate_uuid()
    APPCONFIGS[configkey] = config

    LOG.info('Full WSGI config used: %s', cfg_path)

    appname = "vitrage+" + CONF.api.auth_mode
    return deploy.loadapp("config:" + cfg_path, name=appname,
                          global_conf={'configkey': configkey}) 
開發者ID:openstack,項目名稱:vitrage,代碼行數:21,代碼來源:app.py

示例5: load_paste_app

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises ConfigFilesNotFoundError: when config file cannot be located
    :raises RuntimeError: when application cannot be loaded from config file
    """

    config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
    if not config_path:
        raise cfg.ConfigFilesNotFoundError(
            config_files=[cfg.CONF.api_paste_config])
    config_path = os.path.abspath(config_path)
    LOG.info("Config paste file: %s", config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") %
               {'app_name': app_name,
                'config_path': config_path})
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app 
開發者ID:openstack,項目名稱:tacker,代碼行數:27,代碼來源:config.py

示例6: _get_policy_path

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def _get_policy_path(self, path):
        """Locate the policy YAML/JSON data file/path.

        :param path: It's value can be a full path or related path. When
                     full path specified, this function just returns the full
                     path. When related path specified, this function will
                     search configuration directories to find one that exists.

        :returns: The policy path

        :raises: ConfigFilesNotFoundError if the file/path couldn't
                 be located.
        """
        policy_path = self.conf.find_file(path)

        if policy_path:
            return policy_path

        raise cfg.ConfigFilesNotFoundError((path,)) 
開發者ID:openstack,項目名稱:oslo.policy,代碼行數:21,代碼來源:policy.py

示例7: load_app

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def load_app(conf):
    global APPCONFIGS

    # Build the WSGI app
    cfg_path = conf.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = conf.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])

    config = dict(conf=conf)
    configkey = str(uuid.uuid4())
    APPCONFIGS[configkey] = config

    LOG.info("WSGI config used: %s", cfg_path)
    return deploy.loadapp("config:" + cfg_path,
                          name="aodh+" + (
                              conf.api.auth_mode
                              if conf.api.auth_mode else "noauth"
                          ),
                          global_conf={'configkey': configkey}) 
開發者ID:openstack,項目名稱:aodh,代碼行數:24,代碼來源:app.py

示例8: load_app

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def load_app():
    cfg_file = None
    cfg_path = CONF.api.api_paste_config
    if not os.path.isabs(cfg_path):
        cfg_file = CONF.find_file(cfg_path)
    elif os.path.exists(cfg_path):
        cfg_file = cfg_path

    if not cfg_file:
        raise cfg.ConfigFilesNotFoundError([CONF.api.api_paste_config])
    LOG.info("Full WSGI config used: %s", cfg_file)
    return deploy.loadapp("config:" + cfg_file) 
開發者ID:openstack,項目名稱:zun,代碼行數:14,代碼來源:app.py

示例9: prepare_service

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def prepare_service(args=None, handler=None, api_hander=None, reactor_thread_size=100):
    """prepare all services
    """
    try:
        CONF(args=args, project='yabgp', version=version,
             default_config_files=['/etc/yabgp/yabgp.ini'])
    except cfg.ConfigFilesNotFoundError:
        CONF(args=args, project='yabgp', version=version)

    log.init_log()
    LOG.info('Log (Re)opened.')
    LOG.info("Configuration:")
    cfg.CONF.log_opt_values(LOG, logging.INFO)
    try:
        if not handler:
            LOG.info('No handler provided, init default handler')
            handler = DefaultHandler()
        get_bgp_config()
        check_msg_config()
    except Exception as e:
        LOG.error(e)
        LOG.debug(traceback.format_exc())
        sys.exit()
    # prepare api handler
    if api_hander:
        register_api_handler(api_hander)
    LOG.info('Starting server in PID %s', os.getpid())
    prepare_twisted_service(handler, reactor_thread_size) 
開發者ID:smartbgp,項目名稱:yabgp,代碼行數:30,代碼來源:__init__.py

示例10: _get_enforcers

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def _get_enforcers():
    global _ENFORCERS
    if not _ENFORCERS:
        _ENFORCERS = {}
        pol_files = cfg.CONF.service_policies.service_policy_files
        for service, pol_file in pol_files.items():
            base_path = str(cfg.CONF.service_policies.service_policy_path)
            service_policy_path = os.path.join(base_path,
                                               pol_file)
            enforcer = policy.Enforcer(cfg.CONF, service_policy_path)
            missing_config_file = False

            # oslo.policy's approach to locating these files seems to be
            # changing; current master doesn't raise an exception
            try:
                enforcer.load_rules()
                enforcer.register_defaults(policies.list_rules())
                if not enforcer.policy_path:
                    missing_config_file = True
            except cfg.ConfigFilesNotFoundError:
                missing_config_file = True

            if missing_config_file:
                LOG.error("Policy file for service %(service)s not found"
                          " in %(policy_file)s (base path %(base)s)" %
                          {"service": service, "policy_file": pol_file,
                           "base": service_policy_path})
                raise MissingPolicyFile(
                    "Could not find policy file %(pol_file)s for service "
                    "type %(service)s" % {'pol_file': pol_file,
                                          'service': service})

            LOG.debug("Adding policy enforcer for %s" % service)
            _ENFORCERS[service] = enforcer

    return _ENFORCERS 
開發者ID:openstack,項目名稱:searchlight,代碼行數:38,代碼來源:service_policies.py

示例11: test_api_paste_file_not_exist

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def test_api_paste_file_not_exist(self):
        cfg.CONF.set_override('api_paste_config', 'non-existent-file',
                              group='api')
        with mock.patch.object(cfg.CONF, 'find_file') as ff:
            ff.return_value = None
            self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app) 
開發者ID:openstack,項目名稱:magnum,代碼行數:8,代碼來源:test_root.py

示例12: test_api_paste_file_not_exist_not_abs

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def test_api_paste_file_not_exist_not_abs(self, mock_deploy):
        path = self.get_path(cfg.CONF['api']['api_paste_config'] + 'test')
        cfg.CONF.set_override('api_paste_config', path, group='api')
        self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app) 
開發者ID:openstack,項目名稱:magnum,代碼行數:6,代碼來源:test_root.py

示例13: main

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def main():
    """Parse options and call the appropriate class/method."""
    CONF.register_cli_opt(category_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(_("\nOpenStack manila version: %(version)s\n") %
              {'version': version.version_string()})
        print(script_name + " category action [<args>]")
        print(_("Available categories:"))
        for category in CATEGORIES:
            print("\t%s" % category)
        sys.exit(2)

    try:
        log.register_options(CONF)
        CONF(sys.argv[1:], project='manila',
             version=version.version_string())
        log.setup(CONF, "manila")
    except cfg.ConfigFilesNotFoundError as e:
        cfg_files = e.config_files
        print(_("Failed to read configuration file(s): %s") % cfg_files)
        sys.exit(2)

    fn = CONF.category.action_fn

    fn_args = fetch_func_args(fn)
    fn(*fn_args) 
開發者ID:openstack,項目名稱:manila,代碼行數:29,代碼來源:manage.py

示例14: main

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def main():
    """Parse options and call the appropriate class/method."""
    CONF.register_cli_opt(command_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(_("\nOpenStack masakari version: %(version)s\n") %
              {'version': version.version_string()})
        print(script_name + " category action [<args>]")
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        CONF(sys.argv[1:], project='masakari',
             version=version.version_string())
        logging.setup(CONF, "masakari")
        python_logging.captureWarnings(True)
    except cfg.ConfigDirNotFoundError as details:
        print(_("Invalid directory: %s") % details)
        sys.exit(2)
    except cfg.ConfigFilesNotFoundError as e:
        cfg_files = ', '.join(e.config_files)
        print(_("Failed to read configuration file(s): %s") % cfg_files)
        sys.exit(2)

    fn = CONF.category.action_fn
    fn_args = fetch_func_args(fn)
    fn(*fn_args) 
開發者ID:openstack,項目名稱:masakari,代碼行數:31,代碼來源:manage.py

示例15: prepare_service

# 需要導入模塊: from oslo_config import cfg [as 別名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 別名]
def prepare_service(args=None, handler=None):
    """prepare the twisted service

    :param hander: handler object
    """
    if not handler:
        handler = DefaultHandler()
    try:
        CONF(args=args, project='yabmp', version=version,
             default_config_files=['/etc/yabmp/yabmp.ini'])
    except cfg.ConfigFilesNotFoundError:
        CONF(args=args, project='yabmp', version=version)

    log.init_log()
    LOG.info('Log (Re)opened.')
    LOG.info("Configuration:")

    cfg.CONF.log_opt_values(LOG, logging.INFO)

    handler.init()
    # start bmp server
    try:
        reactor.listenTCP(
            CONF.bind_port,
            BMPFactory(handler=handler),
            interface=CONF.bind_host)
        LOG.info(
            "Starting bmpd server listen to port = %s and ip = %s",
            CONF.bind_port, CONF.bind_host)
        reactor.run()
    except Exception as e:
        LOG.error(e) 
開發者ID:smartbgp,項目名稱:yabmp,代碼行數:34,代碼來源:service.py


注:本文中的oslo_config.cfg.ConfigFilesNotFoundError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。