Class: Kanrisuru::Remote::Cluster
- Inherits:
-
Object
- Object
- Kanrisuru::Remote::Cluster
- Extended by:
- OsPackage::Collection
- Includes:
- Enumerable
- Defined in:
- lib/kanrisuru/core.rb,
lib/kanrisuru/remote/cluster.rb
Instance Method Summary collapse
- #<<(host_opts) ⇒ Object
- #[](hostname) ⇒ Object
- #cd(path = '~') ⇒ Object
- #chdir(path = '~') ⇒ Object
- #delete(host) ⇒ Object
- #disconnect ⇒ Object
- #each(&block) ⇒ Object
- #execute(command) ⇒ Object
- #execute_shell(command) ⇒ Object
- #hostname ⇒ Object
- #hosts ⇒ Object
-
#initialize(*hosts) ⇒ Cluster
constructor
A new instance of Cluster.
- #ping? ⇒ Boolean
- #su(user) ⇒ Object
Methods included from OsPackage::Collection
Constructor Details
#initialize(*hosts) ⇒ Cluster
Returns a new instance of Cluster.
9 10 11 12 13 14 |
# File 'lib/kanrisuru/remote/cluster.rb', line 9 def initialize(*hosts) @hosts = {} hosts.each do |host_opts| add_host(host_opts) end end |
Instance Method Details
#<<(host_opts) ⇒ Object
24 25 26 |
# File 'lib/kanrisuru/remote/cluster.rb', line 24 def <<(host_opts) add_host(host_opts) end |
#[](hostname) ⇒ Object
20 21 22 |
# File 'lib/kanrisuru/remote/cluster.rb', line 20 def [](hostname) @hosts[hostname] end |
#cd(path = '~') ⇒ Object
72 73 74 75 76 |
# File 'lib/kanrisuru/remote/cluster.rb', line 72 def cd(path = '~') @hosts.each do |_host_addr, host| host.cd(path) end end |
#chdir(path = '~') ⇒ Object
68 69 70 |
# File 'lib/kanrisuru/remote/cluster.rb', line 68 def chdir(path = '~') cd(path) end |
#delete(host) ⇒ Object
28 29 30 |
# File 'lib/kanrisuru/remote/cluster.rb', line 28 def delete(host) remove_host(host) end |
#disconnect ⇒ Object
78 79 80 81 82 |
# File 'lib/kanrisuru/remote/cluster.rb', line 78 def disconnect @hosts.each do |_host_addr, host| host.disconnect end end |
#each(&block) ⇒ Object
50 51 52 |
# File 'lib/kanrisuru/remote/cluster.rb', line 50 def each(&block) @hosts.each { |_host_addr, host| block.call(host) } end |
#execute(command) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/kanrisuru/remote/cluster.rb', line 32 def execute(command) @hosts.map do |host_addr, host| ## Need to evaluate each host independently for the command. cmd = create_command(command) { host: host_addr, result: host.execute(cmd) } end end |
#execute_shell(command) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/kanrisuru/remote/cluster.rb', line 41 def execute_shell(command) @hosts.map do |host_addr, host| ## Need to evaluate each host independently for the command. cmd = create_command(command) { host: host_addr, result: host.execute_shell(cmd) } end end |
#hostname ⇒ Object
54 55 56 |
# File 'lib/kanrisuru/remote/cluster.rb', line 54 def hostname map_host_results(:hostname) end |
#hosts ⇒ Object
16 17 18 |
# File 'lib/kanrisuru/remote/cluster.rb', line 16 def hosts @hosts.values end |
#ping? ⇒ Boolean
58 59 60 |
# File 'lib/kanrisuru/remote/cluster.rb', line 58 def ping? map_host_results(:ping?) end |
#su(user) ⇒ Object
62 63 64 65 66 |
# File 'lib/kanrisuru/remote/cluster.rb', line 62 def su(user) @hosts.each do |_host_addr, host| host.su(user) end end |