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


Python Config.get_by_pack方法代碼示例

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


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

示例1: test_get_config_default_value_from_config_schema_is_used

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def test_get_config_default_value_from_config_schema_is_used(self):
        # No value is provided for "region" in the config, default value from config schema
        # should be used
        loader = ContentPackConfigLoader(pack_name='dummy_pack_5')
        config = loader.get_config()
        self.assertEqual(config['region'], 'default-region-value')

        # Here a default value is specified in schema but an explicit value is provided in the
        # config
        loader = ContentPackConfigLoader(pack_name='dummy_pack_1')
        config = loader.get_config()
        self.assertEqual(config['region'], 'us-west-1')

        # Config item attribute has required: false
        # Value is provided in the config - it should be used as provided
        pack_name = 'dummy_pack_5'

        loader = ContentPackConfigLoader(pack_name=pack_name)
        config = loader.get_config()
        self.assertEqual(config['non_required_with_default_value'], 'config value')

        config_db = Config.get_by_pack(pack_name)
        del config_db['values']['non_required_with_default_value']
        Config.add_or_update(config_db)

        # No value in the config - default value should be used
        config_db = Config.get_by_pack(pack_name)
        config_db.delete()

        # No config exists for that pack - default value should be used
        loader = ContentPackConfigLoader(pack_name=pack_name)
        config = loader.get_config()
        self.assertEqual(config['non_required_with_default_value'], 'some default value')
開發者ID:StackStorm,項目名稱:st2,代碼行數:35,代碼來源:test_config_loader.py

示例2: test_default_values_from_schema_are_used_when_no_config_exists

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def test_default_values_from_schema_are_used_when_no_config_exists(self):
        pack_name = 'dummy_pack_5'
        config_db = Config.get_by_pack(pack_name)

        # Delete the existing config loaded in setUp
        config_db = Config.get_by_pack(pack_name)
        config_db.delete()

        # Verify config has been deleted from the database
        self.assertRaises(StackStormDBObjectNotFoundError, Config.get_by_pack, pack_name)

        loader = ContentPackConfigLoader(pack_name=pack_name)
        config = loader.get_config()
        self.assertEqual(config['region'], 'default-region-value')
開發者ID:StackStorm,項目名稱:st2,代碼行數:16,代碼來源:test_config_loader.py

示例3: _register_config_for_pack

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def _register_config_for_pack(self, pack, config_path):
        content = {}
        values = self._meta_loader.load(config_path)

        content['pack'] = pack
        content['values'] = values

        config_api = ConfigAPI(**content)
        config_api.validate(validate_against_schema=self._validate_configs)
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(config_api.pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to config for pack %s.', pack)
            raise

        return config_db
開發者ID:janjaapbos,項目名稱:st2,代碼行數:27,代碼來源:configsregistrar.py

示例4: get_config

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def get_config(self):
        result = {}

        # 1. Retrieve values from pack local config.yaml file
        config = self._config_parser.get_config()

        if config:
            config = config.config or {}
            result.update(config)

        # Retrieve corresponding ConfigDB and ConfigSchemaDB object
        # Note: ConfigSchemaDB is optional right now. If it doesn't exist, we assume every value
        # is of a type string
        try:
            config_db = Config.get_by_pack(value=self.pack_name)
        except StackStormDBObjectNotFoundError:
            # Corresponding pack config doesn't exist, return early
            return result

        try:
            config_schema_db = ConfigSchema.get_by_pack(value=self.pack_name)
        except StackStormDBObjectNotFoundError:
            config_schema_db = None

        # 2. Retrieve values from "global" pack config file (if available) and resolve them if
        # necessary
        config = self._get_values_for_config(config_schema_db=config_schema_db,
                                             config_db=config_db)
        result.update(config)

        return result
開發者ID:Plexxi,項目名稱:st2,代碼行數:33,代碼來源:config_loader.py

示例5: get_config

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def get_config(self):
        result = {}

        # Retrieve corresponding ConfigDB and ConfigSchemaDB object
        # Note: ConfigSchemaDB is optional right now. If it doesn't exist, we assume every value
        # is of a type string
        try:
            config_db = Config.get_by_pack(value=self.pack_name)
        except StackStormDBObjectNotFoundError:
            # Corresponding pack config doesn't exist. We set config_db to an empty config so
            # that the default values from config schema are still correctly applied even if
            # pack doesn't contain a config.
            config_db = ConfigDB(pack=self.pack_name, values={})

        try:
            config_schema_db = ConfigSchema.get_by_pack(value=self.pack_name)
        except StackStormDBObjectNotFoundError:
            config_schema_db = None

        # 2. Retrieve values from "global" pack config file (if available) and resolve them if
        # necessary
        config = self._get_values_for_config(config_schema_db=config_schema_db,
                                             config_db=config_db)
        result.update(config)

        return result
開發者ID:lyandut,項目名稱:st2,代碼行數:28,代碼來源:config_loader.py

示例6: save_model

# 需要導入模塊: from st2common.persistence.pack import Config [as 別名]
# 或者: from st2common.persistence.pack.Config import get_by_pack [as 別名]
    def save_model(config_api):
        pack = config_api.pack
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to save config for pack %s.', pack)
            raise

        return config_db
開發者ID:nzlosh,項目名稱:st2,代碼行數:20,代碼來源:configsregistrar.py


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