SlideShare uma empresa Scribd logo
1 de 16
LWRP DEVELOPMENT

            Speaker:
          Brian Bianco


  Email: brian.bianco@gmail.com
     Twitter: @brianwbianco
  http://github.com/brianbianco
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:
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
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
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::Lwrpdemo

resources/directory.rb   lwrpdemo_directory    Chef::Resource::LwrpdemoDirectory


providers/directory.rb   lwrpdemo_directory    Chef::Provider::LwrpdemoDirectory
LIGHTWEIGHT RESOURCES
The 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 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
LIGHTWEIGHT PROVIDERS
The 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

• @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
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 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
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
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

Mais conteúdo relacionado

Semelhante a Lwrp presentation

Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Software, Inc.
 
Chef, Vagrant and Friends
Chef, Vagrant and FriendsChef, Vagrant and Friends
Chef, Vagrant and FriendsBen McRae
 
Introduction to Cooking with Chef
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with ChefJohn Osborne
 
Resources, Providers, and Helpers Oh My!
Resources, Providers, and Helpers Oh My!Resources, Providers, and Helpers Oh My!
Resources, Providers, and Helpers Oh My!Brian Stajkowski
 
Managing Distributed Systems with Chef
Managing Distributed Systems with ChefManaging Distributed Systems with Chef
Managing Distributed Systems with ChefMandi Walls
 
2015 08-11-scdo-meetup
2015 08-11-scdo-meetup2015 08-11-scdo-meetup
2015 08-11-scdo-meetupSuresh Paulraj
 
CHEF - by Scott Russel
CHEF - by Scott RusselCHEF - by Scott Russel
CHEF - by Scott RusselKangaroot
 
Introduction to the COAR Notify project
Introduction to the COAR Notify projectIntroduction to the COAR Notify project
Introduction to the COAR Notify projectPaul Walk
 
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...Puppet
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Shahrzad Peyman
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowMatt Ray
 
Pushing Chemical Biology Through the Pipes
Pushing Chemical Biology Through the PipesPushing Chemical Biology Through the Pipes
Pushing Chemical Biology Through the PipesRajarshi Guha
 
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah KhanPuppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah KhanHameedullah Khan
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Chef
 
DOO-009_Powering High Velocity Development for your Infrastructure
DOO-009_Powering High Velocity Development for your InfrastructureDOO-009_Powering High Velocity Development for your Infrastructure
DOO-009_Powering High Velocity Development for your Infrastructuredecode2016
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...Puppet
 
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Software, Inc.
 

Semelhante a Lwrp presentation (20)

Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of Chef
 
Chef, Vagrant and Friends
Chef, Vagrant and FriendsChef, Vagrant and Friends
Chef, Vagrant and Friends
 
Introduction to Cooking with Chef
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with Chef
 
Resources, Providers, and Helpers Oh My!
Resources, Providers, and Helpers Oh My!Resources, Providers, and Helpers Oh My!
Resources, Providers, and Helpers Oh My!
 
Managing Distributed Systems with Chef
Managing Distributed Systems with ChefManaging Distributed Systems with Chef
Managing Distributed Systems with Chef
 
2015 08-11-scdo-meetup
2015 08-11-scdo-meetup2015 08-11-scdo-meetup
2015 08-11-scdo-meetup
 
Chef resources
Chef resourcesChef resources
Chef resources
 
CHEF - by Scott Russel
CHEF - by Scott RusselCHEF - by Scott Russel
CHEF - by Scott Russel
 
Introduction to the COAR Notify project
Introduction to the COAR Notify projectIntroduction to the COAR Notify project
Introduction to the COAR Notify project
 
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...
PuppetConf 2017: Custom Types & Providers: Modeling Modern REST Interfaces an...
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
 
Presentationday3oracle12c
Presentationday3oracle12cPresentationday3oracle12c
Presentationday3oracle12c
 
Pushing Chemical Biology Through the Pipes
Pushing Chemical Biology Through the PipesPushing Chemical Biology Through the Pipes
Pushing Chemical Biology Through the Pipes
 
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah KhanPuppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1
 
DOO-009_Powering High Velocity Development for your Infrastructure
DOO-009_Powering High Velocity Development for your InfrastructureDOO-009_Powering High Velocity Development for your Infrastructure
DOO-009_Powering High Velocity Development for your Infrastructure
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
 
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
 

Último

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Último (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Lwrp presentation

  • 1. LWRP DEVELOPMENT Speaker: Brian Bianco Email: brian.bianco@gmail.com Twitter: @brianwbianco http://github.com/brianbianco
  • 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.
  • 4. 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
  • 5.
  • 6. 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
  • 7. 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::Lwrpdemo resources/directory.rb lwrpdemo_directory Chef::Resource::LwrpdemoDirectory providers/directory.rb lwrpdemo_directory Chef::Provider::LwrpdemoDirectory
  • 8. LIGHTWEIGHT RESOURCES The same directory resource if it were using the resource DSL
  • 9. • 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
  • 10. LIGHTWEIGHT PROVIDERS The same provider if it were using the Provider DSL
  • 11. 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
  • 12. ANOTHER PROVIDER EXAMPLE Python VirtualEnv Create Action Checking to see if the virtual env exists already
  • 13. 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
  • 14.
  • 15. 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
  • 16. 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

Notas do Editor

  1. Lets first talk about resources and providers in general (and their ‘non light weight’ implementations)\nResources are a great way to abstract repeatable patterns\nShorcuts I may say => ivar = instance variable, DSL = domain specific language, \n
  2. RunContext order -> Libraries, Providers, Resources, Attributes, Definitions, Recipes\nArgument after resource name is called the “Name attribute”\n\n\n
  3. chef-0.10.10/lib/chef/resource/directory.rb\nRegular ruby class\nresource attributes are methods\nPath is the “name” attribute\n
  4. Chef::Platform contains a HASH of default providers based on operating systems\n\n
  5. All resource actions are named action_<action name>\nload_current_resource is responsible for determining the current state of the resource (where we are)\nnew resource is the state we want the resource in (where we want to be)\nRegular ruby class (This one inherits from Chef::Provider::File)\n\n
  6. \n
  7. \n
  8. name_attribute is populated by the name given when the resource is called\ndefault_action is chef 0.10.10 and above (Will show you later how to do 0.10.8 and below)\nall resources get the :nothing action\nTwo parameters for “attribute” Name of the attribute and the validation parameters\n\n\n
  9. Resource parameters (attributes) are not to be confused with node attributes!\nprovider Chef::Provider::Cookbookname::Providername or provider :my_other_provider\nList of validation parameters\n\n\n\n
  10. You can use other chef resources inside of your providers\nYou can access data passed into the resource via new_resource.<attribute name>\nAll resource actions are implemented here!\nOnly one method for this DSL -> action\n\n
  11. \n
  12. Could also use: \nmyvar = Chef::ShellOut.new(“Some Command”)\nmyvar.run_command (runs the command)\nmyvar.stdout (the output)\n
  13. \n
  14. the run_context is only needed for the case of wanting to use methods like #user, #mount, #cookbook_file\nthe sub_run_context is a subset of resource executed in the provider (since you initialize its ResourceCollection)\nany? Passes the updated function to the set of resources, returns functions that respond with anything other than (nil,false)\nrun_context loads and tracks the context of a chef run\nconverge: iterates over the resource_collection in the run_context calling run_action for each resource\n
  15. \n
  16. \n