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


Python ResourceReference.is_resource_reference方法代码示例

本文整理汇总了Python中st2common.models.system.common.ResourceReference.is_resource_reference方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceReference.is_resource_reference方法的具体用法?Python ResourceReference.is_resource_reference怎么用?Python ResourceReference.is_resource_reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.models.system.common.ResourceReference的用法示例。


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

示例1: _get_by_ref_or_id

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
    def _get_by_ref_or_id(self, ref_or_id, exclude_fields=None, include_fields=None):
        """
        Retrieve resource object by an id of a reference.

        Note: This method throws StackStormDBObjectNotFoundError exception if the object is not
        found in the database.
        """

        if exclude_fields and include_fields:
            msg = ('exclude_fields and include_fields arguments are mutually exclusive. '
                   'You need to provide either one or another, but not both.')
            raise ValueError(msg)

        if ResourceReference.is_resource_reference(ref_or_id):
            # references always contain a dot and id's can't contain it
            is_reference = True
        else:
            is_reference = False

        if is_reference:
            resource_db = self._get_by_ref(resource_ref=ref_or_id, exclude_fields=exclude_fields,
                                          include_fields=include_fields)
        else:
            resource_db = self._get_by_id(resource_id=ref_or_id, exclude_fields=exclude_fields,
                                          include_fields=include_fields)

        if not resource_db:
            msg = 'Resource with a reference or id "%s" not found' % (ref_or_id)
            raise StackStormDBObjectNotFoundError(msg)

        return resource_db
开发者ID:lyandut,项目名称:st2,代码行数:33,代码来源:resource.py

示例2: _transform_action

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
def _transform_action(name, spec):

    action_key, input_key = None, None

    for spec_type, spec_meta in six.iteritems(SPEC_TYPES):
        if spec_meta['action_key'] in spec:
            action_key = spec_meta['action_key']
            input_key = spec_meta['input_key']
            break

    if not action_key:
        return

    if spec[action_key] == 'st2.callback':
        raise WorkflowDefinitionException('st2.callback is deprecated.')

    # Convert parameters that are inline (i.e. action: some_action var1={$.value1} var2={$.value2})
    # and split it to action name and input dict as illustrated below.
    #
    # action: some_action
    # input:
    #   var1: <% $.value1 %>
    #   var2: <% $.value2 %>
    #
    # This step to separate the action name and the input parameters is required
    # to wrap them with the st2.action proxy.
    #
    # action: st2.action
    # input:
    #   ref: some_action
    #   parameters:
    #     var1: <% $.value1 %>
    #     var2: <% $.value2 %>
    _eval_inline_params(spec, action_key, input_key)

    transformed = (spec[action_key] == 'st2.action')

    action_ref = spec[input_key]['ref'] if transformed else spec[action_key]

    action = None

    # Identify if action is a registered StackStorm action.
    if action_ref and ResourceReference.is_resource_reference(action_ref):
        action = action_utils.get_action_by_ref(ref=action_ref)

    # If action is a registered StackStorm action, then wrap the
    # action with the st2 proxy and validate the action input.
    if action:
        if not transformed:
            spec[action_key] = 'st2.action'
            action_input = spec.get(input_key)
            spec[input_key] = {'ref': action_ref}
            if action_input:
                spec[input_key]['parameters'] = action_input

        action_input = spec.get(input_key, {})
        action_params = action_input.get('parameters', {})
        _validate_action_parameters(name, action, action_params)
开发者ID:jspittman,项目名称:st2,代码行数:60,代码来源:mistral.py

示例3: _transform_action

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
def _transform_action(spec, action_key, input_key):

    if action_key not in spec or spec.get(action_key) == 'st2.action':
        return

    if spec.get(action_key) == 'st2.callback':
        raise Exception('st2.callback is deprecated.')

    # Convert parameters that are inline (i.e. action: some_action var1={$.value1} var2={$.value2})
    # and split it to action name and input dict as illustrated below.
    #
    # action: some_action
    # input:
    #   var1: <% $.value1 %>
    #   var2: <% $.value2 %>
    #
    # This step to separate the action name and the input parameters is required
    # to wrap them with the st2.action proxy.
    #
    # action: st2.action
    # input:
    #   ref: some_action
    #   parameters:
    #     var1: <% $.value1 %>
    #     var2: <% $.value2 %>
    _eval_inline_params(spec, action_key, input_key)

    action_ref = spec.get(action_key)

    if action_ref and ResourceReference.is_resource_reference(action_ref):
        ref = ResourceReference.from_string_reference(ref=action_ref)
        actions = Action.query(name=ref.name, pack=ref.pack)
        action = actions.first() if actions else None
    else:
        action = None

    if action:
        spec[action_key] = 'st2.action'
        action_input = spec.get(input_key)
        spec[input_key] = {'ref': action_ref}
        if action_input:
            spec[input_key]['parameters'] = action_input
开发者ID:ruslantum,项目名称:st2,代码行数:44,代码来源:utils.py

示例4: _get_by_ref_or_id

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
    def _get_by_ref_or_id(self, ref_or_id):
        """
        Retrieve resource object by an id of a reference.
        """

        if ResourceReference.is_resource_reference(ref_or_id):
            # references always contain a dot and id's can't contain it
            is_reference = True
        else:
            is_reference = False

        if is_reference:
            resource_db = self._get_by_ref(resource_ref=ref_or_id)
        else:
            resource_db = self._get_by_id(resource_id=ref_or_id)

        if not resource_db:
            msg = 'Resource with a reference of id "%s" not found' % (ref_or_id)
            raise Exception(msg)

        return resource_db
开发者ID:ojacques,项目名称:st2,代码行数:23,代码来源:resource.py

示例5: _get_by_ref_or_id

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
    def _get_by_ref_or_id(self, ref_or_id, exclude_fields=None):
        """
        Retrieve resource object by an id of a reference.

        Note: This method throws StackStormDBObjectNotFoundError exception if the object is not
        found in the database.
        """

        if ResourceReference.is_resource_reference(ref_or_id):
            # references always contain a dot and id's can't contain it
            is_reference = True
        else:
            is_reference = False

        if is_reference:
            resource_db = self._get_by_ref(resource_ref=ref_or_id, exclude_fields=exclude_fields)
        else:
            resource_db = self._get_by_id(resource_id=ref_or_id, exclude_fields=exclude_fields)

        if not resource_db:
            msg = 'Resource with a reference or id "%s" not found' % (ref_or_id)
            raise StackStormDBObjectNotFoundError(msg)

        return resource_db
开发者ID:tonybaloney,项目名称:st2,代码行数:26,代码来源:resource.py

示例6: test_is_resource_reference

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import is_resource_reference [as 别名]
 def test_is_resource_reference(self):
     self.assertTrue(ResourceReference.is_resource_reference('foo.bar'))
     self.assertTrue(ResourceReference.is_resource_reference('foo.bar.ponies'))
     self.assertFalse(ResourceReference.is_resource_reference('foo'))
开发者ID:StackStorm,项目名称:st2,代码行数:6,代码来源:test_resource_reference.py


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