~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/parser/functions/fqdn_rand.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc => 
2
 
    "Generates random numbers based on the node's fqdn. The first argument 
3
 
    sets the range.  The second argument specifies a number to add to the 
4
 
    seed and is optional.") do |args|
 
1
Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
 
2
    "Generates random numbers based on the node's fqdn. The first argument
 
3
    sets the range.  Additional (optional) arguments may be used to further 
 
4
    distinguish the seed.") do |args|
5
5
        require 'md5'
6
 
        max = args[0]
7
 
        if args[1] then
8
 
             seed = args[1]
9
 
        else
10
 
             seed = 1
11
 
        end
12
 
        fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex
13
 
        srand(seed+fqdn_seed)
 
6
        max = args.shift
 
7
        srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
14
8
        rand(max).to_s
15
9
end