class Puppet::Property::Ensure
This property is automatically added to any {Puppet::Type} that responds to the methods 'exists?', 'create', and 'destroy'.
Ensure
defaults to having the wanted _(should)_ value `:present`.
@api public
Public Class Methods
defaultvalues()
click to toggle source
# File lib/puppet/property/ensure.rb 13 def self.defaultvalues 14 newvalue(:present) do 15 if @resource.provider and @resource.provider.respond_to?(:create) 16 @resource.provider.create 17 else 18 @resource.create 19 end 20 nil # return nil so the event is autogenerated 21 end 22 23 newvalue(:absent) do 24 if @resource.provider and @resource.provider.respond_to?(:destroy) 25 @resource.provider.destroy 26 else 27 @resource.destroy 28 end 29 nil # return nil so the event is autogenerated 30 end 31 32 defaultto do 33 if @resource.managed? 34 :present 35 else 36 nil 37 end 38 end 39 40 # This doc will probably get overridden 41 @doc ||= "The basic property that the resource should be in." 42 end
inherited(sub)
click to toggle source
# File lib/puppet/property/ensure.rb 44 def self.inherited(sub) 45 # Add in the two properties that everyone will have. 46 sub.class_eval do 47 end 48 end
Public Instance Methods
change_to_s(currentvalue, newvalue)
click to toggle source
# File lib/puppet/property/ensure.rb 50 def change_to_s(currentvalue, newvalue) 51 begin 52 if currentvalue == :absent || currentvalue.nil? 53 return _("created") 54 elsif newvalue == :absent 55 return _("removed") 56 else 57 return _('%{name} changed %{is} to %{should}') % { name: name, is: is_to_s(currentvalue), should: should_to_s(newvalue) } 58 end 59 rescue Puppet::Error 60 raise 61 rescue => detail 62 raise Puppet::DevError, _("Could not convert change %{name} to string: %{detail}") % { name: self.name, detail: detail }, detail.backtrace 63 end 64 end
retrieve()
click to toggle source
Retrieves the is value for the ensure property. The existence of the resource is checked by first consulting the provider (if it responds to `:exists`), and secondly the resource. A a value of `:present` or `:absent` is returned depending on if the managed entity exists or not.
@return [Symbol] a value of `:present` or `:absent` depending on if it exists or not @raise [Puppet::DevError] if neither the provider nor the resource responds to `:exists`
# File lib/puppet/property/ensure.rb 74 def retrieve 75 # XXX This is a problem -- whether the object exists or not often 76 # depends on the results of other properties, yet we're the first property 77 # to get checked, which means that those other properties do not have 78 # @is values set. This seems to be the source of quite a few bugs, 79 # although they're mostly logging bugs, not functional ones. 80 prov = @resource.provider 81 if prov && prov.respond_to?(:exists?) 82 result = prov.exists? 83 elsif @resource.respond_to?(:exists?) 84 result = @resource.exists? 85 else 86 raise Puppet::DevError, _("No ability to determine if %{name} exists") % { name: @resource.class.name } 87 end 88 if result 89 return :present 90 else 91 return :absent 92 end 93 end