Class: Ndo::MultiHost

Inherits:
Object
  • Object
show all
Includes:
Procrastinate
Defined in:
lib/ndo/multi_host.rb

Overview

A class to execute a command on a list of hosts in parallel; allows access to results and is thus a) multi threaded and b) Ruby 1.9.2 only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hosts) ⇒ MultiHost

Returns a new instance of MultiHost.



13
14
15
# File 'lib/ndo/multi_host.rb', line 13

def initialize(hosts)
  @hosts    = hosts
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



11
12
13
# File 'lib/ndo/multi_host.rb', line 11

def hosts
  @hosts
end

Instance Method Details

#run(command) ⇒ Object

Runs the command on all hosts. Returns a result collection.



19
20
21
22
23
24
25
26
27
28
# File 'lib/ndo/multi_host.rb', line 19

def run(command)
  proxy = Procrastinate.proxy(self)

  hosts.inject(Hash.new) do |hash, host_name|
    hash[host_name] = Ndo::Result.new(
      host_name, 
      proxy.run_for_host(command, host_name))
    hash
  end
end

#run_for_host(command, host) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/ndo/multi_host.rb', line 30

def run_for_host(command, host)
  begin
    Ndo::Host.new(host).run(command)
  rescue => b
    b
  end
end