1 module Puppet::Parser::Functions
2 newfunction(:entropy_provider, :type => :rvalue) do |args|
4 require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb'
9 localinfo = lookupvar('site::localinfo')
10 allnodeinfo = lookupvar('site::allnodeinfo')
12 raise Puppet::ParseError, "entropy_provider: Cannot learn fqdn" unless fqdn
13 raise Puppet::ParseError, "entropy_provider: Cannot learn nodeinfo" unless nodeinfo
14 raise Puppet::ParseError, "entropy_provider: Cannot learn localinfo" unless localinfo
15 raise Puppet::ParseError, "entropy_provider: Cannot learn allnodeinfo" unless allnodeinfo
17 # find where all the entropy keys are
20 localinfo.keys.sort.each do |node|
21 next unless localinfo[node]['entropy_key']
23 addresses = allnodeinfo[node]['ipHostNumber']
24 thishoster = function_whohosts(addresses, "/etc/puppet/modules/debian-org/misc/hoster.yaml")
25 name = thishoster['name']
29 hoster[name] = [] unless hoster[name]
33 # figure out which entropy provider to use
34 consumer_hoster = nodeinfo['hoster']
35 consumer_hoster_name = nodeinfo['hoster']['name']
37 if consumer_hoster['entropy_provider_hoster'] and hoster[consumer_hoster['entropy_provider_hoster']]
38 # if we have a preferred entropy provider hoster for hosts at this one.
39 entropy_provider_hoster = consumer_hoster['entropy_provider_hoster']
40 elsif hoster[consumer_hoster_name]
41 # if there are any at the same hoster, use one of them
42 entropy_provider_hoster = consumer_hoster_name
44 entropy_provider_hoster = nil
47 if provider.include?(fqdn) # if the host has an ekeyd
49 elsif entropy_provider_hoster
50 # if there are more than one ekeys at this hoster pick an arbitrary
51 # one, but the same every time
52 index = fqdn.hash % hoster[entropy_provider_hoster].length
53 ans = hoster[entropy_provider_hoster][index]
54 else # pick an arbitrary provider from all providers
55 index = fqdn.hash % provider.size
61 raise Puppet::ParseError, "Error in entropy_provider: #{e.message}\n#{e.backtrace}"
67 # vim:set shiftwidth=2: