class Kanrisuru::Remote::Cluster

Public Class Methods

new(hosts) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 9
def initialize(hosts)
  @hosts = {}
  hosts.each do |host_opts|
    add_host(host_opts)
  end
end

Public Instance Methods

<<(host_opts) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 20
def <<(host_opts)
  add_host(host_opts)
end
[](hostname) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 16
def [](hostname)
  @hosts[hostname]
end
cd(path = '~') click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 64
def cd(path = '~')
  @hosts.each do |_host_addr, host|
    host.cd(path)
  end
end
chdir(path = '~') click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 60
def chdir(path = '~')
  cd(path)
end
disconnect() click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 70
def disconnect
  @hosts.each do |_host_addr, host|
    host.disconnect
  end
end
each(&block) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 42
def each(&block)
  @hosts.each { |_host_addr, host| block.call(host) }
end
execute(command) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 24
def execute(command)
  @hosts.map do |host_addr, host|
    ## Need to evaluate each host independently for the command.
    cmd = Kanrisuru::Command.new(command)

    { host: host_addr, result: host.execute(cmd) }
  end
end
execute_shell(command) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 33
def execute_shell(command)
  @hosts.map do |host_addr, host|
    ## Need to evaluate each host independently for the command.
    cmd = Kanrisuru::Command.new(command)

    { host: host_addr, result: host.execute_shell(cmd) }
  end
end
hostname() click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 46
def hostname
  map_host_results(:hostname)
end
ping?() click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 50
def ping?
  map_host_results(:ping?)
end
su(user) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 54
def su(user)
  @hosts.each do |_host_addr, host|
    host.su(user)
  end
end

Private Instance Methods

add_host(host_opts) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 84
def add_host(host_opts)
  if host_opts.instance_of?(Hash)
    @hosts[host_opts[:host]] = Kanrisuru::Remote::Host.new(host_opts)
  elsif host_opts.instance_of?(Kanrisuru::Remote::Host)
    @hosts[host_opts.host] = host_opts
  else
    raise 'Not a valid host option'
  end
end
map_host_results(action) click to toggle source
# File lib/kanrisuru/remote/cluster.rb, line 78
def map_host_results(action)
  @hosts.map do |host_addr, host|
    { host: host_addr, result: host.send(action) }
  end
end