Class: Jssh
- Inherits:
-
Object
- Object
- Jssh
- Defined in:
- lib/jssh.rb,
lib/jssh/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#auth_cfg ⇒ Object
Returns the value of attribute auth_cfg.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #execute(from = 0, len = nil, group_size = 1) ⇒ Object
- #go(from = 0, len = nil) ⇒ Object
-
#initialize ⇒ Jssh
constructor
A new instance of Jssh.
- #messages ⇒ Object
Constructor Details
#initialize ⇒ Jssh
Returns a new instance of Jssh.
8 9 10 11 12 |
# File 'lib/jssh.rb', line 8 def initialize @auth_cfg={} self.printer=Printer.new(StdoutExecutor.new) @queue=Queue.new end |
Instance Attribute Details
#auth_cfg ⇒ Object
Returns the value of attribute auth_cfg.
6 7 8 |
# File 'lib/jssh.rb', line 6 def auth_cfg @auth_cfg end |
#cmd ⇒ Object
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/jssh.rb', line 6 def cmd @cmd end |
#hosts ⇒ Object
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/jssh.rb', line 6 def hosts @hosts end |
#printer ⇒ Object
Returns the value of attribute printer.
6 7 8 |
# File 'lib/jssh.rb', line 6 def printer @printer end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/jssh.rb', line 6 def user @user end |
Instance Method Details
#execute(from = 0, len = nil, group_size = 1) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jssh.rb', line 38 def execute(from=0,len=nil,group_size=1) pr=start_printer(self) threads=[] len||=self.hosts.size to=from+len-1 divider(self.hosts[from..to].size,group_size) do |df,dt| threads<<Thread.new(self,from+df,from+dt) do |rssh,f,t| rssh.go(f,t) do |h,r,over| rssh..push({'host'=>h,'content'=>r,'finished'=>over}) end end end threads.each{|t| t.join} loop{ break if self.printer.finished? } Thread.kill pr end |
#go(from = 0, len = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jssh.rb', line 17 def go(from=0,len=nil) len||=self.hosts.size to=from+len-1 password=self.auth_cfg[:password] keys=[self.auth_cfg[:key]].reject{|x| x.nil?} self.hosts[from..to].each_with_index do |host,i| begin Net::SSH.start(host,self.user,:keys=>keys,:password=>password) do |ssh| result=ssh.exec!(self.cmd) || '' ssh.exec!(self.cmd) do |ch,stream,data| data||='' yield host,data,false if block_given? end end rescue=>e result=e.to_s end result||='' yield host,result,true if block_given? end end |
#messages ⇒ Object
13 14 15 |
# File 'lib/jssh.rb', line 13 def @queue end |