Class: MRunEnv::SSHAgent
- Inherits:
-
Object
- Object
- MRunEnv::SSHAgent
- Defined in:
- ext/lib/CompLearnLib/RunEnv.rb
Class Method Summary collapse
- .checkHost(hostname) ⇒ Object
- .helperHosts ⇒ Object
- .isRunning? ⇒ Boolean
- .liveHosts ⇒ Object
- .primaryHost ⇒ Object
- .runAt(cmd, h) ⇒ Object
- .runEverywhere(cmd) ⇒ Object
-
.writeGoodHostFile ⇒ Object
returns filename of new hosts file.
Class Method Details
.checkHost(hostname) ⇒ Object
105 106 107 108 109 110 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 105 def SSHAgent.checkHost(hostname) puts "Checking #{hostname}" result = `unset DISPLAY ; setsid ssh #{hostname} hostname -s` result.gsub!(/\s/,'') hostname == result end |
.helperHosts ⇒ Object
126 127 128 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 126 def SSHAgent.helperHosts() CLConfig.getDefaultConfig().hosts[1..-1] end |
.isRunning? ⇒ Boolean
102 103 104 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 102 def SSHAgent.isRunning?() SSHAgent.checkHost(SSHAgent.primaryHost) end |
.liveHosts ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 129 def SSHAgent.liveHosts() unless SSHAgent.isRunning? puts "Sorry, you forgot to start ssh-agent or run ssh-add" exit(1) end alive = [ ] SSHAgent.helperHosts.each { |h| alive << h if SSHAgent.checkHost(h) } alive end |
.primaryHost ⇒ Object
111 112 113 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 111 def SSHAgent.primaryHost() CLConfig.getDefaultConfig().hosts[0] end |
.runAt(cmd, h) ⇒ Object
114 115 116 117 118 119 120 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 114 def SSHAgent.runAt(cmd, h) if (h == 'dorado') puts "Skipping running #{cmd} on dorado" else `unset DISPLAY ; setsid ssh #{h} #{cmd}` end end |
.runEverywhere(cmd) ⇒ Object
121 122 123 124 125 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 121 def SSHAgent.runEverywhere(cmd) [SSHAgent.primaryHost(), SSHAgent.helperHosts()].flatten.each { |h| SSHAgent.runAt(cmd, h) } end |
.writeGoodHostFile ⇒ Object
returns filename of new hosts file
138 139 140 141 142 143 144 145 146 147 |
# File 'ext/lib/CompLearnLib/RunEnv.rb', line 138 def SSHAgent.writeGoodHostFile() # returns filename of new hosts file cfg = CLConfig.getDefaultConfig fname = RunEnv.getTemporaryFilename() f = File.open(fname, "wb") cfg.hosts.each { |h| f.write("#{h}\n") } f.close fname end |