summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-03-30 13:02:19 -0700
committerMax Martin <max@puppetlabs.com>2011-03-30 13:02:19 -0700
commit9c06fbd762cddcc41a7185a36f2a8e72879125eb (patch)
treebfd37ac5887307857d0b0d79a1db034010eed424 /lib/puppet/parser/functions
parent4196699f5fbb90ceecbb709c8502622eaad39062 (diff)
parent11309a214148abb2167c1bd0adba0e035b2d8384 (diff)
downloadpuppet-9c06fbd762cddcc41a7185a36f2a8e72879125eb.tar.gz
puppet-9c06fbd762cddcc41a7185a36f2a8e72879125eb.tar.xz
puppet-9c06fbd762cddcc41a7185a36f2a8e72879125eb.zip
Merge branch 'next'
* next: (39 commits) (#5908) Add support for new update-rc.d disable API (#6830) Fix tests that depended on special inherited behavior (#6830) Fix overly stubbed tests (#6830) Fix instance_variables now comes back as symbols (#6830) Fix badly stubbed Time object in test (#6830) Fix MD5 handling to work with Ruby 1.9 (#6830) Fix File class scoping (#6830) Handle case where array is actually a string (#6830) Fix case where instance_variables returns symbols in Ruby 1.9 (#6862) Add a default subject for the mail_patches rake task Fixed #6256 - Creation of rrd directory. (#6855) ResourceType#search now accepts a regex (#5477) Allow watch_file to watch non-existent files, especially site.pp (#5477) Allow watch_file to watch non-existent files, especially site.pp Fixing #6851 - ResourceType#find/search loads types Fixing Module#path detection Fixed #6850 - Clean up ResourceType#to_pson (#6830) Fix stat method calls to not use an unneeded argument (#4576) Raise an error when a node is classified into a non-existent class Update CHANGELOG for 2.6.7 ...
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/create_resources.rb47
-rw-r--r--lib/puppet/parser/functions/fqdn_rand.rb4
2 files changed, 49 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/create_resources.rb b/lib/puppet/parser/functions/create_resources.rb
new file mode 100644
index 000000000..430f110b4
--- /dev/null
+++ b/lib/puppet/parser/functions/create_resources.rb
@@ -0,0 +1,47 @@
+Puppet::Parser::Functions::newfunction(:create_resources, :doc => '
+Converts a hash into a set of resources and adds them to the catalog.
+Takes two parameters:
+ create_resource($type, $resources)
+ Creates resources of type $type from the $resources hash. Assumes that
+ hash is in the following form:
+ {title=>{parameters}}
+ This is currently tested for defined resources, classes, as well as native types
+') do |args|
+ raise ArgumentError, ("create_resources(): wrong number of arguments (#{args.length}; must be 2)") if args.length != 2
+ #raise ArgumentError, 'requires resource type and param hash' if args.size < 2
+ # figure out what kind of resource we are
+ type_of_resource = nil
+ type_name = args[0].downcase
+ if type_name == 'class'
+ type_of_resource = :class
+ else
+ if resource = Puppet::Type.type(type_name.to_sym)
+ type_of_resource = :type
+ elsif resource = find_definition(type_name.downcase)
+ type_of_resource = :define
+ else
+ raise ArgumentError, "could not create resource of unknown type #{type_name}"
+ end
+ end
+ # iterate through the resources to create
+ args[1].each do |title, params|
+ raise ArgumentError, 'params should not contain title' if(params['title'])
+ case type_of_resource
+ when :type
+ res = resource.hash2resource(params.merge(:title => title))
+ catalog.add_resource(res)
+ when :define
+ p_resource = Puppet::Parser::Resource.new(type_name, title, :scope => self, :source => resource)
+ params.merge(:name => title).each do |k,v|
+ p_resource.set_parameter(k,v)
+ end
+ resource.instantiate_resource(self, p_resource)
+ compiler.add_resource(self, p_resource)
+ when :class
+ klass = find_hostclass(title)
+ raise ArgumentError, "could not find hostclass #{title}" unless klass
+ klass.ensure_in_catalog(self, params)
+ compiler.catalog.add_class([title])
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb
index 52946f2c1..91157a148 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -5,8 +5,8 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
$random_number = fqdn_rand(30)
$random_number_seed = fqdn_rand(30,30)") do |args|
- require 'md5'
+ require 'digest/md5'
max = args.shift
- srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
+ srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex)
rand(max).to_s
end