Class: Puppet::Resource::Status Private

Inherits:
Object
  • Object
show all
Includes:
Network::FormatSupport, Util::PsychSupport, 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.

API:

  • private

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`.

API:

  • private

[:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled, :corrective_change]

Constants included from Util::Tagging

Util::Tagging::ValidTagRegex

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_from, #raw_tagged?, #set_tags, #tag, #tag_if_valid, #tagged?, #tags, #tags=, #valid_tag?

Methods included from Util::PsychSupport

#encode_with, #init_with

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.

API:

  • private



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/puppet/resource/status.rb', line 156

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
  @corrective_change = false

  @file = resource.file
  @line = resource.line

  merge_tags_from(resource)
  @time = Time.now
  @events = []
  @resource_type = resource.type.to_s.capitalize
  @provider_used = resource.provider.class.name.to_s unless resource.provider.nil?
  @title = resource.title
end

Instance Attribute Details

#change_countObject (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.

API:

  • private



65
66
67
# File 'lib/puppet/resource/status.rb', line 65

def change_count
  @change_count
end

#containment_pathObject (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.

API:

  • private



52
53
54
# File 'lib/puppet/resource/status.rb', line 52

def containment_path
  @containment_path
end

#corrective_changeObject (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.

API:

  • private



93
94
95
# File 'lib/puppet/resource/status.rb', line 93

def corrective_change
  @corrective_change
end

#evaluation_timeFloat

Returns The time elapsed in sections while evaluating ‘@real_resource`. measured in seconds.

Returns:

  • The time elapsed in sections while evaluating ‘@real_resource`. measured in seconds.



31
32
33
# File 'lib/puppet/resource/status.rb', line 31

def evaluation_time
  @evaluation_time
end

#eventsObject (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.

API:

  • private



89
90
91
# File 'lib/puppet/resource/status.rb', line 89

def events
  @events
end

#failed_dependenciesArray<Puppet::Resource>

dependencies of this resource that failed to apply.

Returns:

  • A cache of all



98
99
100
# File 'lib/puppet/resource/status.rb', line 98

def failed_dependencies
  @failed_dependencies
end

#fileString

Returns The file where ‘@real_resource` was defined.

Returns:

  • The file where ‘@real_resource` was defined.



22
23
24
# File 'lib/puppet/resource/status.rb', line 22

def file
  @file
end

#lineInteger

Returns The line number in the file where ‘@real_resource` was defined.

Returns:

  • The line number in the file where ‘@real_resource` was defined.



26
27
28
# File 'lib/puppet/resource/status.rb', line 26

def line
  @line
end

#out_of_sync_countObject (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.

API:

  • private



70
71
72
# File 'lib/puppet/resource/status.rb', line 70

def out_of_sync_count
  @out_of_sync_count
end

#provider_usedString

Returns The class name of the provider used for the resource.

Returns:

  • The class name of the provider used for the resource



80
81
82
# File 'lib/puppet/resource/status.rb', line 80

def provider_used
  @provider_used
end

#resourceObject (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.

API:

  • private



60
61
62
# File 'lib/puppet/resource/status.rb', line 60

def resource
  @resource
end

#resource_typeObject (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.

API:

  • private



76
77
78
# File 'lib/puppet/resource/status.rb', line 76

def resource_type
  @resource_type
end

#source_descriptionObject (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.

API:

  • private



43
44
45
# File 'lib/puppet/resource/status.rb', line 43

def source_description
  @source_description
end

#timeObject (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.

API:

  • private



56
57
58
# File 'lib/puppet/resource/status.rb', line 56

def time
  @time
end

#titleObject (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.

API:

  • private



84
85
86
# File 'lib/puppet/resource/status.rb', line 84

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.

API:

  • private



104
105
106
107
108
# File 'lib/puppet/resource/status.rb', line 104

def self.from_data_hash(data)
  obj = 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.

API:

  • private



117
118
119
120
# File 'lib/puppet/resource/status.rb', line 117

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.

API:

  • private



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/puppet/resource/status.rb', line 122

def add_event(event)
  @events << event
  case event.status
  when 'failure'
    self.failed = true
  when 'success'
    @change_count += 1
    @changed = true
  end
  if event.status != 'audit'
    @out_of_sync_count += 1
    @out_of_sync = true
  end
  if event.corrective_change
    @corrective_change = 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.

Returns:

API:

  • private



100
101
102
# File 'lib/puppet/resource/status.rb', line 100

def dependency_failed?
  failed_dependencies && !failed_dependencies.empty?
end

#fail_with_event(message) ⇒ 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.

Both set the status state to failed and generate a corresponding Puppet::Transaction::Event failure with the given message.

Parameters:

  • the reason for a status failure

API:

  • private



152
153
154
# File 'lib/puppet/resource/status.rb', line 152

def fail_with_event(message)
  add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => message))
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.

API:

  • private



140
141
142
143
144
145
146
147
# File 'lib/puppet/resource/status.rb', line 140

def failed_because(detail)
  @real_resource.log_exception(detail, _("Could not evaluate: %{detail}") % { detail: detail })
  # 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.
  fail_with_event(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.

API:

  • private



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/puppet/resource/status.rb', line 180

def initialize_from_hash(data)
  @resource_type = data['resource_type']
  @provider_used = data['provider_used']
  @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']
  @failed_to_restart = data['failed_to_restart']
  @corrective_change = data['corrective_change']
  @events = data['events'].map do |event|
    # Older versions contain tags that causes Psych to create instances directly
    event.is_a?(Puppet::Transaction::Event) ? event : Puppet::Transaction::Event.from_data_hash(event)
  end
end

#to_data_hashObject

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.

API:

  • private



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/puppet/resource/status.rb', line 206

def to_data_hash
  {
    'title' => @title,
    'file' => @file,
    'line' => @line,
    'resource' => @resource,
    'resource_type' => @resource_type,
    'provider_used' => @provider_used,
    'containment_path' => @containment_path,
    'evaluation_time' => @evaluation_time,
    'tags' => @tags.to_a,
    'time' => @time.iso8601(9),
    'failed' => @failed,
    'failed_to_restart' => failed_to_restart?,
    'changed' => @changed,
    'out_of_sync' => @out_of_sync,
    'skipped' => @skipped,
    'change_count' => @change_count,
    'out_of_sync_count' => @out_of_sync_count,
    'events' => @events.map(&:to_data_hash),
    'corrective_change' => @corrective_change,
  }
end