LWRP prevents code-reuse


#1

Hello,

Within our company, we use PyLabs (1). This environment has it’s own
packaging system (qpackages) and it’s own shell (qshell) based on
ipython. I started a cookbook to install the base environment, and
that was quickly done. However, I have more problems with the custom
resources and providers I am trying to implement:

  1. a custom resource named “pylabs_qshell”, based upon the "script"
    resource, similar to “bash” and “python”.
  2. a custom resource named “pylabs_package”, based on the standard
    "Package" resource
  3. a custom provider named “pylabs_package”, extending the standard
    "Package" provider

However, after several try-outs, I ended up looking in the core Chef
code to see how custom resources/providers worked. If someone packages
resources/providers in the cookbook, you seem to be obliged to use the
Light-Weight Resource Provider syntax. The generated classes in LWRP
are just Resources, not the Script or Package I want it to be. Similar
problem for the custom Provider.

Eventually, I replaced the LWRP syntax with full-fledged resource and
provider classes, but the build_from_file didn’t seem to like it. What
is my best option to go forward?

Greetings,

Ringo

(1) http://www.pylabs.org


#2

Chuck it in a library

On 30 June 2010 00:23, Ringo De Smet ringo.desmet@gmail.com wrote:

Hello,

Within our company, we use PyLabs (1). This environment has it’s own
packaging system (qpackages) and it’s own shell (qshell) based on
ipython. I started a cookbook to install the base environment, and
that was quickly done. However, I have more problems with the custom
resources and providers I am trying to implement:

  1. a custom resource named “pylabs_qshell”, based upon the "script"
    resource, similar to “bash” and “python”.
  2. a custom resource named “pylabs_package”, based on the standard
    "Package" resource
  3. a custom provider named “pylabs_package”, extending the standard
    "Package" provider

However, after several try-outs, I ended up looking in the core Chef
code to see how custom resources/providers worked. If someone packages
resources/providers in the cookbook, you seem to be obliged to use the
Light-Weight Resource Provider syntax. The generated classes in LWRP
are just Resources, not the Script or Package I want it to be. Similar
problem for the custom Provider.

Eventually, I replaced the LWRP syntax with full-fledged resource and
provider classes, but the build_from_file didn’t seem to like it. What
is my best option to go forward?

Greetings,

Ringo

(1) http://www.pylabs.org


#3

AJ,

On 30 June 2010 00:56, AJ Christensen aj@junglist.gen.nz wrote:

Chuck it in a library

Tnx for the tip.

One subsequent question though: the documentation states that
libraries are automatically “require”-d in your recipes, but what if
you want to “require” one library into another? I tried the following
variants:

require "qshell_resource"
require "libraries/qshell_resource"
require “/libraries/qshell_resource”

to refer to “/libraries/qshell_resource.rb”.

None of them worked.

Ringo


#4

On Wed, Jun 30, 2010 at 6:46 AM, Ringo De Smet ringo.desmet@gmail.com wrote:

AJ,

On 30 June 2010 00:56, AJ Christensen aj@junglist.gen.nz wrote:

Chuck it in a library

Tnx for the tip.

One subsequent question though: the documentation states that
libraries are automatically “require”-d in your recipes, but what if
you want to “require” one library into another? I tried the following
variants:

require "qshell_resource"
require "libraries/qshell_resource"
require “/libraries/qshell_resource”

to refer to “/libraries/qshell_resource.rb”.

Chef will automatically load them, but not in any guaranteed order. If
they are all in the same cookbook, I’d recommend using something like:

require File.dirname(FILE) + ‘/qshell_resource’

None of them worked.

Ringo


#5

Daniel,

On 1 July 2010 17:50, Daniel DeLeo dan@kallistec.com wrote:

Chef will automatically load them, but not in any guaranteed order. If
they are all in the same cookbook, I’d recommend using something like:

require File.dirname(FILE) + ‘/qshell_resource’

The ruby require worked now. However, on the Chef level, it is a pity
I can’t use my custom script resource in the body of my package
provider:

def install_package(name, version)
pylabs_qshell “install_package” do
user "root"
code <<-EOH
pkg = q.qp.find(’#{new_resource.package_name}’,’#{new_resource.domain}’,’#{new_resource.version}’)
pkg.install()
EOH
end
end

This would be a very elegant implementation. Any more suggestions? :slight_smile:

Ringo


#6

On Mon, Jul 5, 2010 at 8:12 AM, Ringo De Smet ringo.desmet@gmail.com wrote:

Daniel,

On 1 July 2010 17:50, Daniel DeLeo dan@kallistec.com wrote:

Chef will automatically load them, but not in any guaranteed order. If
they are all in the same cookbook, I’d recommend using something like:

require File.dirname(FILE) + ‘/qshell_resource’

The ruby require worked now. However, on the Chef level, it is a pity
I can’t use my custom script resource in the body of my package
provider:

def install_package(name, version)
pylabs_qshell “install_package” do
user "root"
code <<-EOH
pkg = q.qp.find(’#{new_resource.package_name}’,’#{new_resource.domain}’,’#{new_resource.version}’)
pkg.install()
EOH
end
end

This would be a very elegant implementation. Any more suggestions? :slight_smile:

Sure, here’s a few:

Ringo