Puppet TypeandProviderExecution
PuppetType andProviderExecution
Trevor Vaughan -
License:
Onyx Point, Inc.
Attribution-Sha...
Puppet TypeandProviderExecution
WhatWe're DoingHere
Follow Along at Home!
Introduction to Types and Providers
Basic Type C...
Puppet TypeandProviderExecution
FollowAlongatHome!
Snag a copy of the walkthrough code at
http://git.io/_Bjamg
gitclonegit...
Puppet TypeandProviderExecution
WhatareTypes? -TheBasics
Properties
Something that can be measured and changed on the
syst...
Puppet TypeandProviderExecution
WhatareTypes? -Advanced
Initializer
Provides the ability to manipulate the resource mid-
c...
Puppet TypeandProviderExecution
WhatareProviders?
Initializer
A place to do all sorts of fun things that persist across
th...
Puppet TypeandProviderExecution
(StarTrek:The OriginalSeries.Season2,Episode 7.(Oct27,1967))
Puppet TypeandProviderExecution
TypeScaffold
modulePuppet
newtype(:ex_order)do
definitialize(args)super(args)end
deffinish...
Puppet TypeandProviderExecution
ProviderScaffold
Puppet::Type.type(:ex_order).provide(:ruby)do
@@ex_order_classvars={:exam...
Puppet TypeandProviderExecution
SampleExecutionManifest
ex_order{'test':
foo=>'foo',
bar=>'bar',
baz=>'baz'
}
Puppet TypeandProviderExecution
FullExecutionWalkthrough
You can find all code and output at http://git.io/ZPuZNQ
Puppet TypeandProviderExecution
Type PropertiesandParameters
Output
newparam(:name)doisnamevarend
newparam(:foo)do
Puppet....
Puppet TypeandProviderExecution
Provider Globals
Output
Puppet::Type.type(:ex_order).provide(:ruby)do
Puppet.warning("Sett...
Puppet TypeandProviderExecution
Type NameParameterMunge
Output
newparam(:name)do
isnamevar
mungedo|value|
Puppet.warning("...
Puppet TypeandProviderExecution
Provider Initializer
Output
definitialize(*args)
super(*args)
Puppet.warning("ProviderInit...
Puppet TypeandProviderExecution
Type Property|Baz
Output
#newparam(:foo)do
#newproperty(:baz)do
#newparam(:bar)do
newprope...
Puppet TypeandProviderExecution
Type Parameter|Foo
Output
#newparam(:foo)do
#newproperty(:baz)do
#newparam(:bar)do
newpara...
Puppet TypeandProviderExecution
Type Parameter|Bar
Output
#newparam(:foo)do
#newproperty(:baz)do
#newparam(:bar)do
newpara...
Puppet TypeandProviderExecution
Type Validation
Output
validatedo
required_params=[:foo,:bar,:baz]
Puppet.warning("#{self[...
Puppet TypeandProviderExecution
AREWETHERE
YET?
(ArrestedDevelopment,Fox/Netflix)
Puppet TypeandProviderExecution
Type Initializing
Output
definitialize(args)
super(args)
Puppet.warning("#{self[:name]}:Ty...
Puppet TypeandProviderExecution
Type Finish
Output
deffinish
Puppet.warning("#{self[:name]}:TypeFinishing")
#Don'tforgetto...
Puppet TypeandProviderExecution
Type Autorequires
Output
autorequire(:file)do
Puppet.warning("#{self[:name]}:Autorequring"...
Puppet TypeandProviderExecution
Provider Baz|Getter
Output
Puppet::Type.type(:ex_order).provide(:ruby)do
defbaz
#Thisiswha...
Puppet TypeandProviderExecution
Type Baz|Insync?
Output
newproperty(:baz)do
definsync?(is)
#Thisissimplywhatthenativeprovi...
Puppet TypeandProviderExecution
Provider Baz|Setter
Output
Puppet::Type.type(:ex_order).provide(:ruby)do
defbaz=(should)
#...
Puppet TypeandProviderExecution
Provider Flush
Output
Puppet::Type.type(:ex_order).provide(:ruby)do
defflush
#Thishappensi...
Puppet TypeandProviderExecution
Provider Post-ResourceEval
Output
#ThisisnewinPuppet3.4.0andcanbeusedfor
#cleaningupanyres...
Puppet TypeandProviderExecution
(The Legendof Zelda,Nintendo)
Puppet TypeandProviderExecution
Resources
The original article upon which this presentation is
based
The official document...
Puppet TypeandProviderExecution
PresentationInformation
This presentation was made possible by:
by
by
Reveal.js Hakim El H...
Upcoming SlideShare
Loading in …5
×

Puppet Camp DC 2014: Puppet Type and Provider Execution Presentation

1,309 views

Published on

Puppet Camp DC 2014: "Puppet Type and Provider Execution Presentation" Trevor Vaughn, OnyxPoint, Inc.

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,309
On SlideShare
0
From Embeds
0
Number of Embeds
77
Actions
Shares
0
Downloads
31
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Puppet Camp DC 2014: Puppet Type and Provider Execution Presentation

  1. 1. Puppet TypeandProviderExecution PuppetType andProviderExecution Trevor Vaughan - License: Onyx Point, Inc. Attribution-ShareAlike 3.0Unported(CCBY-SA3.0) 0
  2. 2. Puppet TypeandProviderExecution WhatWe're DoingHere Follow Along at Home! Introduction to Types and Providers Basic Type Code Walkthrough Basic Provider Code Walkthrough Type Execution Order Provider Execution Order
  3. 3. Puppet TypeandProviderExecution FollowAlongatHome! Snag a copy of the walkthrough code at http://git.io/_Bjamg gitclonegit@github.com:onyxpoint/onyxpoint.com.git gitcheckouttype-and-provider-execution-walkthrough
  4. 4. Puppet TypeandProviderExecution WhatareTypes? -TheBasics Properties Something that can be measured and changed on the system Parameters Change how Puppet manages resources through the Properties Think of them as variables Validation Anything that you need to do to validate your resource Autorequires Provides the ability to require other catalog resources if they happen to be defined Does not require resources to be defined!
  5. 5. Puppet TypeandProviderExecution WhatareTypes? -Advanced Initializer Provides the ability to manipulate the resource mid- compile Finish Anything that you want to do to your resource at the end of the compilation Post-Resource Evaluation Magic! Allows for a resource cleanup (Puppet > 3.4.0 only)
  6. 6. Puppet TypeandProviderExecution WhatareProviders? Initializer A place to do all sorts of fun things that persist across the provider Property Methods Automatically referenced methods for manipulating properties on the system Miscellaneous Any other method that is useful to your type
  7. 7. Puppet TypeandProviderExecution (StarTrek:The OriginalSeries.Season2,Episode 7.(Oct27,1967))
  8. 8. Puppet TypeandProviderExecution TypeScaffold modulePuppet newtype(:ex_order)do definitialize(args)super(args)end deffinish(args)superend newparam(:name)do desc"Everybodyneedsaname!" isnamevar end newparam(:foo)dodesc"Foo!"end newproperty(:baz)dodesc"PropertyBaz"end newparam(:bar)dodesc"ParameterBar"end validatedotrueend autorequire(:file)do['/tmp/foo']end end end
  9. 9. Puppet TypeandProviderExecution ProviderScaffold Puppet::Type.type(:ex_order).provide(:ruby)do @@ex_order_classvars={:example=>true} definitialize(*args) super(*args) end defbaz #Getthestateofthe'baz'propertyfromthesystem end defbaz=(should) #Setthesystemtothevalueofthe'baz'propertyinPuppet end defflush #If*any*propertyisnotinsync,thiswillbecalled end end
  10. 10. Puppet TypeandProviderExecution SampleExecutionManifest ex_order{'test': foo=>'foo', bar=>'bar', baz=>'baz' }
  11. 11. Puppet TypeandProviderExecution FullExecutionWalkthrough You can find all code and output at http://git.io/ZPuZNQ
  12. 12. Puppet TypeandProviderExecution Type PropertiesandParameters Output newparam(:name)doisnamevarend newparam(:foo)do Puppet.warning("Param:foo->Starting") end newproperty(:baz)do Puppet.warning("Property:baz->Starting") end newparam(:bar)do Puppet.warning("Param:bar->Starting") end warning:Param:foo->Starting warning:Property:baz->Starting warning:Param:bar->Starting
  13. 13. Puppet TypeandProviderExecution Provider Globals Output Puppet::Type.type(:ex_order).provide(:ruby)do Puppet.warning("SettingPropertyClassVariables") @@ex_order_classvars={ :example=>true } (...) end warning:SettingPropertyClassVariables
  14. 14. Puppet TypeandProviderExecution Type NameParameterMunge Output newparam(:name)do isnamevar mungedo|value| Puppet.warning("#{value}:Inthenameparameter.") value end end warning:test:Inthenameparameter.
  15. 15. Puppet TypeandProviderExecution Provider Initializer Output definitialize(*args) super(*args) Puppet.warning("ProviderInitialization:name='#{@resource[:name]}'") Puppet.warning("ProviderInitialization:foo='#{@resource[:foo]}'") Puppet.warning("ProviderInitialization:bar='#{@resource[:bar]}'") end warning:ProviderInitialization:name='test' warning:ProviderInitialization:foo='' warning:ProviderInitialization:bar=''
  16. 16. Puppet TypeandProviderExecution Type Property|Baz Output #newparam(:foo)do #newproperty(:baz)do #newparam(:bar)do newproperty(:baz)do validatedo|value| Puppet.warning("#{resource[:name]}::baz->Validating") Puppet.warning("#{resource[:name]}:Foo->'#{resource[:foo]}'") end end warning:test:Property:baz->Validating warning:test:Foo->''
  17. 17. Puppet TypeandProviderExecution Type Parameter|Foo Output #newparam(:foo)do #newproperty(:baz)do #newparam(:bar)do newparam(:foo)do validatedo|value| Puppet.warning("#{resource[:name]}:Param:foo->Validating") end mungedo|value| Puppet.warning("#{resource[:name]}:Param:foo->Munging") Puppet.warning("Where'sParam:bar?Baris'#{resource[:bar]}'") value end end warning:test:Param:foo->Validating warning:test:Param:foo->Munging warning:Where'sParam:bar?Baris''
  18. 18. Puppet TypeandProviderExecution Type Parameter|Bar Output #newparam(:foo)do #newproperty(:baz)do #newparam(:bar)do newparam(:bar)do Puppet.warning("Param:bar->Starting") validatedo|value| Puppet.warning("#{resource[:name]}:Param:bar->Validating") end mungedo|value| Puppet.warning("#{resource[:name]}:Param:bar->Munging") Puppet.warning("Where'sParam:foo?Foois'#{resource[:foo]}'") value end end warning:test:Param:bar->Validating warning:test:Param:bar->Munging warning:test:Where'sParam:foo?Foois'foo'<-OrderMatters!
  19. 19. Puppet TypeandProviderExecution Type Validation Output validatedo required_params=[:foo,:bar,:baz] Puppet.warning("#{self[:name]}:Validating") required_params.eachdo|param| ifnotself[param]then #Notehowweshowtheuser*where*theerroris. raisePuppet::ParseError,"Ohnoes!#{self.file}:#{self.line}" end end end Warning:test:Param:bar->Validating
  20. 20. Puppet TypeandProviderExecution AREWETHERE YET? (ArrestedDevelopment,Fox/Netflix)
  21. 21. Puppet TypeandProviderExecution Type Initializing Output definitialize(args) super(args) Puppet.warning("#{self[:name]}:TypeInitializing") num_ex_orders=@catalog.resources.find_all{|r| r.is_a?(Puppet::Type.type(:ex_order)) }.count Puppet.warning("Ex_order'sinthecatalog:'#{num_ex_orders+1}'") end warning:test:TypeInitializing warning:Ex_order'sinthecatalog:'1'
  22. 22. Puppet TypeandProviderExecution Type Finish Output deffinish Puppet.warning("#{self[:name]}:TypeFinishing") #Don'tforgettocallthis*attheend* super end warning:test:TypeFinishing
  23. 23. Puppet TypeandProviderExecution Type Autorequires Output autorequire(:file)do Puppet.warning("#{self[:name]}:Autorequring") ["/tmp/foo"] end warning:test:Autorequring
  24. 24. Puppet TypeandProviderExecution Provider Baz|Getter Output Puppet::Type.type(:ex_order).provide(:ruby)do defbaz #Thisiswhat'is'endsupbeingininsync? Puppet.warning("#{@resource[:name]}:Ingetterfor:baz") end end warning:test:Ingetterfor:baz
  25. 25. Puppet TypeandProviderExecution Type Baz|Insync? Output newproperty(:baz)do definsync?(is) #Thisissimplywhatthenativeprovidercodewoulddo. is==@should #Note,youhavetouse@resource,notresourceheresince #you'renotinthepropertyanymore,you'reintheprovider. Puppet.warning("#{@resource[:name]}:In'insync?'for:baz") #We'rereturningfalsejusttoseetherestofthecomponents #fireoff. false end end warning:test:In'insync?'for:baz
  26. 26. Puppet TypeandProviderExecution Provider Baz|Setter Output Puppet::Type.type(:ex_order).provide(:ruby)do defbaz=(should) #Calledifinsync?isfalse Puppet.warning("#{@resource[:name]}:Insetterfor:baz") end end warning:test:Insetterfor:baz notice:/Stage[main]/Main/Ex_order[test]/baz:bazchanged 'test:Ingetterfor:baz'to'baz'
  27. 27. Puppet TypeandProviderExecution Provider Flush Output Puppet::Type.type(:ex_order).provide(:ruby)do defflush #Thishappensif*any*propertywasmodified. Puppet.warning("Timetoflush#{@resource[:name]}") end end warning:Timetoflushtest
  28. 28. Puppet TypeandProviderExecution Provider Post-ResourceEval Output #ThisisnewinPuppet3.4.0andcanbeusedfor #cleaningupanyresourcepersistencesinceithappensafter #*all*resourcesofthistypehavebeenevaluated. defself.post_resource_eval Puppet.warning("FINIS!!!!") end warning:FINIS!!!!
  29. 29. Puppet TypeandProviderExecution (The Legendof Zelda,Nintendo)
  30. 30. Puppet TypeandProviderExecution Resources The original article upon which this presentation is based The official documentation on custom types. The Puppet Types and Providers book by and The source code for this presentation Type and Provider Execution Walkthrough Puppet Labs' Custom Type Documentation Puppet Types and Providers Book Dan Bode Nan Liu Presentation Source
  31. 31. Puppet TypeandProviderExecution PresentationInformation This presentation was made possible by: by by Reveal.js Hakim El Hattab Reveal.js Modifications José Manuel Ciges Regueiro

×