Class: Puppet::Resource::Status
Overview
Constant Summary
collapse
- STATES =
[:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
- YAML_ATTRIBUTES =
%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)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included, #mime, #render, #support_format?, #to_msgpack
#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #send_log
#tag, #tagged?, #tags, #tags=
Constructor Details
#initialize(resource) ⇒ Status
Returns a new instance of Status.
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/puppet/resource/status.rb', line 73
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.tags)
@time = Time.now
@events = []
@resource_type = resource.type.to_s.capitalize
@title = resource.title
end
|
Instance Attribute Details
#change_count ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def change_count
@change_count
end
|
#containment_path ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def containment_path
@containment_path
end
|
#current_values ⇒ Object
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def current_values
@current_values
end
|
#default_log_level ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def default_log_level
@default_log_level
end
|
#evaluation_time ⇒ Object
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def evaluation_time
@evaluation_time
end
|
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def file
@file
end
|
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def line
@line
end
|
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def node
@node
end
|
#out_of_sync_count ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def out_of_sync_count
@out_of_sync_count
end
|
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def resource
@resource
end
|
#resource_type ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def resource_type
@resource_type
end
|
#source_description ⇒ Object
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def source_description
@source_description
end
|
11
12
13
|
# File 'lib/puppet/resource/status.rb', line 11
def status
@status
end
|
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def time
@time
end
|
16
17
18
|
# File 'lib/puppet/resource/status.rb', line 16
def title
@title
end
|
Class Method Details
.from_pson(data) ⇒ Object
27
28
29
30
31
|
# File 'lib/puppet/resource/status.rb', line 27
def self.from_pson(data)
obj = self.allocate
obj.initialize_from_hash(data)
obj
end
|
Instance Method Details
#<<(event) ⇒ Object
40
41
42
43
|
# File 'lib/puppet/resource/status.rb', line 40
def <<(event)
add_event(event)
self
end
|
#add_event(event) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/puppet/resource/status.rb', line 45
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
|
59
60
61
|
# File 'lib/puppet/resource/status.rb', line 59
def events
@events
end
|
#failed_because(detail) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/puppet/resource/status.rb', line 63
def failed_because(detail)
@real_resource.log_exception(detail, "Could not evaluate: #{detail}")
failed = true
add_event(@real_resource.event(:name => :resource_error, :status => "failure", :message => detail.to_s))
end
|
#initialize_from_hash(data) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/puppet/resource/status.rb', line 95
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_pson(event)
end
end
|
#to_data_hash ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/puppet/resource/status.rb', line 118
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_pson(*args) ⇒ Object
139
140
141
|
# File 'lib/puppet/resource/status.rb', line 139
def to_pson(*args)
to_data_hash.to_pson(*args)
end
|
#to_yaml_properties ⇒ Object
143
144
145
|
# File 'lib/puppet/resource/status.rb', line 143
def to_yaml_properties
YAML_ATTRIBUTES & super
end
|