class Puppet::Resource::Status

This class represents the result of evaluating a given resource. It contains file and line information about the source, events generated while evaluating the resource, timing information, and the status of the resource evaluation.

@api private

Constants

STATES

Boolean status types set while evaluating `@real_resource`.

Attributes

change_count[R]

@!attribute [r] change_count

@return [Integer] A count of the successful changes made while
  evaluating `@real_resource`.
containment_path[R]

@!attribute [r] containment_path

@return [Array<String>] A list of resource references that contain
  `@real_resource`.
@example A normal contained type
  status.containment_path #=> ["Stage[main]", "Myclass", "Exec[date]"]
@example A whit associated with a class
  status.containment_path #=> ["Whit[Admissible_class[Main]]"]
corrective_change[R]

@!attribute [r] corrective_change

@return [Boolean] true if the resource contained a corrective change.
evaluation_time[RW]

@!attribute [rw] evaluation_time

@return [Float] The time elapsed in sections while evaluating `@real_resource`.
  measured in seconds.
events[R]

@!attribute [r] events

@return [Array<Puppet::Transaction::Event>] A list of events generated
  while evaluating `@real_resource`.
failed_dependencies[RW]

@!attribute [rw] failed_dependencies

@return [Array<Puppet::Resource>] A cache of all
dependencies of this resource that failed to apply.
file[RW]

@!attribute [rw] file

@return [String] The file where `@real_resource` was defined.
line[RW]

@!attribute [rw] line

@return [Integer] The line number in the file where `@real_resource` was defined.
out_of_sync_count[R]

@!attribute [r] out_of_sync_count

@return [Integer] A count of the audited changes made while
  evaluating `@real_resource`.
provider_used[RW]

@!attribute [rw] provider_used

@return [String] The class name of the provider used for the resource
resource[R]

@!attribute [r] resource

@return [String] The resource reference for `@real_resource`
resource_type[R]

@!attribute [r] resource_type

@example
  status.resource_type #=> 'Notify'
@return [String] The class name of `@real_resource`
source_description[R]

@!attribute [r] source_description

@return [String] The textual description of the path to `@real_resource`
  based on the containing structures. This is in contrast to
  `@containment_path` which is a list of containment path components.
@example
  status.source_description #=> "/Stage[main]/Myclass/Exec[date]"
time[R]

@!attribute [r] time

@return [Time] The time that this status object was created
title[R]

@!attribute [r] title

@return [String] The title of `@real_resource`

Public Class Methods

from_data_hash(data) click to toggle source
    # File lib/puppet/resource/status.rb
104 def self.from_data_hash(data)
105   obj = self.allocate
106   obj.initialize_from_hash(data)
107   obj
108 end
new(resource) click to toggle source
    # File lib/puppet/resource/status.rb
155 def initialize(resource)
156   @real_resource = resource
157   @source_description = resource.path
158   @containment_path = resource.pathbuilder
159   @resource = resource.to_s
160   @change_count = 0
161   @out_of_sync_count = 0
162   @changed = false
163   @out_of_sync = false
164   @skipped = false
165   @failed = false
166   @corrective_change = false
167 
168   @file = resource.file
169   @line = resource.line
170 
171   merge_tags_from(resource)
172   @time = Time.now
173   @events = []
174   @resource_type = resource.type.to_s.capitalize
175   @provider_used = resource.provider.class.name.to_s unless resource.provider.nil?
176   @title = resource.title
177 end

Public Instance Methods

<<(event) click to toggle source
    # File lib/puppet/resource/status.rb
117 def <<(event)
118   add_event(event)
119   self
120 end
add_event(event) click to toggle source
    # File lib/puppet/resource/status.rb
122 def add_event(event)
123   @events << event
124   if event.status == 'failure'
125     self.failed = true
126   elsif event.status == 'success'
127     @change_count += 1
128     @changed = true
129   end
130   if event.status != 'audit'
131     @out_of_sync_count += 1
132     @out_of_sync = true
133   end
134   if event.corrective_change
135     @corrective_change = true
136   end
137 end
dependency_failed?() click to toggle source
    # File lib/puppet/resource/status.rb
100 def dependency_failed?
101   failed_dependencies && !failed_dependencies.empty?
102 end
fail_with_event(message) click to toggle source

Both set the status state to failed and generate a corresponding Puppet::Transaction::Event failure with the given message. @param message [String] the reason for a status failure

    # File lib/puppet/resource/status.rb
151 def fail_with_event(message)
152   add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => message))
153 end
failed_because(detail) click to toggle source
    # File lib/puppet/resource/status.rb
139 def failed_because(detail)
140   @real_resource.log_exception(detail, _("Could not evaluate: %{detail}") % { detail: detail })
141   # There's a contract (implicit unfortunately) that a status of failed
142   # will always be accompanied by an event with some explanatory power.  This
143   # is useful for reporting/diagnostics/etc.  So synthesize an event here
144   # with the exception detail as the message.
145   fail_with_event(detail.to_s)
146 end
initialize_from_hash(data) click to toggle source
    # File lib/puppet/resource/status.rb
179 def initialize_from_hash(data)
180   @resource_type = data['resource_type']
181   @provider_used = data['provider_used']
182   @title = data['title']
183   @resource = data['resource']
184   @containment_path = data['containment_path']
185   @file = data['file']
186   @line = data['line']
187   @evaluation_time = data['evaluation_time']
188   @change_count = data['change_count']
189   @out_of_sync_count = data['out_of_sync_count']
190   @tags = Puppet::Util::TagSet.new(data['tags'])
191   @time = data['time']
192   @time = Time.parse(@time) if @time.is_a? String
193   @out_of_sync = data['out_of_sync']
194   @changed = data['changed']
195   @skipped = data['skipped']
196   @failed = data['failed']
197   @failed_to_restart = data['failed_to_restart']
198   @corrective_change = data['corrective_change']
199   @events = data['events'].map do |event|
200     # Older versions contain tags that causes Psych to create instances directly
201     event.is_a?(Puppet::Transaction::Event) ? event : Puppet::Transaction::Event.from_data_hash(event)
202   end
203 end
to_data_hash() click to toggle source
    # File lib/puppet/resource/status.rb
205 def to_data_hash
206   {
207     'title' => @title,
208     'file' => @file,
209     'line' => @line,
210     'resource' => @resource,
211     'resource_type' => @resource_type,
212     'provider_used' => @provider_used,
213     'containment_path' => @containment_path,
214     'evaluation_time' => @evaluation_time,
215     'tags' => @tags.to_a,
216     'time' => @time.iso8601(9),
217     'failed' => @failed,
218     'failed_to_restart' => self.failed_to_restart?,
219     'changed' => @changed,
220     'out_of_sync' => @out_of_sync,
221     'skipped' => @skipped,
222     'change_count' => @change_count,
223     'out_of_sync_count' => @out_of_sync_count,
224     'events' => @events.map { |event| event.to_data_hash },
225     'corrective_change' => @corrective_change,
226   }
227 end