concat_getparam.rb 970 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Test whether a given class or definition is defined
  2. require 'puppet/parser/functions'
  3. Puppet::Parser::Functions.newfunction(:concat_getparam,
  4. :type => :rvalue,
  5. :doc => <<-'ENDOFDOC'
  6. Takes a resource reference and name of the parameter and
  7. returns value of resource's parameter.
  8. *Examples:*
  9. define example_resource($param) {
  10. }
  11. example_resource { "example_resource_instance":
  12. param => "param_value"
  13. }
  14. concat_getparam(Example_resource["example_resource_instance"], "param")
  15. Would return: param_value
  16. ENDOFDOC
  17. ) do |vals|
  18. reference, param = vals
  19. raise(ArgumentError, 'Must specify a reference') unless reference
  20. raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String
  21. return '' if param.empty?
  22. if resource = findresource(reference.to_s)
  23. return resource[param] if resource[param]
  24. end
  25. return ''
  26. end