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('localinfo')
10 allnodeinfo = lookupvar('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']['name']
35 if provider.include?(fqdn) # if the host has an ekeyd
37 elsif hoster[consumer_hoster] # if there are any at the same hoster, use one of them
38 # if there are more than one ekeys at this hoster pick an arbitrary
39 # one, but the same every time
40 index = fqdn.hash % hoster[consumer_hoster].length
41 ans = hoster[consumer_hoster][index]
42 else # pick an arbitrary provider from all providers
43 index = fqdn.hash % provider.size
49 raise Puppet::ParseError, "Error in entropy_provider: #{e.message}\n#{e.backtrace}"
55 # vim:set shiftwidth=2: