On 14.07.2013 02:27, Schofield wrote:
> I'm taking some time to refactor a custom provider.  I'm trying to move
> common code into a parent provider so that it can be shared among all
> custom resource providers in the puppet module.  While verifying I can
> call methods in the parent provider I get the following error:
> 
> Error: Could not prefetch jboss7_deployment provider 'jboss7':
>     undefined method `echo' for
> Puppet::Type::Jboss7_deployment::ProviderJboss7:Class
> 
> Here are the relevant snippets of code
> 
> class Puppet::Provider::Jboss7 < Puppet::Provider
>   def echo(arg)
>     info arg
>   end
> end

so your provider has an instance method "echo" ...

> 
> require 'puppet/provider/jboss7'
> Puppet::Type.type(:jboss7_deployment).provide(:jboss7, :parent =>
> Puppet::Provider::Jboss7) do
>   echo "hello world"
>   ...
> end

.. and here you are calling echo in  a class context that will execute
as soon as the corresponding file is loaded. So depending on your actual
goal you should either only call echo in an instance method

    Puppet::Type.type(:jboss7_deployment).provide(:jboss7, :parent =>
Puppet::Provider::Jboss7) do
      def create
        echo "I was created"
      end
    end

or, if you want to call the `echo` method at class level (e.g.
self.prefetch), define your method as a class method in your parent provider

    class Puppet::Provider::Jboss7 < Puppet::Provider
      def self.echo(arg)
        info arg
      end
    end

Does this make sense?

-Stefan

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to