diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-05-24 10:18:28 +1000 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-05-24 10:18:28 +1000 |
commit | 9decf35a304a444a855a9d16d6d945ca89beb6cc (patch) | |
tree | 968e62c8fb3c0f3c6d7b2b6bc0e11e195bc2a452 | |
parent | 6c3e7e1b547ba2040e8ff5d5011605c1df7c4681 (diff) | |
download | puppet-9decf35a304a444a855a9d16d6d945ca89beb6cc.tar.gz puppet-9decf35a304a444a855a9d16d6d945ca89beb6cc.tar.xz puppet-9decf35a304a444a855a9d16d6d945ca89beb6cc.zip |
Put function in ticket #311 in correct location
-rw-r--r-- | lib/puppet/parser/functions.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 93991275c..8decb8227 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -188,6 +188,22 @@ module Functions result end + newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random + numbers based on the node's fqdn. The first argument sets the range. + The second argument specifies a number to add to the seed and is + optional.") do |args| + require 'md5' + max = args[0] + if args[1] then + seed = args[1] + else + seed = 1 + end + fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex + srand(seed+fqdn_seed) + rand(max).to_s + end + newfunction(:fail, :doc => "Fail with a parse error.") do |vals| vals = vals.collect { |s| s.to_s }.join(" ") if vals.is_a? Array raise Puppet::ParseError, vals.to_s |