本文整理汇总了Python中st2common.models.api.trigger.TriggerAPI.to_model方法的典型用法代码示例。如果您正苦于以下问题:Python TriggerAPI.to_model方法的具体用法?Python TriggerAPI.to_model怎么用?Python TriggerAPI.to_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.trigger.TriggerAPI
的用法示例。
在下文中一共展示了TriggerAPI.to_model方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_or_update_trigger_db
# 需要导入模块: from st2common.models.api.trigger import TriggerAPI [as 别名]
# 或者: from st2common.models.api.trigger.TriggerAPI import to_model [as 别名]
def create_or_update_trigger_db(trigger):
"""
Create a new TriggerDB model if one doesn't exist yet or update existing
one.
:param trigger: Trigger info.
:type trigger: ``dict``
"""
assert isinstance(trigger, dict)
existing_trigger_db = _get_trigger_db(trigger)
if existing_trigger_db:
is_update = True
else:
is_update = False
trigger_api = TriggerAPI(**trigger)
trigger_api.validate()
trigger_db = TriggerAPI.to_model(trigger_api)
if is_update:
trigger_db.id = existing_trigger_db.id
trigger_db = Trigger.add_or_update(trigger_db)
extra = {'trigger_db': trigger_db}
if is_update:
LOG.audit('Trigger updated. Trigger.id=%s' % (trigger_db.id), extra=extra)
else:
LOG.audit('Trigger created. Trigger.id=%s' % (trigger_db.id), extra=extra)
return trigger_db
示例2: create_trigger_db
# 需要导入模块: from st2common.models.api.trigger import TriggerAPI [as 别名]
# 或者: from st2common.models.api.trigger.TriggerAPI import to_model [as 别名]
def create_trigger_db(trigger_api):
# TODO: This is used only in trigger API controller. We should get rid of this.
trigger_ref = ResourceReference.to_string_reference(name=trigger_api.name, pack=trigger_api.pack)
trigger_db = get_trigger_db_by_ref(trigger_ref)
if not trigger_db:
trigger_db = TriggerAPI.to_model(trigger_api)
LOG.debug("Verified trigger and formulated TriggerDB=%s", trigger_db)
trigger_db = Trigger.add_or_update(trigger_db)
return trigger_db
示例3: test_triggered_execution
# 需要导入模块: from st2common.models.api.trigger import TriggerAPI [as 别名]
# 或者: from st2common.models.api.trigger.TriggerAPI import to_model [as 别名]
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)
示例4: put
# 需要导入模块: from st2common.models.api.trigger import TriggerAPI [as 别名]
# 或者: from st2common.models.api.trigger.TriggerAPI import to_model [as 别名]
def put(self, trigger, trigger_id):
trigger_db = TriggerController.__get_by_id(trigger_id)
try:
if trigger.id is not None and trigger.id != '' and trigger.id != trigger_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
trigger.id, trigger_id)
trigger_db = TriggerAPI.to_model(trigger)
trigger_db.id = trigger_id
trigger_db = Trigger.add_or_update(trigger_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for trigger data=%s', trigger)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_trigger_db': trigger, 'new_trigger_db': trigger_db}
LOG.audit('Trigger updated. Trigger.id=%s' % (trigger.id), extra=extra)
trigger_api = TriggerAPI.from_model(trigger_db)
return trigger_api