summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-25 16:00:48 -0500
committerLuke Kanies <luke@madstop.com>2008-05-25 16:00:48 -0500
commit29f5f1b862112179ce1b77ae0177811ab2208aeb (patch)
tree5938a8df29fd6cf8182f6e12f28956ebeff2732c /lib/puppet/parser/functions.rb
parentfe157f239a301abb52f81c62719355c8e50c970c (diff)
parent7b02f2ba443ba35d7305c24b87028456eaf6bd29 (diff)
downloadpuppet-29f5f1b862112179ce1b77ae0177811ab2208aeb.tar.gz
puppet-29f5f1b862112179ce1b77ae0177811ab2208aeb.tar.xz
puppet-29f5f1b862112179ce1b77ae0177811ab2208aeb.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG lib/puppet/transaction.rb
Diffstat (limited to 'lib/puppet/parser/functions.rb')
-rw-r--r--lib/puppet/parser/functions.rb16
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