lib/chef/knife/ssh.rb in chef-0.8.6 vs lib/chef/knife/ssh.rb in chef-0.8.8
- old
+ new
@@ -35,27 +35,48 @@
:short => "-a ATTR",
:long => "--attribute ATTR",
:description => "The attribute to use for opening the connection - default is fqdn",
:default => "fqdn"
+ option :manual,
+ :short => "-m",
+ :long => "--manual-list",
+ :boolean => true,
+ :description => "QUERY is a space separated list of servers",
+ :default => false
+
def session
@session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency])
end
def h
@highline ||= HighLine.new
end
def configure_session
- q = Chef::Search::Query.new
- q.search(:node, @name_args[0]) do |item|
- data = format_for_display(item)
- Chef::Log.debug("Adding #{data[config[:attribute]]}")
- session.use data[config[:attribute]]
- @longest = data[config[:attribute]].length if data[config[:attribute]].length > @longest
+ list = case config[:manual]
+ when true
+ @name_args[0].split(" ")
+ when false
+ r = Array.new
+ q = Chef::Search::Query.new
+ q.search(:node, @name_args[0]) do |item|
+ r << format_for_display(item)[config[:attribute]]
+ end
+ r
+ end
+ session_from_list(list)
+ end
+
+ def session_from_list(list)
+ list.each do |item|
+ Chef::Log.debug("Adding #{item}")
+ session.use item
+ @longest = item.length if item.length > @longest
end
+ session
end
def fixup_sudo(command)
command.sub(/^sudo/, 'sudo -p \'knife sudo password: \'')
end
@@ -145,20 +166,36 @@
ssh_command(command)
end
end
end
+ def screen
+ tf = Tempfile.new("knife-ssh-screen")
+ tf.puts("caption always '%w'")
+ tf.puts("hardstatus alwayslastline 'knife ssh #{@name_args[0]}'")
+ window = 0
+ session.servers_for.collect { |s| s.host }.each do |server|
+ tf.puts("screen -t \"#{server}\" #{window} ssh #{server}")
+ window += 1
+ end
+ tf.close
+ exec("screen -c #{tf.path}")
+ end
+
def run
@longest = 0
require 'net/ssh/multi'
require 'readline'
require 'highline'
configure_session
- if @name_args[1] == "interactive"
+ case @name_args[1]
+ when "interactive"
interactive
+ when "screen"
+ screen
else
ssh_command(@name_args[1..-1].join(" "))
end
session.close