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({ 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) } }) 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, six.text_type(e))) raise action_exc.ParameterRenderingFailedException(msg) return rendered_result
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
def _get_rendered_vars(vars, action_parameters): if not vars: return {} context = {} context.update({ kv_constants.DATASTORE_PARENT_SCOPE: { kv_constants.SYSTEM_SCOPE: kv_service.KeyValueLookup( scope=kv_constants.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)
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)
def inject_immutable_parameters(action_alias_db, multiple_execution_parameters, action_context): """ Inject immutable parameters from the alias definiton on the execution parameters. Jinja expressions will be resolved. """ immutable_parameters = action_alias_db.immutable_parameters or {} if not immutable_parameters: return multiple_execution_parameters user = action_context.get("user", None) 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_context) rendered_params = render_values(immutable_parameters, context) for exec_params in multiple_execution_parameters: overriden = [ param for param in immutable_parameters.keys() if param in exec_params ] if overriden: raise ValueError( "Immutable arguments cannot be overriden: {}".format( ",".join(overriden))) exec_params.update(rendered_params) return multiple_execution_parameters