
The main issue with INI files, it doesn't support complex structures which end up being declared as strings. This approach get that chain of character and verify it's a valid JSON equivalent before assigning the value. Another driver is even though Hiera supports complex structure, we tend to keep it simple when using Hiera interpolations. https://wiki.openstack.org/wiki/SR-IOV-Passthrough-For-Networking#SR-IOV_Configuration Change-Id: I27d43af13fcc80f41a16c31a0a6cfe112dc96acb
28 lines
728 B
Ruby
28 lines
728 B
Ruby
require 'json'
|
|
|
|
def array_of_hash?(list)
|
|
return false unless !list.empty? && list.class == Array
|
|
list.each do |e|
|
|
return false unless e.class == Hash
|
|
end
|
|
true
|
|
end
|
|
|
|
module Puppet::Parser::Functions
|
|
newfunction(:check_array_of_hash, :arity =>1, :type => :rvalue, :doc => "Check
|
|
input String is a valid Array of Hash in JSON style") do |arg|
|
|
if arg[0].class == String
|
|
begin
|
|
list = JSON.load(arg[0].gsub("'","\""))
|
|
rescue JSON::ParserError
|
|
raise Puppet::ParseError, "Syntax error: #{arg[0]} is invalid"
|
|
else
|
|
return arg[0] if array_of_hash?(list)
|
|
end
|
|
else
|
|
raise Puppet::ParseError, "Syntax error: #{arg[0]} is not a String"
|
|
end
|
|
return ''
|
|
end
|
|
end
|