Class: Kanrisuru::Remote::Cluster

Inherits:
Object
  • Object
show all
Extended by:
OsPackage::Collection
Includes:
Enumerable
Defined in:
lib/kanrisuru/core.rb,
lib/kanrisuru/remote/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OsPackage::Collection

os_collection

Constructor Details

#initialize(*hosts) ⇒ Cluster

Returns a new instance of Cluster.



12
13
14
15
16
17
18
19
20
# File 'lib/kanrisuru/remote/cluster.rb', line 12

def initialize(*hosts)
  @parallel = false 
  @concurrency = local_concurrency

  @hosts = {}
  hosts.each do |host_opts|
    add_host(host_opts)
  end
end

Instance Attribute Details

#concurrencyObject

Returns the value of attribute concurrency.



10
11
12
# File 'lib/kanrisuru/remote/cluster.rb', line 10

def concurrency
  @concurrency
end

#parallelObject

Returns the value of attribute parallel.



10
11
12
# File 'lib/kanrisuru/remote/cluster.rb', line 10

def parallel
  @parallel
end

Instance Method Details

#<<(host_opts) ⇒ Object



30
31
32
# File 'lib/kanrisuru/remote/cluster.rb', line 30

def <<(host_opts)
  add_host(host_opts)
end

#[](hostname) ⇒ Object



26
27
28
# File 'lib/kanrisuru/remote/cluster.rb', line 26

def [](hostname)
  @hosts[hostname]
end

#cd(path = '~') ⇒ Object



62
63
64
# File 'lib/kanrisuru/remote/cluster.rb', line 62

def cd(path = '~')
  each { |host| host.cd(path) }
end

#chdir(path = '~') ⇒ Object



58
59
60
# File 'lib/kanrisuru/remote/cluster.rb', line 58

def chdir(path = '~')
  cd(path)
end

#delete(host) ⇒ Object



34
35
36
# File 'lib/kanrisuru/remote/cluster.rb', line 34

def delete(host)
  remove_host(host)
end

#disconnectObject



66
67
68
# File 'lib/kanrisuru/remote/cluster.rb', line 66

def disconnect
  each { |host| host.disconnect }
end

#each(&block) ⇒ Object



74
75
76
# File 'lib/kanrisuru/remote/cluster.rb', line 74

def each(&block)
  parallel? ? each_parallel(preserve: false, &block) : each_sequential(preserve: false, &block)
end

#execute(command) ⇒ Object



38
39
40
# File 'lib/kanrisuru/remote/cluster.rb', line 38

def execute(command)
  map { |host| host.execute(create_command(command)) }
end

#execute_shell(command) ⇒ Object



42
43
44
# File 'lib/kanrisuru/remote/cluster.rb', line 42

def execute_shell(command)
  map { |host| host.execute_shell(create_command(command)) }
end

#hostnameObject



46
47
48
# File 'lib/kanrisuru/remote/cluster.rb', line 46

def hostname
  map { |host| host.send(:hostname) }
end

#hostsObject



22
23
24
# File 'lib/kanrisuru/remote/cluster.rb', line 22

def hosts
  @hosts.values
end

#map(&block) ⇒ Object



70
71
72
# File 'lib/kanrisuru/remote/cluster.rb', line 70

def map(&block)
  parallel? ? each_parallel(preserve: true, &block) : each_sequential(preserve: true, &block)
end

#parallel?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/kanrisuru/remote/cluster.rb', line 78

def parallel?
  @parallel 
end

#ping?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/kanrisuru/remote/cluster.rb', line 50

def ping?
  map { |host| host.send(:ping?) }
end

#sequential?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/kanrisuru/remote/cluster.rb', line 82

def sequential?
  !parallel?
end

#su(user) ⇒ Object



54
55
56
# File 'lib/kanrisuru/remote/cluster.rb', line 54

def su(user)
  each { |host| host.su(user) }
end