Class: Puppet::Resource::Status
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)
Util::Tagging::ValidTagRegex
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included, #mime, #render, #support_format?, #to_msgpack, #to_pson
#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log
#raw_tagged?, #tag, #tagged?, #tags, #tags=
Constructor Details
#initialize(resource) ⇒ Status
Returns a new instance of Status.
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/puppet/resource/status.rb', line 78
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_data_hash(data) ⇒ Object
27
28
29
30
31
|
# File 'lib/puppet/resource/status.rb', line 27
def self.from_data_hash(data)
obj = self.allocate
obj.initialize_from_hash(data)
obj
end
|
.from_pson(data) ⇒ Object
33
34
35
36
|
# File 'lib/puppet/resource/status.rb', line 33
def self.from_pson(data)
Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.")
self.from_data_hash(data)
end
|
Instance Method Details
#<<(event) ⇒ Object
45
46
47
48
|
# File 'lib/puppet/resource/status.rb', line 45
def <<(event)
add_event(event)
self
end
|
#add_event(event) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/puppet/resource/status.rb', line 50
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
|
64
65
66
|
# File 'lib/puppet/resource/status.rb', line 64
def events
@events
end
|
#failed_because(detail) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/puppet/resource/status.rb', line 68
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/puppet/resource/status.rb', line 100
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/puppet/resource/status.rb', line 123
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
144
145
146
|
# File 'lib/puppet/resource/status.rb', line 144
def to_yaml_properties
YAML_ATTRIBUTES & super
end
|