X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdefined_with_params.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdefined_with_params.rb;h=d7df306c7932e6f310669c58c4c21a1a0a291b85;hb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;hp=0000000000000000000000000000000000000000;hpb=23d29143ac40015ce61cf83a4067466f8f7d66dc;p=dsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb new file mode 100644 index 00000000..d7df306c --- /dev/null +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb @@ -0,0 +1,35 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:defined_with_params, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and an optional hash of attributes. + +Returns true if a resource with the specified attributes has already been added +to the catalog, and false otherwise. + + user { 'dan': + ensure => present, + } + + if ! defined_with_params(User[dan], {'ensure' => 'present' }) { + user { 'dan': ensure => present, } + } +ENDOFDOC +) do |vals| + reference, params = vals + raise(ArgumentError, 'Must specify a reference') unless reference + if (! params) || params == '' + params = {} + end + ret = false + if resource = findresource(reference.to_s) + matches = params.collect do |key, value| + resource[key] == value + end + ret = params.empty? || !matches.include?(false) + end + Puppet.debug("Resource #{reference} was not determined to be defined") + ret +end