Advice on writing an LWRP


#1

Hello all,

I am trying to write a LWRP, and following the instructions, have something
basic working, now comes the hard part, making it do what I really want.

The main problem is I don’t want to duplicate code and so want to extend a
Provider that comes with Chef (RemoteFile), but a LWP gets a class dynamically
generated for it. Is there any way to specify that the generated class in a LWP
should extend another? I tried just plopping a whole ruby class (partially
included below) in the LWP file, but when run it fails complaining " FATAL:
NameError: uninitialized constant
#Class:0x1024a9888::Chef::Provider::RemoteFile" even though I had required
’chef/provider/remote_file’.

I can of course copy the methods from File and RemoteFile into my LWP, but I
don’t want to do that if I can avoid it.

Thank you in advance.

Code excerpt mentioned above:

require 'chef/provider/remote_file’
class Chef
class Provider
class S3File < Chef::Provider::RemoteFile

end
end
end


#2

I have a s3_file resource i can send you that extends the same class. It isn’t a LWRP and extends the class correctly. When I get home from the pub I’ll attach it. Only thing it doesn’t do is check checksums correctly because amazon uses md5 not sha.

Sent from my iPhone

On Jun 3, 2011, at 6:46 PM, npahucki@gmail.com wrote:

Hello all,

I am trying to write a LWRP, and following the instructions, have something
basic working, now comes the hard part, making it do what I really want.

The main problem is I don’t want to duplicate code and so want to extend a
Provider that comes with Chef (RemoteFile), but a LWP gets a class dynamically
generated for it. Is there any way to specify that the generated class in a LWP
should extend another? I tried just plopping a whole ruby class (partially
included below) in the LWP file, but when run it fails complaining " FATAL:
NameError: uninitialized constant
#Class:0x1024a9888::Chef::Provider::RemoteFile" even though I had required
’chef/provider/remote_file’.

I can of course copy the methods from File and RemoteFile into my LWP, but I
don’t want to do that if I can avoid it.

Thank you in advance.

Code excerpt mentioned above:

require 'chef/provider/remote_file’
class Chef
class Provider
class S3File < Chef::Provider::RemoteFile

end
end
end