本文整理汇总了Python中st2common.persistence.actionalias.ActionAlias.query方法的典型用法代码示例。如果您正苦于以下问题:Python ActionAlias.query方法的具体用法?Python ActionAlias.query怎么用?Python ActionAlias.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.actionalias.ActionAlias
的用法示例。
在下文中一共展示了ActionAlias.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias 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: get_matching_alias
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import query [as 别名]
def get_matching_alias(command):
"""
Find a matching ActionAliasDB object (if any) for the provided command.
"""
# 1. Get aliases
action_alias_dbs = ActionAlias.query(
Q(formats__match_multiple=None) | Q(formats__match_multiple=False),
enabled=True)
# 2. Match alias(es) to command
matches = match_command_to_alias(command=command, aliases=action_alias_dbs)
if len(matches) > 1:
raise ActionAliasAmbiguityException("Command '%s' matched more than 1 pattern" %
command,
matches=matches,
command=command)
elif len(matches) == 0:
match_multiple_action_alias_dbs = ActionAlias.query(
formats__match_multiple=True,
enabled=True)
matches = match_command_to_alias(command=command, aliases=match_multiple_action_alias_dbs,
match_multiple=True)
if len(matches) > 1:
raise ActionAliasAmbiguityException("Command '%s' matched more than 1 (multi) pattern" %
command,
matches=matches,
command=command)
if len(matches) == 0:
raise ActionAliasAmbiguityException("Command '%s' matched no patterns" %
command,
matches=[],
command=command)
return matches[0]