Hi John

Thanks a lot. I misunderstood 'arguments' as an array of elements rather 
than array of 'arguments'. 

Cheers
Kashif 


On Thursday, February 13, 2014 3:33:26 PM UTC, jcbollinger wrote:
>
>
>
> On Wednesday, February 12, 2014 7:21:30 AM UTC-6, kashif wrote:
>>
>> I have written a small custom function to replace '.' to '_' of all 
>> element of an array and return an converted array.
>>
>> module Puppet::Parser::Functions
>>   newfunction(:convert_vo, :type => :rvalue, :doc => <<-'ENDOFDOC'
>>  This function takes an array of vo and replace '.' with '_' and return 
>> an converted array
>> ENDOFDOC
>>   ) do |arguments|
>>
>>     require 'rubygems'
>>     vo_list = arguments.clone
>>     unless vo_list.is_a?(Array)
>>       raise(Puppet::ParseError, 'convert_vo requires an array')
>>     end
>>     converted_vo = Array.new()
>>     vo_list.each do |vo|
>>       converted_vo.push(vo.gsub(/\./, '_'))
>>     end
>>     return converted_vo
>>   end
>> end
>>
>> I am calling it like this from init.p
>>
>> $vo = ['dteam', 'vo.southgrid.ac.uk']
>> $converted_vo = convert_vo($vo)
>>
>>
>> Puppet run on client machine fails with this error
>>
>> Error: Could not retrieve catalog from remote server: Error 400 on 
>> SERVER: private method `gsub' called for ["dteam", 
>> "vo.southgrid.ac.uk"]:Array 
>> at /etc/puppet/modules/voms_client/manifests/init.pp
>>
>>
>> I ran this script on client and server machines seperately and it worked 
>> perfectly. I am not sure that what I am missing?
>>
>
>
> I'm not sure what you mean by "I ran this script", but your function is 
> buggy.  The error message tells you exactly what the problem is: you are 
> trying to invoke a method named 'gsub' on an object of type Array (which 
> has no such method). 
>
> The function seems to be getting its nesting levels wrong.  The 
> 'arguments' object passed into it is an array of the arguments to the 
> function.  You call it with one argument, itself an array.  In your 
> particular case, the value of 'arguments' seen by the function is [ [ 
> 'dteam', 'vo.southgrid.ac.uk' ] ].  The function assumes that each 
> element of 'arguments' supports a gsub() method, but that is not the case.
>
> Among your alternatives are
>
>    - don't wrap the function arguments in an array
>    - make the function recognize array arguments and handle them 
>    appropriately
>
>
> John
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/25bf3b36-c901-4263-93cf-3ebf7ebd863e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to