Class: MCollective::Util::BoltSupport::TaskResult
- Inherits:
-
Object
- Object
- MCollective::Util::BoltSupport::TaskResult
- Defined in:
- lib/mcollective/util/bolt_support/task_result.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.from_asserted_hash(hash) ⇒ TaskResult
Method used by Puppet to create the TaskResult from a hash.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access the value data embedded in the result.
-
#bolt_task_result ⇒ Object
Access the value returned by a Bolt task.
-
#error ⇒ Puppet::DataTypes::Error?
A error object if this represents an error.
- #fail_ok ⇒ Object (also: #fail_ok?)
-
#initialize(host, result) ⇒ TaskResult
constructor
A new instance of TaskResult.
-
#ok ⇒ Object
(also: #ok?)
If this task result represents a succesful task.
- #to_hash ⇒ Object
- #to_json(obj = {}) ⇒ Object
- #to_s ⇒ Object
-
#type ⇒ Object
The type of task that created this result.
-
#value ⇒ Object
Access the value data in raw form.
Constructor Details
#initialize(host, result) ⇒ TaskResult
Returns a new instance of TaskResult.
17 18 19 20 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 17 def initialize(host, result) @host = host @result = result end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 5 def host @host end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 5 def result @result end |
Class Method Details
.from_asserted_hash(hash) ⇒ TaskResult
Method used by Puppet to create the TaskResult from a hash
11 12 13 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 11 def self.from_asserted_hash(hash) new(hash.keys.first, hash.values.first) end |
Instance Method Details
#[](key) ⇒ Object
Access the value data embedded in the result
71 72 73 74 75 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 71 def [](key) return @result["value"] unless @result["value"].is_a?(Hash) @result["value"][key] end |
#bolt_task_result ⇒ Object
Access the value returned by a Bolt task
87 88 89 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 87 def bolt_task_result @bolt_task_result ||= JSON.parse(@result["value"]["data"]["stdout"]) end |
#error ⇒ Puppet::DataTypes::Error?
A error object if this represents an error
33 34 35 36 37 38 39 40 41 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 33 def error if @result["error"] if defined?(Puppet::DataTypes::Error) Puppet::DataTypes::Error.from_asserted_hash(@result["error"]) else @result["error"] end end end |
#fail_ok ⇒ Object Also known as: fail_ok?
62 63 64 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 62 def fail_ok @result["fail_ok"] end |
#ok ⇒ Object Also known as: ok?
If this task result represents a succesful task
This supposed fail_ok, any task with that set will be considered passed
55 56 57 58 59 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 55 def ok return true if @result["fail_ok"] !@result.include?("error") end |
#to_hash ⇒ Object
22 23 24 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 22 def to_hash {@host => @result} end |
#to_json(obj = {}) ⇒ Object
26 27 28 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 26 def to_json(obj={}) to_hash.to_json(obj) end |
#to_s ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 91 def to_s if Object.const_defined?(:Puppet) Puppet::Pops::Types::StringConverter.convert(self, "%p") else super end end |
#type ⇒ Object
The type of task that created this result
46 47 48 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 46 def type @result["type"] end |
#value ⇒ Object
Access the value data in raw form
80 81 82 |
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 80 def value @result["value"] end |