fqdn_rand.patch
| parser/functions.rb 2008-05-21 18:19:15.000000000 +0000 | ||
|---|---|---|
| 301 | 301 |
end |
| 302 | 302 |
output |
| 303 | 303 |
end |
| 304 | ||
| 305 |
newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random numbers |
|
| 306 |
based on the node's fqdn. The first argument sets the range. The second |
|
| 307 |
argument specifies a number to add to the seed and is optional.") do |args| |
|
| 308 |
require 'md5' |
|
| 309 |
max = args[0] |
|
| 310 |
if args[1] then |
|
| 311 |
seed = args[1] |
|
| 312 |
else |
|
| 313 |
seed = 1 |
|
| 314 |
end |
|
| 315 |
fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex
|
|
| 316 |
srand(seed+fqdn_seed) |
|
| 317 |
rand(max).to_s |
|
| 318 |
end |
|
| 319 | ||
| 304 | 320 |
end |
| 305 | 321 |
end |