Skip to content

Commit

Permalink
doing some suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dudemcbacon committed Apr 15, 2015
1 parent 3909c8e commit e373efe
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/hammer_cli_foreman/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Command < HammerCLIForeman::Command

command_name 'SSH to hosts'
option %w(-c --command), 'COMMAND', _('Command to execute'), :attribute_name => :command, :required => true
option %w(-n --concurrent), 'CONCURRENCY', _('Number of concurrent SSH sessions'), :attribute_name => :concurrent
option %w(-n --concurrent), 'CONCURRENCY', _('Number of concurrent SSH sessions'), :attribute_name => :concurrent do |o|
Integer(o)
end
option %w(-u --user), 'USER', _('Execute as user'), :attribute_name => :user, :default => ENV['USER']
option %w(-s --search), 'FILTER', _('Filter hosts based on a filter'), :attribute_name => :search
option '--[no-]dns', :flag, _('Use DNS to resolve IP addresses'), :attribute_name => :use_dns
Expand All @@ -29,10 +31,7 @@ def request_params
end

def execute
if concurrent && concurrent.to_i == 0
warn _("specify 1 or more concurrent hosts")
return HammerCLI::EX_OK
end
signal_usage_error(_("specify 1 or more concurrent hosts")) if (!concurrent.nil? && concurrent < 1)

limit = concurrent.nil? ? concurrent : concurrent.to_i

Expand All @@ -48,7 +47,7 @@ def execute
ssh_options[:keys] = [identity_file] unless identity_file.to_s.empty?

Net::SSH::Multi.start(:concurrent_connections => limit, :on_error => :warn) do |session|
puts _("executing on #{limit} concurrent host(s)") if limit.to_i > 0
logger.info(_("executing on #{limit} concurrent host(s)")) if limit.to_i > 0
targets.each { |s| session.use s, ssh_options }
session.exec command
session.loop
Expand Down

0 comments on commit e373efe

Please sign in to comment.