Class: Chef::ResourceReporter::ResourceReport
- Inherits:
-
Struct
- Object
- Struct
- Chef::ResourceReporter::ResourceReport
- Defined in:
- lib/chef/resource_reporter.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#current_resource ⇒ Object
Returns the value of attribute current_resource.
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#new_resource ⇒ Object
Returns the value of attribute new_resource.
Class Method Summary collapse
- .new_for_exception(new_resource, action) ⇒ Object
- .new_with_current_state(new_resource, action, current_resource) ⇒ Object
Instance Method Summary collapse
- #finish ⇒ Object
-
#for_json ⇒ Object
Future: Some resources store state information that does not convert nicely to json.
- #success? ⇒ Boolean
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
29 30 31 |
# File 'lib/chef/resource_reporter.rb', line 29 def action @action end |
#current_resource ⇒ Object
Returns the value of attribute current_resource
29 30 31 |
# File 'lib/chef/resource_reporter.rb', line 29 def current_resource @current_resource end |
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time
29 30 31 |
# File 'lib/chef/resource_reporter.rb', line 29 def elapsed_time @elapsed_time end |
#exception ⇒ Object
Returns the value of attribute exception
29 30 31 |
# File 'lib/chef/resource_reporter.rb', line 29 def exception @exception end |
#new_resource ⇒ Object
Returns the value of attribute new_resource
29 30 31 |
# File 'lib/chef/resource_reporter.rb', line 29 def new_resource @new_resource end |
Class Method Details
.new_for_exception(new_resource, action) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/chef/resource_reporter.rb', line 43 def self.new_for_exception(new_resource, action) report = new report.new_resource = new_resource report.action = action report end |
.new_with_current_state(new_resource, action, current_resource) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/chef/resource_reporter.rb', line 35 def self.new_with_current_state(new_resource, action, current_resource) report = new report.new_resource = new_resource report.action = action report.current_resource = current_resource report end |
Instance Method Details
#finish ⇒ Object
85 86 87 |
# File 'lib/chef/resource_reporter.rb', line 85 def finish self.elapsed_time = new_resource.elapsed_time end |
#for_json ⇒ Object
Future: Some resources store state information that does not convert nicely to json. We can’t call a resource’s state method here, since there are conflicts with some LWRPs, so we can’t override a resource’s state method to return json-friendly state data.
The registry key resource returns json-friendly state data through its state attribute, and uses a read-only variable for fetching true state data. If we have conflicts with other resources reporting json incompatible state, we may want to extend the state_attrs API with the ability to rename POST’d attrs.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef/resource_reporter.rb', line 60 def for_json as_hash = {} as_hash["type"] = new_resource.resource_name.to_sym as_hash["name"] = new_resource.name.to_s as_hash["id"] = new_resource.identity.to_s as_hash["after"] = new_resource.state_for_resource_reporter as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {} as_hash["duration"] = (elapsed_time * 1000).to_i.to_s as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff") as_hash["delta"] = "" if as_hash["delta"].nil? # TODO: rename as "action" as_hash["result"] = action.to_s if success? else #as_hash["result"] = "failed" end if new_resource.cookbook_name as_hash["cookbook_name"] = new_resource.cookbook_name as_hash["cookbook_version"] = new_resource.cookbook_version.version end as_hash end |
#success? ⇒ Boolean
89 90 91 |
# File 'lib/chef/resource_reporter.rb', line 89 def success? !self.exception end |