Class: MCollective::Util::BoltSupport::TaskResult

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/bolt_support/task_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, result) ⇒ TaskResult

Returns a new instance of TaskResult.

Parameters:

  • host (String)

    node name

  • result (Hash)

    result value as produced by execution_result methods



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

#hostObject (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

#resultObject (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

Parameters:

  • hash (Hash)

    hash as prodused by various execution_result method

Returns:



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

Parameters:

  • key (String)

    data to access

Returns:

  • (Object)

    the specifiv item in the value hash or the raw value



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

#errorPuppet::DataTypes::Error?

A error object if this represents an error

Returns:

  • (Puppet::DataTypes::Error, nil)


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_okObject 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

#okObject 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

Returns:

  • Boolean



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_hashObject



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_sObject



84
85
86
87
88
89
90
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 84

def to_s
  if Object.const_defined?(:Puppet)
    Puppet::Pops::Types::StringConverter.convert(self, "%p")
  else
    super
  end
end

#typeObject

The type of task that created this result

Returns:

  • String examples like mcollective, data etc



46
47
48
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 46

def type
  @result["type"]
end

#valueObject

Access the value data in raw form

Returns:

  • (Object)

    whatever value the task produced



80
81
82
# File 'lib/mcollective/util/bolt_support/task_result.rb', line 80

def value
  @result["value"]
end