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

Public Instance Methods

<<(event) click to toggle source
    # File lib/puppet/resource/status.rb
116 def <<(event)
117   add_event(event)
118   self
119 end
add_event(event) click to toggle source
    # File lib/puppet/resource/status.rb
121 def add_event(event)
122   @events << event
123   if event.status == 'failure'
124     self.failed = true
125   elsif event.status == 'success'
126     @change_count += 1
127     @changed = true
128   end
129   if event.status != 'audit'
130     @out_of_sync_count += 1
131     @out_of_sync = true
132   end
133   if event.corrective_change
134     @corrective_change = true
135   end
136 end
dependency_failed?() click to toggle source
    # File lib/puppet/resource/status.rb
 99 def dependency_failed?
100   failed_dependencies && !failed_dependencies.empty?
101 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
150 def fail_with_event(message)
151   add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => message))
152 end
failed_because(detail) click to toggle source
    # File lib/puppet/resource/status.rb
138 def failed_because(detail)
139   @real_resource.log_exception(detail, _("Could not evaluate: %{detail}") % { detail: detail })
140   # There's a contract (implicit unfortunately) that a status of failed
141   # will always be accompanied by an event with some explanatory power.  This
142   # is useful for reporting/diagnostics/etc.  So synthesize an event here
143   # with the exception detail as the message.
144   fail_with_event(detail.to_s)
145 end
initialize_from_hash(data) click to toggle source
    # File lib/puppet/resource/status.rb
178 def initialize_from_hash(data)
179   @resource_type = data['resource_type']
180   @provider_used = data['provider_used']
181   @title = data['title']
182   @resource = data['resource']
183   @containment_path = data['containment_path']
184   @file = data['file']
185   @line = data['line']
186   @evaluation_time = data['evaluation_time']
187   @change_count = data['change_count']
188   @out_of_sync_count = data['out_of_sync_count']
189   @tags = Puppet::Util::TagSet.new(data['tags'])
190   @time = data['time']
191   @time = Time.parse(@time) if @time.is_a? String
192   @out_of_sync = data['out_of_sync']
193   @changed = data['changed']
194   @skipped = data['skipped']
195   @failed = data['failed']
196   @failed_to_restart = data['failed_to_restart']
197   @corrective_change = data['corrective_change']
198   @events = data['events'].map do |event|
199     # Older versions contain tags that causes Psych to create instances directly
200     event.is_a?(Puppet::Transaction::Event) ? event : Puppet::Transaction::Event.from_data_hash(event)
201   end
202 end
to_data_hash() click to toggle source
    # File lib/puppet/resource/status.rb
204 def to_data_hash
205   {
206     'title' => @title,
207     'file' => @file,
208     'line' => @line,
209     'resource' => @resource,
210     'resource_type' => @resource_type,
211     'provider_used' => @provider_used,
212     'containment_path' => @containment_path,
213     'evaluation_time' => @evaluation_time,
214     'tags' => @tags.to_a,
215     'time' => @time.iso8601(9),
216     'failed' => @failed,
217     'failed_to_restart' => self.failed_to_restart?,
218     'changed' => @changed,
219     'out_of_sync' => @out_of_sync,
220     'skipped' => @skipped,
221     'change_count' => @change_count,
222     'out_of_sync_count' => @out_of_sync_count,
223     'events' => @events.map { |event| event.to_data_hash },
224     'corrective_change' => @corrective_change,
225   }
226 end