diff options
author | Jeff McCune <jeff@puppetlabs.com> | 2013-01-09 17:52:41 -0800 |
---|---|---|
committer | Jeff McCune <jeff@puppetlabs.com> | 2013-01-09 17:52:41 -0800 |
commit | 3118e642dc9ec460b5c2e5220bed3b54c977f27c (patch) | |
tree | 85d283d806ded7d21a02c0fda4ce8df7ebc9906f /lib/puppet/parser | |
parent | d674190d8e160b74250c514775003569b36d9984 (diff) | |
parent | 20e0e0709021b7ba4a819f1324526d98bcb5dcc3 (diff) |
Merge branch 'offlinehacker-feature/master/getparam_function'
* offlinehacker-feature/master/getparam_function:
Add getparam function to get defined resource parameters
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/functions/getparam.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/getparam.rb b/lib/puppet/parser/functions/getparam.rb new file mode 100644 index 0000000..0962656 --- /dev/null +++ b/lib/puppet/parser/functions/getparam.rb @@ -0,0 +1,33 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:getparam, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and name of the parameter and +returns value of resource's parameter. + +*Examples:* + + define example_resource($param) { + } + + example_resource { "example_resource_instance": + param => "param_value" + } + + getparam(Example_resource["example_resource_instance"], "param") + +Would return: param_value +ENDOFDOC +) do |vals| + reference, param = vals + raise(ArgumentError, 'Must specify a reference') unless reference + raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String + + if resource = findresource(reference.to_s) + return resource[param] if resource[param] + end + + return '' +end |