On Wed, Nov 19, 2008 at 2:42 PM, Luke Kanies <[EMAIL PROTECTED]> wrote:
>
> On Nov 19, 2008, at 1:12 PM, Nigel Kersten wrote:
>> On Wed, Nov 19, 2008 at 6:17 AM, Luke Kanies <[EMAIL PROTECTED]> wrote:
>>
>>>> Would it make more sense to define this in type.rb than in a
>>>> specific
>>>> service type?
>>>>
>>>> That would seem more sensible if I'm understanding all the
>>>> inheritance
>>>> correctly?
>>>
>>> Yeah, that's kind of what I was suggesting.
>>
>> ok, so I think I have most of it working, I'm just not quite sure how
>> to specify the File resource to be returned.
>
> Because autorequire is declared with a given resource type (at least,
> in its current incarnation) you just return an array of names and the
> transaction will create the resources for you.  Or you can create the
> resources and return them, which works fine, too.
>
>>
>> I've tried to make this as generic as possible.
>>
>> type.rb already has an autorequire method that checks class
>> autorequires, so I'm adding the provider autorequires there.
>>
>>        self.class.suitableprovider.each do |provider|
>>            if provider.respond_to?(:autorequire)
>>                provider.autorequire(self).each do |req|
>>                    Puppet.notice("got an autorequire of: #{req}")
>>                end
>>            end
>>        end
>>
>> Obviously I'm not doing anything with it yet, but it will get appended
>> to the existing array of requirements.
>>
>> I have two questions:
>>
>> a) Should I be passing "self" to the provider autorequire method?
>> I need some way for the provider in its own autorequire method to know
>> what resource it needs to build the autorequire list for, and this
>> works, but I'm not sure if it is consistent with the rest of the
>> Puppet code.
>
> The provider has a '@resource' instance variable and related
> 'resource' accessor, so you can just use that.  So you shouldn't need
> to pass anything to the autorequire method.
>
>>
>> b) On the other side in my provider, once I have the resource name,
>> and thus can work out what files it should autorequire, how do I build
>> a File resource to return back based upon the path(s) ?
>>
>> from my provider:
>>
>>    def self.autorequire(resource)
>>        Puppet.notice("provider.self.autorequire: resource:
>> #{resource[:name]}")
>>        job_path, job_plist = self.plist_from_label(resource[:name])
>>        Puppet.notice("provider.self.autorequire: path: #{job_path}")
>>        # how do I return an array of required file resources at this
>> point?
>>        []
>>    end
>
>
> So, the current implementation of 'autorequire' has you declare a
> given type/block tuple.  So, you'd say:
>
> autorequire(:file) do
>   ...return array of file names...
> end
>
> autorequire(:user) do
>   ...return array of user names...
> end
>
> I hadn't looked at how this works internally in a while, but it looks
> like it won't necessarily scale that well to the provider.  That is,
> there's a decent bit of plumbing to make this interface work, and my
> guess is it makes more sense to just have the provider either directly
> find the resource in the catalog:
>
>   if resource = resource.catalog(:file, "/what/ever")
>     return [resource]
>   end
>
> Or maybe do a small amount of plumbing so you can return resource
> references:
>
>   return [Puppet::ResourceReference.new(:file, "/what/ever")]
>
> The latter probably makes more sense.  I didn't have this
> ResourceReference class when I created the autorequire plumbing.
>
> Does that all make sense?

It does, but from experimenting, I don't think the current code base
supports plugging autorequire into providers as easily as this makes
it sound... :)

I'll grab you on IRC sometime when we can chat back and forth.


-- 
Nigel Kersten
Systems Administrator
Tech Lead - MacOps

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com
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