本文整理汇总了Python中st2common.persistence.rule.Rule.query方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.query方法的具体用法?Python Rule.query怎么用?Python Rule.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.rule.Rule
的用法示例。
在下文中一共展示了Rule.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
def test_run(self):
pack = 'dummy_pack_1'
# Verify all the resources are there
pack_dbs = Pack.query(ref=pack)
action_dbs = Action.query(pack=pack)
alias_dbs = ActionAlias.query(pack=pack)
rule_dbs = Rule.query(pack=pack)
sensor_dbs = Sensor.query(pack=pack)
trigger_type_dbs = TriggerType.query(pack=pack)
policy_dbs = Policy.query(pack=pack)
config_schema_dbs = ConfigSchema.query(pack=pack)
config_dbs = Config.query(pack=pack)
self.assertEqual(len(pack_dbs), 1)
self.assertEqual(len(action_dbs), 1)
self.assertEqual(len(alias_dbs), 2)
self.assertEqual(len(rule_dbs), 1)
self.assertEqual(len(sensor_dbs), 3)
self.assertEqual(len(trigger_type_dbs), 4)
self.assertEqual(len(policy_dbs), 2)
self.assertEqual(len(config_schema_dbs), 1)
self.assertEqual(len(config_dbs), 1)
# Run action
action = self.get_action_instance()
action.run(packs=[pack])
# Make sure all resources have been removed from the db
pack_dbs = Pack.query(ref=pack)
action_dbs = Action.query(pack=pack)
alias_dbs = ActionAlias.query(pack=pack)
rule_dbs = Rule.query(pack=pack)
sensor_dbs = Sensor.query(pack=pack)
trigger_type_dbs = TriggerType.query(pack=pack)
policy_dbs = Policy.query(pack=pack)
config_schema_dbs = ConfigSchema.query(pack=pack)
config_dbs = Config.query(pack=pack)
self.assertEqual(len(pack_dbs), 0)
self.assertEqual(len(action_dbs), 0)
self.assertEqual(len(alias_dbs), 0)
self.assertEqual(len(rule_dbs), 0)
self.assertEqual(len(sensor_dbs), 0)
self.assertEqual(len(trigger_type_dbs), 0)
self.assertEqual(len(policy_dbs), 0)
self.assertEqual(len(config_schema_dbs), 0)
self.assertEqual(len(config_dbs), 0)
示例2: test_rule_lookup
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
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])
示例3: test_rule_lookup_disabled
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
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])
示例4: get_matching_rules_for_trigger
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
def get_matching_rules_for_trigger(self, trigger_instance):
trigger = trigger_instance.trigger
trigger = get_trigger_db_by_ref(trigger_instance.trigger)
rules = Rule.query(trigger=trigger_instance.trigger, enabled=True)
LOG.info('Found %d rules defined for trigger %s (type=%s)', len(rules), trigger['name'],
trigger['type'])
matcher = RulesMatcher(trigger_instance=trigger_instance,
trigger=trigger, rules=rules)
matching_rules = matcher.get_matching_rules()
LOG.info('Matched %s rule(s) for trigger_instance %s (type=%s)', len(matching_rules),
trigger['name'], trigger['type'])
return matching_rules
示例5: get_rules_with_trigger_ref
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
def get_rules_with_trigger_ref(trigger_ref=None, enabled=True):
"""
Get rules in DB corresponding to given trigger_ref as a string reference.
:param trigger_ref: Reference to trigger.
:type trigger_ref: ``str``
:rtype: ``list`` of ``RuleDB``
"""
if not trigger_ref:
return None
LOG.debug('Querying rules with trigger %s', trigger_ref)
return Rule.query(trigger=trigger_ref, enabled=enabled)
示例6: analyze
# 需要导入模块: from st2common.persistence.rule import Rule [as 别名]
# 或者: from st2common.persistence.rule.Rule import query [as 别名]
def analyze(self, root_action_ref, link_tigger_ref):
rules = Rule.query(trigger=link_tigger_ref, enabled=True)
# pprint.pprint([rule.ref for rule in rules])
for rule in rules:
source_action_ref = self._get_source_action_ref(rule)
if not source_action_ref:
print('No source_action_ref for rule %s' % rule.ref)
continue
rule_links = self._rules.get(source_action_ref, None)
if rule_links is None:
rule_links = []
self._rules[source_action_ref] = rule_links
rule_links.append(RuleLink(source_action_ref=source_action_ref, rule_ref=rule.ref,
dest_action_ref=rule.action.ref))
analyzed = self._do_analyze(action_ref=root_action_ref)
for (depth, rule_link) in analyzed:
print('%s%s' % (' ' * depth, rule_link))
return analyzed