Class: MCollective::Util::BoltSupport::TaskResults

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mcollective/util/bolt_support/task_results.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results, exception = nil) ⇒ TaskResults

Returns a new instance of TaskResults.

Parameters:



24
25
26
27
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 24

def initialize(results, exception=nil)
  @results = results
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



5
6
7
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 5

def exception
  @exception
end

#messageObject



67
68
69
70
71
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 67

def message
  return exception.to_s if exception

  @message
end

#resultsObject (readonly)

Returns the value of attribute results.



5
6
7
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 5

def results
  @results
end

Class Method Details

.from_asserted_hash(results, exception = nil) ⇒ TaskResults

Method used by Puppet to create the TaskResults from a array

Parameters:

  • results (Array<TaskResult>)

    hash as prodused by various execution_result method

Returns:



19
20
21
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 19

def self.from_asserted_hash(results, exception=nil)
  new(results, exception)
end

.include_iterableObject



10
11
12
13
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 10

def self.include_iterable
  include(Puppet::Pops::Types::Iterable)
  include(Puppet::Pops::Types::IteratorProducer)
end

Instance Method Details

#countInteger

Determines the count of results in the set

Returns:

  • (Integer)


106
107
108
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 106

def count
  @results.size
end

#each {|TaskResult| ... } ⇒ Object

Iterate over all results

Yields:



36
37
38
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 36

def each(&block)
  @results.each(&block)
end

#emptyBoolean Also known as: empty?

Determines if the resultset is empty

Returns:

  • (Boolean)


98
99
100
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 98

def empty
  @results.empty?
end

#error_setTaskResults

Set of all the results that are errors regardless of fail_ok

Returns:



43
44
45
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 43

def error_set
  TaskResults.new(@results.select(&:error))
end

#fail_okObject Also known as: fail_ok?



62
63
64
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 62

def fail_ok
  @results.all?(&:fail_ok)
end

#find(host) ⇒ TaskResult?

Finds a result by name

Parameters:

  • host (String)

    node hostname

Returns:



91
92
93
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 91

def find(host)
  @results.find {|r| r.host == host}
end

#firstTaskResult

First result in the set

Returns:



83
84
85
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 83

def first
  @results.first
end

#hostsArray<String>

List of node names for all results

Returns:



76
77
78
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 76

def hosts
  @results.map(&:host)
end

#iteratorObject

Raises:

  • (NotImplementedError)


118
119
120
121
122
123
124
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 118

def iterator
  if Object.const_defined?(:Puppet) && Puppet.const_defined?(:Pops) && self.class.included_modules.include?(Puppet::Pops::Types::Iterable)
    return Puppet::Pops::Types::Iterable.on(@results, TaskResult)
  end

  raise(NotImplementedError, "iterator requires puppet code to be loaded.")
end

#okBoolean Also known as: ok?

Determines if all results are ok, considers fail_ok

Returns:

  • (Boolean)


57
58
59
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 57

def ok
  @results.all?(&:ok)
end

#ok_setTaskResults

Set of all the results that are ok regardless of fail_ok

Returns:



50
51
52
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 50

def ok_set
  TaskResults.new(@results.reject(&:error))
end

#to_json(obj = {}) ⇒ Object



29
30
31
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 29

def to_json(obj={})
  @results.to_json(obj)
end

#to_sObject



110
111
112
113
114
115
116
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 110

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