1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
60
61
62
63
64
65
66
|
# File 'lib/puppet/functions/kubeinstall/discovery_hosts.rb', line 1
Puppet::Functions.create_function(:'kubeinstall::discovery_hosts', Puppet::Functions::InternalFunction) do
dispatch :discovery_hosts_title do
scope_param
param 'String', :lookup_type
optional_param 'Array', :equery
end
dispatch :discovery_hosts_param do
scope_param
param 'String', :lookup_type
param 'String', :lookup_param
optional_param 'Array', :equery
end
dispatch :discovery_hosts_list do
scope_param
param 'String', :lookup_type
param 'Array[String]', :lookup_param
optional_param 'Array', :equery
end
def exported_collector_collect(scope, lookup_type, equery = nil)
resources = scope.compiler.resources.select { |r| r.type == lookup_type && r.exported? }
found = if Puppet[:storeconfigs]
Puppet::Resource.indirection.search(lookup_type, host: scope.compiler.node.name, filter: equery, scope: scope)
else
[]
end
found_resources = found.map { |x| x.is_a?(Puppet::Parser::Resource) ? x : x.to_resource(scope) }
found_resources.each do |item|
unless scope.findresource(item.resource_type, item.title)
resources << item
end
end
resources
end
def discovery_hosts_title(scope, lookup_type, equery = nil)
resources = exported_collector_collect(scope, lookup_type, equery)
resources.map { |r| r.title.to_s }
end
def discovery_hosts_param(scope, lookup_type, lookup_param, equery = nil)
resources = exported_collector_collect(scope, lookup_type, equery)
p = lookup_param.to_sym
resources.reject { |r| r[p].nil? }.map { |r| r[p].to_s }
end
def discovery_hosts_list(scope, lookup_type, lookup_param, equery = nil)
resources = exported_collector_collect(scope, lookup_type, equery)
p = lookup_param.map { |n| n.to_sym }
resources.map { |r| p.map { |n| (n == :title) ? r.title.to_s : r[n].to_s } }
.select { |r| r.any? } end
end
|