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
@!attribute [r] change_count
@return [Integer] A count of the successful changes made while evaluating `@real_resource`.
@!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]]"]
@!attribute [r] corrective_change
@return [Boolean] true if the resource contained a corrective change.
@!attribute [rw] evaluation_time
@return [Float] The time elapsed in sections while evaluating `@real_resource`. measured in seconds.
@!attribute [r] events
@return [Array<Puppet::Transaction::Event>] A list of events generated while evaluating `@real_resource`.
@!attribute [rw] failed_dependencies
@return [Array<Puppet::Resource>] A cache of all dependencies of this resource that failed to apply.
@!attribute [rw] file
@return [String] The file where `@real_resource` was defined.
@!attribute [rw] line
@return [Integer] The line number in the file where `@real_resource` was defined.
@!attribute [r] out_of_sync_count
@return [Integer] A count of the audited changes made while evaluating `@real_resource`.
@!attribute [rw] provider_used
@return [String] The class name of the provider used for the resource
@!attribute [r] resource
@return [String] The resource reference for `@real_resource`
@!attribute [r] resource_type
@example status.resource_type #=> 'Notify' @return [String] The class name of `@real_resource`
@!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]"
@!attribute [r] time
@return [Time] The time that this status object was created
@!attribute [r] title
@return [String] The title of `@real_resource`
Public Class Methods
# 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
# 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
# File lib/puppet/resource/status.rb 116 def <<(event) 117 add_event(event) 118 self 119 end
# 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
# File lib/puppet/resource/status.rb 99 def dependency_failed? 100 failed_dependencies && !failed_dependencies.empty? 101 end
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
# 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
# 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
# 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