# File lib/rhc/ssh_helpers.rb, line 34 def run(&block) out = nil Net::SSH::Multi.start( :concurrent_connections => @opts[:limit], :on_error => lambda{ |server| $stderr.puts RHC::Helpers.color("Unable to connect to gear #{server}", :red) } ) do |session| @over.each do |item| case item when RHC::Rest::GearGroup item.gears.each do |gear| session.use ssh_host_for(gear), :properties => {:gear => gear, :group => item} end #when RHC::Rest::Gear # session.use ssh_host_for(item), :properties => {:gear => item} #end else raise "Cannot establish an SSH session to this type" end end session.exec @command, &( case when @opts[:raw] lambda { |ch, dest, data| (dest == :stdout ? $stdout : $stderr).puts data } when @opts[:as] == :table out = [] lambda { |ch, dest, data| label = label_for(ch) data.chomp.each_line do |line| row = out.find{ |row| row[0] == label } || (out << [label, []])[-1] row[1] << line end } when @opts[:as] == :gear lambda { |ch, dest, data| (ch.connection.properties[:gear]['data'] ||= "") << data } else width = 0 lambda { |ch, dest, data| label = label_for(ch) io = dest == :stdout ? $stdout : $stderr data.chomp! if data.each_line.to_a.count < 2 io.puts "[#{label}] #{data}" elsif @opts[:always_prefix] data.each_line do |line| io.puts "[#{label}] #{line}" end else io.puts "=== #{label}" io.puts data end } end) session.loop end if block_given? && !@opts[:raw] case when @opts[:as] == :gear out = [] @over.each do |item| case item when RHC::Rest::GearGroup then item.gears.each{ |gear| out << yield(gear, gear['data'], item) } #when RHC::Rest::Gear then out << yield(gear, gear['data'], nil) end end end end out end
# File lib/rhc/ssh_helpers.rb, line 122 def key_for(channel) channel.connection.properties[:gear]['id'] end
# File lib/rhc/ssh_helpers.rb, line 114 def label_for(channel) channel.properties[:label] ||= begin group = channel.connection.properties[:group] "#{key_for(channel)} #{group.cartridges.map{ |c| c['name'] }.join('+')}" end end
# File lib/rhc/ssh_helpers.rb, line 126 def requires_ssh_multi! begin require 'net/ssh/multi' rescue LoadError raise RHC::OperationNotSupportedException, "You must install Net::SSH::Multi to use the --gears option. Most systems: 'gem install net-ssh-multi'" end end
Generated with the Darkfish Rdoc Generator 2.