//
you're reading...
ChefCodeNotes

Multiple resources in LWRPs

In my smartos_zones cookbook I have two different resource types but a single provider.

I wanted to highlight what I had to do to detect which was used.

I have a KVM and a Zone resource, in the provider’s load_current_resource I have:

...
  restype = get_restype
  @current_resource ||= restype.new(@new_resource.name)
...

Get restype looks like this:

...
def get_restype
  if @new_resource.resource_name.eql? :zone; return Chef::Resource::Zone; end
  if @new_resource.resource_name.eql? :kvm; return Chef::Resource::Kvm; end
  Chef::Application.fatal!("Couldn't find resource class")
end
...

Fairly simple, but took me a bit of messing around to get it to be right, hence a note about it.

Advertisements

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s