puppet-tripleo/lib/puppet/functions/list_to_hash.rb
Alex Schultz 4a576293c1 Update parser functions to 4.x api
This change updates additional parser functions we have to use teh
puppet 4.x function api.  This includes some basic unit tests to ensure
they continue to function as expected.

Change-Id: Iebeb82b2890216bed139219441718fffc4004391
Related-Bug: #1799786
2018-10-29 14:26:54 +00:00

32 lines
838 B
Ruby

# This function is an hack because we are not enabling Puppet parser
# that would allow us to manipulate data iterations directly in manifests.
#
# Example:
# keystone_vips = ['192.168.0.1:5000', '192.168.0.2:5000']
# $keystone_bind_opts = ['transparent']
#
# Using this function:
# $keystone_vips_hash = list_to_hash($keystone_vips, $keystone_bind_opts)
#
# Would return:
# $keystone_vips_hash = {
# '192.168.0.1:5000' => ['transparent'],
# '192.168.0.2:5000' => ['transparent'],
# }
#
# Disclaimer: this function is an hack and will disappear once TripleO enable
# Puppet parser.
#
Puppet::Functions.create_function(:list_to_hash) do
dispatch :list_to_hash do
param 'Array', :arr1
param 'Array', :arr2
end
def list_to_hash(arr1, arr2)
hh = arr1.each_with_object({}) { |v,h| h[v] = arr2 }
return hh
end
end