17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb', line 17
newfunction(:conftool, :type => :rvalue, :arity => -2) do |args|
case args.length
when 2
tags, type = *args
when 1
tags = args[0]
type = 'node'
end
if !tags.is_a?(Hash) || tags.empty?
raise Puppet::ParseError, "tags should be in hash format"
end
begin
selector = tags.map { |k, v| "#{k}=#{v}" }.join ","
result = []
data = function_generate(
[
'/usr/bin/confctl',
'--object-type', type,
'select', selector,
'get'
]
).chomp
if data.empty?
return []
end
data.split("\n").each do |line|
entry = JSON.load(line)
tags = entry.delete 'tags'
obj_name = entry.keys.pop
result.push({'name' => obj_name, 'tags' => tags, 'value' => entry[obj_name]})
end
result
rescue StandardError => e
raise Puppet::ParseError, "Unable to read data from conftool. Wrapped error is #{e}: #{e.message}"
end
end
|