本文整理汇总了Python中st2common.util.jinja.render_values函数的典型用法代码示例。如果您正苦于以下问题:Python render_values函数的具体用法?Python render_values怎么用?Python render_values使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_values函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _resolve_params
def _resolve_params(action_node, original_parameters, results, chain_vars, chain_context):
# setup context with original parameters and the intermediate results.
context = {}
context.update(original_parameters)
context.update(results)
context.update(chain_vars)
context.update({RESULTS_KEY: results})
context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)})
context.update({
DATASTORE_PARENT_SCOPE: {
SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
}
})
context.update({ACTION_CONTEXT_KV_PREFIX: chain_context})
try:
rendered_params = jinja_utils.render_values(mapping=action_node.get_parameters(),
context=context)
except Exception as e:
LOG.exception('Jinja rendering for parameter "%s" failed.' % (e.key))
key = getattr(e, 'key', None)
value = getattr(e, 'value', None)
msg = ('Failed rendering value for action parameter "%s" in task "%s" '
'(template string=%s): %s') % (key, action_node.name, value, str(e))
raise ParameterRenderingFailedException(msg)
LOG.debug('Rendered params: %s: Type: %s', rendered_params, type(rendered_params))
return rendered_params
示例2: run
def run(self, execution_id):
execution = self._get_execution(execution_id)
context = {
'six': six,
'execution': execution
}
template = self.default_template
result = {}
alias_id = execution['context'].get('action_alias_ref', {}).get('id', None)
if alias_id:
alias = self.client.managers['ActionAlias'].get_by_id(alias_id)
context.update({
'alias': alias
})
result_params = getattr(alias, 'result', None)
if result_params:
if not result_params.get('enabled', True):
raise Exception("Output of this template is disabled.")
if 'format' in alias.result:
template = alias.result['format']
if 'extra' in alias.result:
result['extra'] = jinja_utils.render_values(alias.result['extra'], context)
result['message'] = self.jinja.from_string(template).render(context),
return result
示例3: test_render_values_skip_missing
def test_render_values_skip_missing(self):
actual = jinja_utils.render_values(
mapping={'k1': '{{a}}', 'k2': '{{b}}', 'k3': '{{c}}'},
context={'a': 'v1', 'b': 'v2'},
allow_undefined=True)
expected = {'k2': 'v2', 'k1': 'v1', 'k3': ''}
self.assertEqual(actual, expected)
示例4: _render_publish_vars
def _render_publish_vars(action_node, action_parameters, execution_result,
previous_execution_results, chain_vars):
"""
If no output is specified on the action_node the output is the entire execution_result.
If any output is specified then only those variables are published as output of an
execution of this action_node.
The output variable can refer to a variable from the execution_result,
previous_execution_results or chain_vars.
"""
if not action_node.publish:
return {}
context = {}
context.update(action_parameters)
context.update({action_node.name: execution_result})
context.update(previous_execution_results)
context.update(chain_vars)
context.update({RESULTS_KEY: previous_execution_results})
context.update({SYSTEM_KV_PREFIX: KeyValueLookup()})
try:
rendered_result = jinja_utils.render_values(mapping=action_node.publish,
context=context)
except Exception as e:
key = getattr(e, 'key', None)
value = getattr(e, 'value', None)
msg = ('Failed rendering value for publish parameter "%s" in task "%s" '
'(template string=%s): %s' % (key, action_node.name, value, str(e)))
raise ParameterRenderingFailedException(msg)
return rendered_result
示例5: __call__
def __call__(self, mapping):
context = copy.copy(self._payload_context)
context[SYSTEM_SCOPE] = KeyValueLookup(scope=SYSTEM_SCOPE)
context.update({
DATASTORE_PARENT_SCOPE: {
SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
}
})
return jinja_utils.render_values(mapping=mapping, context=context)
示例6: _resolve_params
def _resolve_params(action_node, original_parameters, results, chain_vars):
# setup context with original parameters and the intermediate results.
context = {}
context.update(original_parameters)
context.update(results)
context.update(chain_vars)
context.update({RESULTS_KEY: results})
context.update({SYSTEM_KV_PREFIX: KeyValueLookup()})
rendered_params = jinja_utils.render_values(mapping=action_node.params, context=context)
LOG.debug('Rendered params: %s: Type: %s', rendered_params, type(rendered_params))
return rendered_params
示例7: _get_rendered_vars
def _get_rendered_vars(vars, action_parameters):
if not vars:
return {}
context = {}
context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)})
context.update({
DATASTORE_PARENT_SCOPE: {
SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)
}
})
context.update(action_parameters)
return jinja_utils.render_values(mapping=vars, context=context)
示例8: _get_rendered_vars
def _get_rendered_vars(vars, action_parameters):
if not vars:
return {}
context = {}
context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)})
context.update({
DATASTORE_PARENT_SCOPE: {
SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
}
})
context.update(action_parameters)
LOG.info('Rendering action chain vars. Mapping = %s; Context = %s', vars, context)
return jinja_utils.render_values(mapping=vars, context=context)
示例9: _resolve_params
def _resolve_params(action_node, original_parameters, results, chain_vars, chain_context):
# setup context with original parameters and the intermediate results.
context = {}
context.update(original_parameters)
context.update(results)
context.update(chain_vars)
context.update({RESULTS_KEY: results})
context.update({SYSTEM_KV_PREFIX: KeyValueLookup()})
context.update({ACTION_KV_PREFIX: chain_context})
try:
rendered_params = jinja_utils.render_values(mapping=action_node.params,
context=context)
except Exception as e:
LOG.exception('Jinja rendering failed.')
raise ParameterRenderingFailedException(e)
LOG.debug('Rendered params: %s: Type: %s', rendered_params, type(rendered_params))
return rendered_params
示例10: _get_rendered_vars
def _get_rendered_vars(vars, action_parameters, action_context):
if not vars:
return {}
action_context = action_context or {}
user = action_context.get('user', cfg.CONF.system_user.user)
context = {}
context.update({
kv_constants.DATASTORE_PARENT_SCOPE: {
kv_constants.SYSTEM_SCOPE: kv_service.KeyValueLookup(
scope=kv_constants.FULL_SYSTEM_SCOPE),
kv_constants.USER_SCOPE: kv_service.UserKeyValueLookup(
scope=kv_constants.FULL_USER_SCOPE, user=user)
}
})
context.update(action_parameters)
LOG.info('Rendering action chain vars. Mapping = %s; Context = %s', vars, context)
return jinja_utils.render_values(mapping=vars, context=context)
示例11: _render_publish_vars
def _render_publish_vars(action_node, action_parameters, execution_result,
previous_execution_results, chain_vars):
"""
If no output is specified on the action_node the output is the entire execution_result.
If any output is specified then only those variables are published as output of an
execution of this action_node.
The output variable can refer to a variable from the execution_result,
previous_execution_results or chain_vars.
"""
if not action_node.publish:
return {}
context = {}
context.update(action_parameters)
context.update({action_node.name: execution_result})
context.update(previous_execution_results)
context.update(chain_vars)
context.update({RESULTS_KEY: previous_execution_results})
context.update({SYSTEM_KV_PREFIX: KeyValueLookup()})
rendered_result = jinja_utils.render_values(mapping=action_node.publish, context=context)
return rendered_result
示例12: _resolve_params
def _resolve_params(action_node, original_parameters, results, chain_vars, chain_context):
# setup context with original parameters and the intermediate results.
chain_parent = chain_context.get('parent', {})
pack = chain_parent.get('pack')
user = chain_parent.get('user')
config = get_config(pack, user)
context = {}
context.update(original_parameters)
context.update(results)
context.update(chain_vars)
context.update({RESULTS_KEY: results})
context.update({
kv_constants.SYSTEM_SCOPE: kv_service.KeyValueLookup(
scope=kv_constants.SYSTEM_SCOPE)
})
context.update({
kv_constants.DATASTORE_PARENT_SCOPE: {
kv_constants.SYSTEM_SCOPE: kv_service.KeyValueLookup(
scope=kv_constants.FULL_SYSTEM_SCOPE)
}
})
context.update({action_constants.ACTION_CONTEXT_KV_PREFIX: chain_context})
context.update({pack_constants.PACK_CONFIG_CONTEXT_KV_PREFIX: config})
try:
rendered_params = jinja_utils.render_values(mapping=action_node.get_parameters(),
context=context)
except Exception as e:
LOG.exception('Jinja rendering for parameter "%s" failed.' % (e.key))
key = getattr(e, 'key', None)
value = getattr(e, 'value', None)
msg = ('Failed rendering value for action parameter "%s" in task "%s" '
'(template string=%s): %s') % (key, action_node.name, value, six.text_type(e))
raise action_exc.ParameterRenderingFailedException(msg)
LOG.debug('Rendered params: %s: Type: %s', rendered_params, type(rendered_params))
return rendered_params
示例13: test_render_values_ascii_and_unicode_values
def test_render_values_ascii_and_unicode_values(self):
mapping = {
u'k_ascii': '{{a}}',
u'k_unicode': '{{b}}',
u'k_ascii_unicode': '{{c}}'}
context = {
'a': u'some ascii value',
'b': u'٩(̾●̮̮̃̾•̃̾)۶ ٩(̾●̮̮̃̾•̃̾)۶ ćšž',
'c': u'some ascii some ٩(̾●̮̮̃̾•̃̾)۶ ٩(̾●̮̮̃̾•̃̾)۶ '
}
expected = {
'k_ascii': u'some ascii value',
'k_unicode': u'٩(̾●̮̮̃̾•̃̾)۶ ٩(̾●̮̮̃̾•̃̾)۶ ćšž',
'k_ascii_unicode': u'some ascii some ٩(̾●̮̮̃̾•̃̾)۶ ٩(̾●̮̮̃̾•̃̾)۶ '
}
actual = jinja_utils.render_values(
mapping=mapping,
context=context,
allow_undefined=True)
self.assertEqual(actual, expected)
示例14: run
def run(self, execution_id):
execution = self._get_execution(execution_id)
context = {"six": six, "execution": execution}
template = self.default_template
result = {}
alias_id = execution["context"].get("action_alias_ref", {}).get("id", None)
if alias_id:
alias = self.client.managers["ActionAlias"].get_by_id(alias_id)
context.update({"alias": alias})
result_params = getattr(alias, "result", None)
if result_params:
if not result_params.get("enabled", True):
raise Exception("Output of this template is disabled.")
if "format" in alias.result:
template = alias.result["format"]
if "extra" in alias.result:
result["extra"] = jinja_utils.render_values(alias.result["extra"], context)
result["message"] = self.jinja.from_string(template).render(context)
return result
示例15: _get_rendered_vars
def _get_rendered_vars(vars):
if not vars:
return {}
context = {SYSTEM_KV_PREFIX: KeyValueLookup()}
return jinja_utils.render_values(mapping=vars, context=context)