diff options
| author | Dan Bode <bodepd@gmail.com> | 2011-01-08 17:18:25 -0600 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-01-24 16:44:41 -0800 |
| commit | 18ca97b0d16fae149a1eab04c520421b5eb38969 (patch) | |
| tree | 043de05a8f0b30838c7beafdaa9e5678c312c341 /lib/puppet | |
| parent | 41090d3617d99f9eaa58df32be93f3d16467bc50 (diff) | |
| download | puppet-18ca97b0d16fae149a1eab04c520421b5eb38969.tar.gz puppet-18ca97b0d16fae149a1eab04c520421b5eb38969.tar.xz puppet-18ca97b0d16fae149a1eab04c520421b5eb38969.zip | |
(#5045) Adds support to resource/type to also accept a param hash
The params are added as attributes when the resource is created.
Also, even if the class already exists, if params are passed, we still try to create it.
Reviewed-by: Matt Robinson
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/resource/type.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index d40adc145..a31795a1b 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -143,18 +143,26 @@ class Puppet::Resource::Type # classes and nodes. No parameters are be supplied--if this is a # parameterized class, then all parameters take on their default # values. - def ensure_in_catalog(scope) + def ensure_in_catalog(scope, attributes=nil) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. - if resource = scope.catalog.resource(resource_type, name) + # we should not do this for classes with attributes + # if attributes are passed, we should still try to create the resource + # even if it exists so that we can fail + # this prevents us from being able to combine param classes with include + if resource = scope.catalog.resource(resource_type, name) and !attributes return resource end - resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) + if attributes + attributes.each do |k,v| + resource.set_parameter(k,v) + end + end instantiate_resource(scope, resource) scope.compiler.add_resource(scope, resource) resource |
