当前位置: 首页>>代码示例>>Python>>正文


Python ActionAlias.query方法代码示例

本文整理汇总了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)
开发者ID:lyandut,项目名称:st2,代码行数:54,代码来源:test_action_unload.py

示例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]
开发者ID:lyandut,项目名称:st2,代码行数:40,代码来源:actionalias_matching.py


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