Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
LWRP DEVELOPMENT            Speaker:          Brian Bianco  Email: brian.bianco@gmail.com     Twitter: @brianwbianco  http...
RESOURCES• Resources represent a piece of system state• We supply resources with data• Ordering of resources is important•...
PROVIDERS•Providers are the underlying implementation of a resource•They are loaded by Chef::RunContext before Resources• ...
WHAT ARE LWRPS• A DSL provided to make writing resources and providers easier• Useful for creating your own resources and ...
FILE STRUCTURE                 Filename paths are relative to:                     /cookbooks/lwrpdemo      Filename      ...
LIGHTWEIGHT RESOURCESThe same directory resource if it were using the resource DSL
• Resources will look for providers by the same name (you can specify one with the provider resource attribute)• Actions d...
LIGHTWEIGHT PROVIDERSThe same provider if it were using the Provider DSL
load_current_resource•This method is responsible for loading the current state of  the resource into @current_resource• @c...
ANOTHER PROVIDER EXAMPLE         Python VirtualEnv Create Action  Checking to see if the virtual env exists already
NESTED RESOURCES• Resources can be nested inside of light weight providers• If those resources call updated_by_last action...
TIPS • Check out others cookbooks, especially the opscode teams• The default recipe should just make the resource availabl...
CONTRIBUTING BACK• http://wiki.opscode.com/display/chef/How+to+Contribute • Create a jira account • Sign the CLA • Submit ...
Lwrp presentation
Lwrp presentation
Lwrp presentation
Upcoming SlideShare
Loading in …5
×

Lwrp presentation

5,194 views

Published on

Published in: Technology, Business

Lwrp presentation

  1. 1. LWRP DEVELOPMENT Speaker: Brian Bianco Email: brian.bianco@gmail.com Twitter: @brianwbianco http://github.com/brianbianco
  2. 2. RESOURCES• Resources represent a piece of system state• We supply resources with data• Ordering of resources is important• Chef ’s Recipe DSL creates resources• During the compile phase these resources are added to the resource collection Example of a resource in a recipe:
  3. 3. PROVIDERS•Providers are the underlying implementation of a resource•They are loaded by Chef::RunContext before Resources• Node attributes are NOT available to them (they can however be passed in via resource attributes)• Normal providers are selected by Chef::Platform
  4. 4. WHAT ARE LWRPS• A DSL provided to make writing resources and providers easier• Useful for creating your own resources and providers without having to implement the actual ruby classes• LWRP has two components: Resource & Provider• Great way to abstract some repeated pattern
  5. 5. FILE STRUCTURE Filename paths are relative to: /cookbooks/lwrpdemo Filename Resource / Provider Generated Class Name resources/default.rb lwrpdemo Chef::Resource::Lwrpdemo providers/default.rb lwrpdemo Chef::Provider::Lwrpdemoresources/directory.rb lwrpdemo_directory Chef::Resource::LwrpdemoDirectoryproviders/directory.rb lwrpdemo_directory Chef::Provider::LwrpdemoDirectory
  6. 6. LIGHTWEIGHT RESOURCESThe same directory resource if it were using the resource DSL
  7. 7. • Resources will look for providers by the same name (you can specify one with the provider resource attribute)• Actions defined in the resource correspond to action methods in the provider• Attributes correspond to methods for the resource (These are called parameters)• Validation parameters: :default :kind_of :required :regex :equal_to :name_attribute :callbacks :respond_to
  8. 8. LIGHTWEIGHT PROVIDERSThe same provider if it were using the Provider DSL
  9. 9. load_current_resource•This method is responsible for loading the current state of the resource into @current_resource• @current_resource = Chef::Resource::LwrpdemoDirectory.new(new_resource.name) updated_by_last_action •Call this method when the provider changes something • When called with true, will fire off notifications
  10. 10. ANOTHER PROVIDER EXAMPLE Python VirtualEnv Create Action Checking to see if the virtual env exists already
  11. 11. NESTED RESOURCES• Resources can be nested inside of light weight providers• If those resources call updated_by_last action your provider will not inherit that• Luckily there is a pattern you can use to solve this!• You can use the updated? method on any resource in the Chef::ResourceCollection
  12. 12. TIPS • Check out others cookbooks, especially the opscode teams• The default recipe should just make the resource available and setup any necessary files and configurations• The #chef channel on irc.freenode.org is full of helpful people • The mailing list is a great place to ask questions http://lists.opscode.com
  13. 13. CONTRIBUTING BACK• http://wiki.opscode.com/display/chef/How+to+Contribute • Create a jira account • Sign the CLA • Submit pull requests• Share you cookbooks on Github and community.opscode.com• Even the smallest bug fixes help

×