HOT intrinisic function list_join like Fn::Join

We have an increasing number of attributes which are a list of strings.

In HOT there is no way to join a list into a string as with the CFN
function Fn::Join.

This change implements HOT intrinsic function list_join using an
identical implementation as Fn::Join.

Tripleo will benefit from this function since the lack of a join
function in HOT is one of the barriers to transitioning to the
HOT template format.

Change-Id: I29e0b744271213429fff6922397b925eb9ccc204
This commit is contained in:
Steve Baker 2014-06-26 16:55:32 +12:00
parent 30e416324e
commit 1e8e0fcc46
3 changed files with 38 additions and 3 deletions

View File

@ -726,6 +726,26 @@ The *resource ID* of the referenced resources as used in the current template is
given as single parameter to the get_resource function. given as single parameter to the get_resource function.
list_join
--------
The *list_join* function joins a list of strings with the given delimiter.
The syntax of the list_join function is as follows:
::
list_join:
- <delimiter>
- <list to join>
A sample use of this function with a simple list is shown below.
::
list_join: [', ', ['one', 'two', 'and three']]
This would resolve to "one, two, and three".
resource_facade resource_facade
--------------- ---------------
The *resource_facade* function allows a provider template to retrieve data The *resource_facade* function allows a provider template to retrieve data

View File

@ -202,6 +202,20 @@ class GetFile(function.Function):
return f return f
class Join(cfn_funcs.Join):
'''
A function for joining strings.
Takes the form::
{ "list_join" : [ "<delim>", [ "<string_1>", "<string_2>", ... ] }
And resolves to::
"<string_1><delim><string_2><delim>..."
'''
class ResourceFacade(cfn_funcs.ResourceFacade): class ResourceFacade(cfn_funcs.ResourceFacade):
''' '''
A function for obtaining data from the facade resource from within the A function for obtaining data from the facade resource from within the
@ -235,6 +249,7 @@ def function_mapping(version_key, version):
'get_attr': GetAtt, 'get_attr': GetAtt,
'Fn::Select': cfn_funcs.Select, 'Fn::Select': cfn_funcs.Select,
'Fn::Join': cfn_funcs.Join, 'Fn::Join': cfn_funcs.Join,
'list_join': Join,
'Fn::Split': cfn_funcs.Split, 'Fn::Split': cfn_funcs.Split,
'str_replace': Replace, 'str_replace': Replace,
'Fn::Replace': cfn_funcs.Replace, 'Fn::Replace': cfn_funcs.Replace,

View File

@ -17,10 +17,10 @@ import six
from heat.common import exception from heat.common import exception
from heat.common import identifier from heat.common import identifier
from heat.common import template_format from heat.common import template_format
from heat.engine.cfn import functions as cfn_funcs
from heat.engine import constraints from heat.engine import constraints
from heat.engine import environment from heat.engine import environment
from heat.engine import function from heat.engine import function
from heat.engine.hot import functions as hot_functions
from heat.engine.hot import parameters as hot_param from heat.engine.hot import parameters as hot_param
from heat.engine.hot import template as hot_template from heat.engine.hot import template as hot_template
from heat.engine import parameters from heat.engine import parameters
@ -585,8 +585,8 @@ class HOTemplateTest(HeatTestCase):
parent_resource.stack = parser.Stack(utils.dummy_context(), parent_resource.stack = parser.Stack(utils.dummy_context(),
'toplevel_stack', 'toplevel_stack',
parser.Template(hot_tpl_empty)) parser.Template(hot_tpl_empty))
del_policy = cfn_funcs.Join(parent_resource.stack, del_policy = hot_functions.Join(parent_resource.stack,
'Fn::Join', ['eta', ['R', 'in']]) 'list_join', ['eta', ['R', 'in']])
parent_resource.t = rsrc_defn.ResourceDefinition( parent_resource.t = rsrc_defn.ResourceDefinition(
'parent', 'SomeType', 'parent', 'SomeType',
deletion_policy=del_policy) deletion_policy=del_policy)