From 9decf35a304a444a855a9d16d6d945ca89beb6cc Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 24 May 2008 10:18:28 +1000 Subject: Put function in ticket #311 in correct location --- lib/puppet/parser/functions.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 -- cgit