lib/knife/undev/plugins/cloud_ssh.rb in knife-undev-0.1.1 vs lib/knife/undev/plugins/cloud_ssh.rb in knife-undev-0.1.2
- old
+ new
@@ -87,10 +87,11 @@
:default => false
def session
config[:on_error] ||= :skip
ssh_error_handler = Proc.new do |server|
+
@failed_connect_nodes << { "node" => server.host , "message" => "#{$!.class.name}: #{$!.message}" }
if config[:manual]
node_name = server.host
else
@action_nodes.each do |n|
@@ -127,10 +128,11 @@
end
def configure_session
list = case config[:manual]
when true
+ @all_nodes += @name_args[0].split(" ")
@name_args[0].split(" ")
when false
r = Array.new
q = Chef::Search::Query.new
@action_nodes = q.search(:node, @name_args[0])[0]
@@ -147,10 +149,11 @@
i = extract_nested_value(item, config[:attribute])
end
# next if we couldn't find the specified attribute in the returned node object
next if i.nil?
r.push(i)
+ @all_nodes << item[:fqdn]
end
r
end
if list.length == 0
if @action_nodes.length == 0
@@ -238,11 +241,11 @@
ichannel.send_data("#{get_password}\n")
end
end
ch.on_request "exit-status" do |ichannel, data|
exit_status = [exit_status, data.read_long].max
- @not_zerro_nodes << { 'node' => ichannel[:host], "message" => "exit status: #{exit_status}" } if exit_status != 0
+ @not_zerro_nodes << { 'node' => ichannel[:host], "message" => "exit status: #{exit_status}" } if exit_status != 0
end
end
end
session.loop
exit_status
@@ -330,22 +333,28 @@
def extract_nested_value(data_structure, path_spec)
ui.presenter.extract_nested_value(data_structure, path_spec)
end
- def print_failed(arr = [{"node" => "ip", "meesage" => "message"}])
- return if arr.compact.empty?
- arr.each do |status|
- ui.error("#{status['node']} #{status['message']}")
+ def print_all_status
+ succ = @all_nodes.count - @failed_connect_nodes.count - @not_zerro_nodes.count
+ failed = @failed_connect_nodes.count + @not_zerro_nodes.count
+ @failed_connect_nodes.each { |msg| ui.error("#{msg['node']} #{msg['message']}") }
+ @not_zerro_nodes.each { |msg| ui.error("#{msg['node']} #{msg['message']}") }
+ if failed > 0
+ ui.warn "All: #{@all_nodes.count}, successful: #{succ}, connection problem: #{@failed_connect_nodes.count}, failed: #{@not_zerro_nodes.count}"
+ else
+ ui.info "All: #{@all_nodes.count}, successful: #{succ}"
end
end
def run
extend Chef::Mixin::Command
@longest = 0
+ @all_nodes = []
@failed_connect_nodes = []
@not_zerro_nodes = []
configure_attribute
configure_user
@@ -362,11 +371,10 @@
end
session.close
- print_failed(@failed_connect_nodes)
- print_failed(@not_zerro_nodes)
+ print_all_status
if (@not_zerro_nodes + @failed_connect_nodes).compact.empty?
exit_status
else
my_status = exit_status == 0 ? 1 : exit_status