lib/knife/undev/plugins/cloud_ssh.rb in knife-undev-0.0.9 vs lib/knife/undev/plugins/cloud_ssh.rb in knife-undev-0.1.0
- old
+ new
@@ -24,11 +24,11 @@
include Chef::Mixin::ShellOut
attr_writer :password
- banner "knife private_ssh QUERY COMMAND (options)"
+ banner "knife cloud_ssh QUERY COMMAND (options)"
option :concurrency,
:short => "-C NUM",
:long => "--concurrency NUM",
:description => "The number of concurrent connections",
@@ -262,11 +262,60 @@
config[:attribute] = (Chef::Config[:knife][:ssh_attribute] ||
config[:attribute] ||
"private_ipaddress").strip
end
+ def read_line
+ loop do
+ command = reader.readline("#{ui.color('knife-ssh>', :bold)} ", true)
+ if command.nil?
+ command = "exit"
+ puts(command)
+ else
+ command.strip!
+ end
+
+ unless command.empty?
+ return command
+ end
+ end
+ end
+
+ def reader
+ Readline
+ end
+
+ def interactive
+ puts "Connected to #{ui.list(session.servers_for.collect { |s| ui.color(s.host, :cyan) }, :inline, " and ")}"
+ puts
+ puts "To run a command on a list of servers, do:"
+ puts " on SERVER1 SERVER2 SERVER3; COMMAND"
+ puts " Example: on latte foamy; echo foobar"
+ puts
+ puts "To exit interactive mode, use 'quit!'"
+ puts
+ while 1
+ command = read_line
+ case command
+ when 'quit!'
+ puts 'Bye!'
+ break
+ when /^on (.+?); (.+)$/
+ raw_list = $1.split(" ")
+ server_list = Array.new
+ session.servers.each do |session_server|
+ server_list << session_server if raw_list.include?(session_server.host)
+ end
+ command = $2
+ ssh_command(command, session.on(*server_list))
+ else
+ ssh_command(command)
+ end
+ end
+ end
+
def get_stripped_unfrozen_value(value)
return nil if value.nil?
value.strip
end
@@ -303,10 +352,17 @@
configure_user
configure_identity_file
configure_gateway
configure_session
- exit_status = ssh_command(@name_args[1..-1].join(" "))
+ exit_status =
+ case @name_args[1]
+ when "interactive"
+ interactive
+ else
+ ssh_command(@name_args[1..-1].join(" "))
+ end
+
session.close
print_failed(@failed_connect_nodes)
print_failed(@not_zerro_nodes)