本文整理汇总了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
示例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)
示例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
示例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
示例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
示例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'))