On Sun, 2008-08-24 at 18:19 -0500, Luke Kanies wrote:
> On Aug 24, 2008, at 5:56 AM, Brice Figureau wrote:
> 
> >
> > Hi,
> 
> Sorry, probably should have replied to this one first.
> 
> >
> > I'm unfortunately more a java/c/c++/perl guy than a ruby kind of
> > programmer :-(
> 
> It's not too late. :)

I have quite hard time understanding how the provider class is built :-(

> >
> > I started working on a service provider for daemontools, but I'm stuck
> > with the following issue:
> >
> > Here is a snippet of my provider I produced using pattern matching  
> > from
> > other providers:
> >
> > Puppet::Type.type(:service).provide :daemontools, :parent => :base do
> >    desc "Daemontools service management."
> >
> >    commands :svc  => "/usr/bin/svc"
> >    commands :svstat => "/usr/bin/svstat"
> >
> >    class << self
> >        attr_accessor :defpath
> >        attr_accessor :srcpath
> >    end
> >
> >    case Facter["operatingsystem"].value
> >    when "Debian":
> >        @defpath = "/etc/service"
> >        @srcpath = "/var/lib/service"
> >    else
> >        @defpath = "/service"
> >        @srcpath = "/var/lib/service"
> >    end
> >
> > ...
> >    def enabled?
> >        appdir = File.join(self.defpath, @resource[:name])
> >        FileTest.symlink?(appdir)
> >    end
> > ...
> 
> You've created a class accessor above -- that 'class << self...end'  
> syntax is modifying the class, rather than instances, so you've made  
> 'defpath' and 'srcpath' class attributes.
> 
> However, your self.defpath call is using an instance attribute, since  
> 'enabled?' is an instance method.

OK, got it. 
This provider is based on the init one, and in init, self.defpath is
also called, hence I thought it would work.

> Just change this to 'self.class.defpath'.  You wouldn't normally need  
> the 'self', but you can't lead a statement with 'class' because it  
> confuses Ruby's parser (since 'class' is a reserved word).

OK. Anyway, as you probably saw it, I rewrote it differently.

> > What is the way to access properties of my provider in the provider  
> > method
> > (like status, start, stop...)
> 
> Provider, or resource?

In fact I meant provider, because I didn't understood I was adding
defpath as a class attribute. For me it was an instance variable hence
the question.

> You'd access resource attributes like: status = resource[:hasstatus].

The currently defined services seems to use @resource[:hasstatus]. 
Is your code snippet a typo error or is it the real syntax?

> Note that versions prior to, I think, 0.24.4 required you to use  
> 'resource.should(:property)' for properties. and 'resource[:param]'  
> for parameters, for backward compatbility.  This has been fixed now,  
> thankfully, and the [] syntax works everywhere.

OK, good to know.

I have some other questions related to this provider:

 * I know from the provider documentation that the "commands" keyword
check a command is present and change the suitability accordingly. I
know about optional_command. As asked by Adam in another e-mail, if the
provider supports runit, it should use another subset of commands.
The question is how I can check the presence of the executable and
choose a command subset instead than another?

 * A question related to the previous one. I want to be able to detect
the service directory (which is usually /service or /etc/service on
debian lenny, or /var/lib/svscan on old debian fhs). What would be the
best way to do that?
Should it be a new fact, or can I place FileTest heuristic directly in
the provider class (my fear is that the class is loaded in the
puppetmaster, hence the heuristic could be wrong)?

Thanks for the information,
-- 
Brice Figureau <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to