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