Class: Puppet::Resource::Status Private
- Includes:
- Network::FormatSupport, Util::Tagging
- Defined in:
- lib/puppet/resource/status.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Constant Summary collapse
- STATES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Boolean status types set while evaluating ‘@real_resource`.
[:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
- YAML_ATTRIBUTES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A list of instance variables that should be serialized with this object when converted to YAML.
%w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped @failed @containment_path}. map(&:to_sym)
Constants included from Util::Tagging
Instance Attribute Summary collapse
- #change_count ⇒ Object readonly private
- #containment_path ⇒ Object readonly private
-
#evaluation_time ⇒ Float
The time elapsed in sections while evaluating ‘@real_resource`.
- #events ⇒ Object readonly private
-
#failed_dependencies ⇒ Array<Puppet::Resource>
dependencies of this resource that failed to apply.
-
#file ⇒ String
The file where ‘@real_resource` was defined.
-
#line ⇒ Integer
The line number in the file where ‘@real_resource` was defined.
- #out_of_sync_count ⇒ Object readonly private
- #resource ⇒ Object readonly private
- #resource_type ⇒ Object readonly private
- #source_description ⇒ Object readonly private
- #time ⇒ Object readonly private
- #title ⇒ Object readonly private
Class Method Summary collapse
- .from_data_hash(data) ⇒ Object private
Instance Method Summary collapse
- #<<(event) ⇒ Object private
- #add_event(event) ⇒ Object private
- #dependency_failed? ⇒ Boolean private
- #failed_because(detail) ⇒ Object private
-
#initialize(resource) ⇒ Status
constructor
private
A new instance of Status.
- #initialize_from_hash(data) ⇒ Object private
- #to_data_hash ⇒ Object private
- #to_yaml_properties ⇒ Object private
Methods included from Network::FormatSupport
included, #mime, #render, #support_format?, #to_json, #to_msgpack, #to_pson
Methods included from Util::Tagging
#merge_into, #merge_tags, #raw_tagged?, #set_tags, #tag, #tag_if_valid, #tagged?, #tags, #tags=
Constructor Details
#initialize(resource) ⇒ Status
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Status.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/puppet/resource/status.rb', line 143 def initialize(resource) @real_resource = resource @source_description = resource.path @containment_path = resource.pathbuilder @resource = resource.to_s @change_count = 0 @out_of_sync_count = 0 @changed = false @out_of_sync = false @skipped = false @failed = false @file = resource.file @line = resource.line tag(*resource.) @time = Time.now @events = [] @resource_type = resource.type.to_s.capitalize @title = resource.title end |
Instance Attribute Details
#change_count ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/puppet/resource/status.rb', line 62 def change_count @change_count end |
#containment_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/puppet/resource/status.rb', line 49 def containment_path @containment_path end |
#evaluation_time ⇒ Float
Returns The time elapsed in sections while evaluating ‘@real_resource`. measured in seconds.
28 29 30 |
# File 'lib/puppet/resource/status.rb', line 28 def evaluation_time @evaluation_time end |
#events ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/puppet/resource/status.rb', line 82 def events @events end |
#failed_dependencies ⇒ Array<Puppet::Resource>
dependencies of this resource that failed to apply.
87 88 89 |
# File 'lib/puppet/resource/status.rb', line 87 def failed_dependencies @failed_dependencies end |
#file ⇒ String
Returns The file where ‘@real_resource` was defined.
19 20 21 |
# File 'lib/puppet/resource/status.rb', line 19 def file @file end |
#line ⇒ Integer
Returns The line number in the file where ‘@real_resource` was defined.
23 24 25 |
# File 'lib/puppet/resource/status.rb', line 23 def line @line end |
#out_of_sync_count ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/puppet/resource/status.rb', line 67 def out_of_sync_count @out_of_sync_count end |
#resource ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 |
# File 'lib/puppet/resource/status.rb', line 57 def resource @resource end |
#resource_type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/puppet/resource/status.rb', line 73 def resource_type @resource_type end |
#source_description ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/puppet/resource/status.rb', line 40 def source_description @source_description end |
#time ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/puppet/resource/status.rb', line 53 def time @time end |
#title ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/puppet/resource/status.rb', line 77 def title @title end |
Class Method Details
.from_data_hash(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 104 105 |
# File 'lib/puppet/resource/status.rb', line 101 def self.from_data_hash(data) obj = self.allocate obj.initialize_from_hash(data) obj end |
Instance Method Details
#<<(event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 117 |
# File 'lib/puppet/resource/status.rb', line 114 def <<(event) add_event(event) self end |
#add_event(event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/puppet/resource/status.rb', line 119 def add_event(event) @events << event if event.status == 'failure' self.failed = true elsif event.status == 'success' @change_count += 1 @changed = true end if event.status != 'audit' @out_of_sync_count += 1 @out_of_sync = true end end |
#dependency_failed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/puppet/resource/status.rb', line 89 def dependency_failed? failed_dependencies && !failed_dependencies.empty? end |
#failed_because(detail) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
133 134 135 136 137 138 139 140 141 |
# File 'lib/puppet/resource/status.rb', line 133 def failed_because(detail) @real_resource.log_exception(detail, "Could not evaluate: #{detail}") failed = true # There's a contract (implicit unfortunately) that a status of failed # will always be accompanied by an event with some explanatory power. This # is useful for reporting/diagnostics/etc. So synthesize an event here # with the exception detail as the message. add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => detail.to_s)) end |
#initialize_from_hash(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/puppet/resource/status.rb', line 165 def initialize_from_hash(data) @resource_type = data['resource_type'] @title = data['title'] @resource = data['resource'] @containment_path = data['containment_path'] @file = data['file'] @line = data['line'] @evaluation_time = data['evaluation_time'] @change_count = data['change_count'] @out_of_sync_count = data['out_of_sync_count'] @tags = Puppet::Util::TagSet.new(data['tags']) @time = data['time'] @time = Time.parse(@time) if @time.is_a? String @out_of_sync = data['out_of_sync'] @changed = data['changed'] @skipped = data['skipped'] @failed = data['failed'] @events = data['events'].map do |event| Puppet::Transaction::Event.from_data_hash(event) end end |
#to_data_hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/puppet/resource/status.rb', line 188 def to_data_hash { 'title' => @title, 'file' => @file, 'line' => @line, 'resource' => @resource, 'resource_type' => @resource_type, 'containment_path' => @containment_path, 'evaluation_time' => @evaluation_time, 'tags' => @tags, 'time' => @time.iso8601(9), 'failed' => @failed, 'changed' => @changed, 'out_of_sync' => @out_of_sync, 'skipped' => @skipped, 'change_count' => @change_count, 'out_of_sync_count' => @out_of_sync_count, 'events' => @events, } end |
#to_yaml_properties ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
209 210 211 |
# File 'lib/puppet/resource/status.rb', line 209 def to_yaml_properties YAML_ATTRIBUTES & super end |