• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python reference.get_str_resource_ref_from_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中st2common.util.reference.get_str_resource_ref_from_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_str_resource_ref_from_model函数的具体用法?Python get_str_resource_ref_from_model怎么用?Python get_str_resource_ref_from_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_str_resource_ref_from_model函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: to_model

    def to_model(cls, rule):
        kwargs = {}
        kwargs['name'] = getattr(rule, 'name', None)
        kwargs['description'] = getattr(rule, 'description', None)

        # Create a trigger for the provided rule
        trigger_db = TriggerService.create_trigger_db_from_rule(rule)
        kwargs['trigger'] = reference.get_str_resource_ref_from_model(trigger_db)

        # Validate trigger parameters
        validator.validate_trigger_parameters(trigger_db=trigger_db)

        kwargs['pack'] = getattr(rule, 'pack', DEFAULT_PACK_NAME)
        kwargs['ref'] = ResourceReference.to_string_reference(pack=kwargs['pack'],
                                                              name=kwargs['name'])

        # Validate criteria
        kwargs['criteria'] = dict(getattr(rule, 'criteria', {}))
        validator.validate_criteria(kwargs['criteria'])

        kwargs['action'] = ActionExecutionSpecDB(ref=rule.action['ref'],
                                                 parameters=rule.action.get('parameters', {}))

        rule_type = dict(getattr(rule, 'type', {}))
        if rule_type:
            kwargs['type'] = RuleTypeSpecDB(ref=rule_type['ref'],
                                            parameters=rule_type.get('parameters', {}))

        kwargs['enabled'] = getattr(rule, 'enabled', False)
        kwargs['tags'] = TagsHelper.to_model(getattr(rule, 'tags', []))

        model = cls.model(**kwargs)
        return model
开发者ID:hejin,项目名称:st2,代码行数:33,代码来源:rule.py


示例2: to_model

    def to_model(cls, rule):
        name = getattr(rule, 'name', None)
        description = getattr(rule, 'description', None)

        # Create a trigger for the provided rule
        trigger_db = TriggerService.create_trigger_db_from_rule(rule)

        trigger = reference.get_str_resource_ref_from_model(trigger_db)
        criteria = dict(getattr(rule, 'criteria', {}))
        pack = getattr(rule, 'pack', DEFAULT_PACK_NAME)
        ref = ResourceReference.to_string_reference(pack=pack, name=name)

        # Validate criteria
        validator.validate_criteria(criteria)

        # Validate trigger parameters
        validator.validate_trigger_parameters(trigger_db=trigger_db)

        action = ActionExecutionSpecDB(ref=rule.action['ref'],
                                       parameters=rule.action['parameters'])

        enabled = rule.enabled
        tags = TagsHelper.to_model(getattr(rule, 'tags', []))

        model = cls.model(name=name, description=description, pack=pack, ref=ref, trigger=trigger,
                          criteria=criteria, action=action, enabled=enabled, tags=tags)
        return model
开发者ID:joshgre,项目名称:st2,代码行数:27,代码来源:rule.py


示例3: test_rule_lookup

 def test_rule_lookup(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     trigger = ReactorModelTest._create_save_trigger(triggertype)
     runnertype = ActionModelTest._create_save_runnertype()
     action = ActionModelTest._create_save_action(runnertype)
     saved = ReactorModelTest._create_save_rule(trigger, action)
     retrievedrules = Rule.query(trigger=reference.get_str_resource_ref_from_model(trigger))
     self.assertEqual(1, len(retrievedrules), 'No rules found.')
     for retrievedrule in retrievedrules:
         self.assertEqual(saved.id, retrievedrule.id, 'Incorrect rule returned.')
     ReactorModelTest._delete([saved, trigger, action, runnertype, triggertype])
开发者ID:azamsheriff,项目名称:st2,代码行数:11,代码来源:test_db.py


示例4: test_rule_lookup_disabled

 def test_rule_lookup_disabled(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     trigger = ReactorModelTest._create_save_trigger(triggertype)
     runnertype = ActionModelTest._create_save_runnertype()
     action = ActionModelTest._create_save_action(runnertype)
     saved = ReactorModelTest._create_save_rule(trigger, action, False)
     retrievedrules = Rule.query(trigger=reference.get_str_resource_ref_from_model(trigger), enabled=False)
     self.assertEqual(1, len(retrievedrules), "Error looking up enabled rules.")
     for retrievedrule in retrievedrules:
         self.assertEqual(saved.id, retrievedrule.id, "Incorrect rule returned.")
     ReactorModelTest._delete([saved, trigger, action, runnertype, triggertype])
开发者ID:rlugojr,项目名称:st2,代码行数:11,代码来源:test_db.py


示例5: to_model

 def to_model(cls, rule):
     model = super(cls, cls).to_model(rule)
     trigger_db = TriggerService.create_trigger_db_from_rule(rule)
     model.trigger = reference.get_str_resource_ref_from_model(trigger_db)
     model.criteria = dict(getattr(rule, 'criteria', {}))
     validator.validate_criteria(model.criteria)
     model.action = ActionExecutionSpecDB()
     model.action.ref = rule.action['ref']
     model.action.parameters = rule.action['parameters']
     model.enabled = rule.enabled
     model.tags = TagsHelper.to_model(getattr(rule, 'tags', []))
     return model
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:12,代码来源:rule.py


示例6: _create_save_rule

 def _create_save_rule(trigger, action=None, enabled=True):
     created = RuleDB()
     created.name = 'rule-1'
     created.description = ''
     created.enabled = enabled
     created.trigger = reference.get_str_resource_ref_from_model(trigger)
     created.criteria = {}
     created.action = ActionExecutionSpecDB()
     action_ref = ResourceReference(pack=action.pack, name=action.name).ref
     created.action.ref = action_ref
     created.action.pack = action.pack
     created.action.parameters = {}
     return Rule.add_or_update(created)
开发者ID:srenatus,项目名称:st2,代码行数:13,代码来源:test_db.py


示例7: test_triggered_execution

    def test_triggered_execution(self):
        docs = {
            'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
            'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
            'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
            'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance'])}

        # Trigger an action execution.
        trigger_type = TriggerType.add_or_update(
            TriggerTypeAPI.to_model(TriggerTypeAPI(**docs['trigger_type'])))
        trigger = Trigger.add_or_update(TriggerAPI.to_model(TriggerAPI(**docs['trigger'])))
        rule = RuleAPI.to_model(RuleAPI(**docs['rule']))
        rule.trigger = reference.get_str_resource_ref_from_model(trigger)
        rule = Rule.add_or_update(rule)
        trigger_instance = TriggerInstance.add_or_update(
            TriggerInstanceAPI.to_model(TriggerInstanceAPI(**docs['trigger_instance'])))
        trace_service.add_or_update_given_trace_context(
            trace_context={'trace_tag': 'test_triggered_execution_trace'},
            trigger_instances=[str(trigger_instance.id)])
        enforcer = RuleEnforcer(trigger_instance, rule)
        enforcer.enforce()

        # Wait for the action execution to complete and then confirm outcome.
        liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
        self.assertIsNotNone(liveaction)
        liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)

        execution = self._get_action_execution(
            liveaction__id=str(liveaction.id),
            raise_exception=True
        )

        self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
        self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
        self.assertDictEqual(execution.trigger_instance,
                             vars(TriggerInstanceAPI.from_model(trigger_instance)))
        self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
        action = action_utils.get_action_by_ref(liveaction.action)
        self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
        runner = RunnerType.get_by_name(action.runner_type['name'])
        self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
        liveaction = LiveAction.get_by_id(str(liveaction.id))
        self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
        self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
        self.assertEqual(execution.result, liveaction.result)
        self.assertEqual(execution.status, liveaction.status)
        self.assertEqual(execution.context, liveaction.context)
        self.assertEqual(execution.liveaction['callback'], liveaction.callback)
        self.assertEqual(execution.liveaction['action'], liveaction.action)
开发者ID:StackStorm,项目名称:st2,代码行数:49,代码来源:test_executions.py


示例8: _create_save_rule

 def _create_save_rule(trigger, action=None, enabled=True):
     name = "rule-1"
     pack = "default"
     ref = ResourceReference.to_string_reference(name=name, pack=pack)
     created = RuleDB(name=name, pack=pack, ref=ref)
     created.description = ""
     created.enabled = enabled
     created.trigger = reference.get_str_resource_ref_from_model(trigger)
     created.criteria = {}
     created.action = ActionExecutionSpecDB()
     action_ref = ResourceReference(pack=action.pack, name=action.name).ref
     created.action.ref = action_ref
     created.action.pack = action.pack
     created.action.parameters = {}
     return Rule.add_or_update(created)
开发者ID:rlugojr,项目名称:st2,代码行数:15,代码来源:test_db.py


示例9: to_model

 def to_model(cls, rule):
     model = super(cls, cls).to_model(rule)
     trigger_db = TriggerService.create_trigger_db_from_rule(rule)
     model.trigger = reference.get_str_resource_ref_from_model(trigger_db)
     model.criteria = dict(getattr(rule, 'criteria', {}))
     for oldkey, value in six.iteritems(model.criteria):
         newkey = oldkey.replace('.', u'\u2024')
         if oldkey != newkey:
             model.criteria[newkey] = value
             del model.criteria[oldkey]
     validator.validate_criteria(model.criteria)
     model.action = ActionExecutionSpecDB()
     model.action.ref = rule.action['ref']
     model.action.parameters = rule.action['parameters']
     model.enabled = rule.enabled
     return model
开发者ID:bjoernbessert,项目名称:st2,代码行数:16,代码来源:rule.py


示例10: to_model

    def to_model(cls, rule):
        kwargs = {}
        kwargs['name'] = getattr(rule, 'name', None)
        kwargs['description'] = getattr(rule, 'description', None)

        # Validate trigger parameters
        # Note: This must happen before we create a trigger, otherwise create trigger could fail
        # with a cryptic error
        trigger = getattr(rule, 'trigger', {})
        trigger_type_ref = trigger.get('type', None)
        parameters = trigger.get('parameters', {})

        validator.validate_trigger_parameters(trigger_type_ref=trigger_type_ref,
                                              parameters=parameters)

        # Create a trigger for the provided rule
        trigger_db = TriggerService.create_trigger_db_from_rule(rule)
        kwargs['trigger'] = reference.get_str_resource_ref_from_model(trigger_db)

        kwargs['pack'] = getattr(rule, 'pack', DEFAULT_PACK_NAME)
        kwargs['ref'] = ResourceReference.to_string_reference(pack=kwargs['pack'],
                                                              name=kwargs['name'])

        # Validate criteria
        kwargs['criteria'] = dict(getattr(rule, 'criteria', {}))
        validator.validate_criteria(kwargs['criteria'])

        kwargs['action'] = ActionExecutionSpecDB(ref=rule.action['ref'],
                                                 parameters=rule.action.get('parameters', {}))

        rule_type = dict(getattr(rule, 'type', {}))
        if rule_type:
            kwargs['type'] = RuleTypeSpecDB(ref=rule_type['ref'],
                                            parameters=rule_type.get('parameters', {}))

        kwargs['enabled'] = getattr(rule, 'enabled', False)
        kwargs['context'] = getattr(rule, 'context', dict())
        kwargs['tags'] = TagsHelper.to_model(getattr(rule, 'tags', []))
        kwargs['metadata_file'] = getattr(rule, 'metadata_file', None)

        model = cls.model(**kwargs)
        return model
开发者ID:nzlosh,项目名称:st2,代码行数:42,代码来源:rule.py


示例11: test_triggered_execution

    def test_triggered_execution(self):
        docs = {
            'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
            'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
            'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
            'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance'])}

        # Trigger an action execution.
        trigger_type = TriggerType.add_or_update(
            TriggerTypeAPI.to_model(TriggerTypeAPI(**docs['trigger_type'])))
        trigger = Trigger.add_or_update(TriggerAPI.to_model(TriggerAPI(**docs['trigger'])))
        rule = RuleAPI.to_model(RuleAPI(**docs['rule']))
        rule.trigger = reference.get_str_resource_ref_from_model(trigger)
        rule = Rule.add_or_update(rule)
        trigger_instance = TriggerInstance.add_or_update(
            TriggerInstanceAPI.to_model(TriggerInstanceAPI(**docs['trigger_instance'])))
        enforcer = RuleEnforcer(trigger_instance, rule)
        enforcer.enforce()

        # Wait for the action execution to complete and then confirm outcome.
        execution = ActionExecution.get(context__trigger_instance__id=str(trigger_instance.id))
        self.assertIsNotNone(execution)
        execution = ActionExecution.get_by_id(str(execution.id))
        self.assertEqual(execution.status, ACTIONEXEC_STATUS_SUCCEEDED)
        history = ActionExecutionHistory.get(execution__id=str(execution.id), raise_exception=True)
        self.assertDictEqual(history.trigger, vars(TriggerAPI.from_model(trigger)))
        self.assertDictEqual(history.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
        self.assertDictEqual(history.trigger_instance,
                             vars(TriggerInstanceAPI.from_model(trigger_instance)))
        self.assertDictEqual(history.rule, vars(RuleAPI.from_model(rule)))
        action_ref = ResourceReference.from_string_reference(ref=execution.action)
        action, _ = action_utils.get_action_by_dict(
            {'name': action_ref.name, 'pack': action_ref.pack})
        self.assertDictEqual(history.action, vars(ActionAPI.from_model(action)))
        runner = RunnerType.get_by_name(action.runner_type['name'])
        self.assertDictEqual(history.runner, vars(RunnerTypeAPI.from_model(runner)))
        execution = ActionExecution.get_by_id(str(execution.id))
        self.assertDictEqual(history.execution, vars(ActionExecutionAPI.from_model(execution)))
开发者ID:bjoernbessert,项目名称:st2,代码行数:38,代码来源:test_history.py


示例12: TriggerDB

MOCK_TRIGGER = TriggerDB(pack='dummy_pack_1', name='trigger-test.name', type='system.test')

MOCK_TRIGGER_INSTANCE = TriggerInstanceDB(trigger=MOCK_TRIGGER.get_reference().ref,
                                          occurrence_time=date_utils.get_datetime_utc_now(),
                                          payload={
                                              'p1': 'v1',
                                              'p2': 'preYYYpost',
                                              'bool': True,
                                              'int': 1,
                                              'float': 0.8})

MOCK_ACTION = ActionDB(id=bson.ObjectId(), pack='wolfpack', name='action-test-1.name')

MOCK_RULE_1 = RuleDB(id=bson.ObjectId(), pack='wolfpack', name='some1',
                     trigger=reference.get_str_resource_ref_from_model(MOCK_TRIGGER),
                     criteria={}, action=ActionExecutionSpecDB(ref="somepack.someaction"))

MOCK_RULE_2 = RuleDB(id=bson.ObjectId(), pack='wolfpack', name='some2',
                     trigger=reference.get_str_resource_ref_from_model(MOCK_TRIGGER),
                     criteria={}, action=ActionExecutionSpecDB(ref="somepack.someaction"))


@mock.patch.object(reference, 'get_model_by_resource_ref',
                   mock.MagicMock(return_value=MOCK_TRIGGER))
class FilterTest(DbTestCase):
    def test_empty_criteria(self):
        rule = MOCK_RULE_1
        rule.criteria = {}
        f = RuleFilter(MOCK_TRIGGER_INSTANCE, MOCK_TRIGGER, rule)
        self.assertTrue(f.filter(), 'equals check should have failed.')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:30,代码来源:test_filter.py


示例13: ActionDB

MOCK_TRIGGER_INSTANCE.trigger = reference.get_ref_from_model(MOCK_TRIGGER)
MOCK_TRIGGER_INSTANCE.payload = {}
MOCK_TRIGGER_INSTANCE.occurrence_time = datetime.datetime.utcnow()

MOCK_ACTION = ActionDB()
MOCK_ACTION.id = 'action-test-1.id'
MOCK_ACTION.name = 'action-test-1.name'

MOCK_ACTION_EXECUTION = ActionExecutionDB()
MOCK_ACTION_EXECUTION.id = 'actionexec-test-1.id'
MOCK_ACTION_EXECUTION.name = 'actionexec-test-1.name'
MOCK_ACTION_EXECUTION.status = 'scheduled'

MOCK_RULE_1 = RuleDB()
MOCK_RULE_1.id = 'rule-test-1'
MOCK_RULE_1.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_1.criteria = {}
MOCK_RULE_1.action = ActionExecutionSpecDB()
MOCK_RULE_1.action.ref = reference.get_ref_from_model(MOCK_ACTION)
MOCK_RULE_1.enabled = True

MOCK_RULE_2 = RuleDB()
MOCK_RULE_2.id = 'rule-test-2'
MOCK_RULE_2.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_2.criteria = {}
MOCK_RULE_2.action = ActionExecutionSpecDB()
MOCK_RULE_2.action.ref = reference.get_ref_from_model(MOCK_ACTION)
MOCK_RULE_2.enabled = True


class EnforceTest(unittest2.TestCase):
开发者ID:bjoernbessert,项目名称:st2,代码行数:31,代码来源:test_enforce.py


示例14: _get_sample_rules

    def _get_sample_rules(self):
        rules = []

        RULE_1 = {
            'enabled': True,
            'name': 'st2.test.rule1',
            'trigger': {
                'type': 'dummy_pack_1.st2.test.trigger1'
            },
            'criteria': {
                'k1': {                     # Missing prefix 'trigger'. This rule won't match.
                    'pattern': 't1_p_v',
                    'type': 'equals'
                }
            },
            'action': {
                'ref': 'sixpack.st2.test.action',
                'parameters': {
                    'ip2': '{{rule.k1}}',
                    'ip1': '{{trigger.t1_p}}'
                }
            },
            'id': '23',
            'description': ''
        }
        rule_api = RuleAPI(**RULE_1)
        rule_db = RuleAPI.to_model(rule_api)
        trigger_api = TriggerAPI(**rule_api.trigger)
        trigger_db = TriggerService.create_trigger_db(trigger_api)
        trigger_ref = reference.get_str_resource_ref_from_model(trigger_db)
        rule_db.trigger = trigger_ref
        rule_db = Rule.add_or_update(rule_db)
        rules.append(rule_db)

        RULE_2 = {                      # Rule should match.
            'enabled': True,
            'name': 'st2.test.rule2',
            'trigger': {
                'type': 'dummy_pack_1.st2.test.trigger1'
            },
            'criteria': {
                'trigger.k1': {
                    'pattern': 't1_p_v',
                    'type': 'equals'
                }
            },
            'action': {
                'ref': 'sixpack.st2.test.action',
                'parameters': {
                    'ip2': '{{rule.k1}}',
                    'ip1': '{{trigger.t1_p}}'
                }
            },
            'id': '23',
            'description': ''
        }
        rule_api = RuleAPI(**RULE_2)
        rule_db = RuleAPI.to_model(rule_api)
        rule_db.trigger = trigger_ref
        rule_db = Rule.add_or_update(rule_db)
        rules.append(rule_db)

        RULE_3 = {
            'enabled': False,         # Disabled rule shouldn't match.
            'name': 'st2.test.rule3',
            'trigger': {
                'type': 'dummy_pack_1.st2.test.trigger1'
            },
            'criteria': {
                'trigger.k1': {
                    'pattern': 't1_p_v',
                    'type': 'equals'
                }
            },
            'action': {
                'ref': 'sixpack.st2.test.action',
                'parameters': {
                    'ip2': '{{rule.k1}}',
                    'ip1': '{{trigger.t1_p}}'
                }
            },
            'id': '23',
            'description': ''
        }
        rule_api = RuleAPI(**RULE_3)
        rule_db = RuleAPI.to_model(rule_api)
        rule_db.trigger = trigger_ref
        rule_db = Rule.add_or_update(rule_db)
        rules.append(rule_db)

        return rules
开发者ID:bjoernbessert,项目名称:st2,代码行数:91,代码来源:test_rule_matcher.py



注:本文中的st2common.util.reference.get_str_resource_ref_from_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python schema.get_validator函数代码示例发布时间:2022-05-27
下一篇:
Python param.get_finalized_params函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap