Skip to content

Commit 2485472

Browse files
committed
Merge branch 'CHEF-1215'
2 parents 9c78f05 + e77c235 commit 2485472

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

‎chef/lib/chef/knife/ssh.rb‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
require 'chef/knife'
2020
require 'chef/data_bag_item'
2121

22+
begin
23+
gem "net-ssh", ">= 2.0.23"
24+
rescue LoadError
25+
end
26+
2227
class Chef
2328
class Knife
2429
class Ssh < Knife
@@ -31,7 +36,8 @@ class Ssh < Knife
3136
:short => "-C NUM",
3237
:long => "--concurrency NUM",
3338
:description => "The number of concurrent connections",
34-
:default => nil
39+
:default => nil,
40+
:proc => lambda { |o| o.to_i }
3541

3642
option :attribute,
3743
:short => "-a ATTR",
@@ -233,9 +239,7 @@ def macterm
233239
def run
234240
@longest = 0
235241

236-
require 'net/ssh/multi'
237-
require 'readline'
238-
require 'highline'
242+
load_late_dependencies
239243

240244
configure_session
241245

@@ -254,6 +258,34 @@ def run
254258

255259
session.close
256260
end
261+
262+
def load_late_dependencies
263+
require 'net/ssh/multi'
264+
require 'readline'
265+
require 'highline'
266+
267+
assert_net_ssh_version_acceptable!
268+
end
269+
270+
# :nodoc:
271+
# TODO: remove this stuff entirely and package knife ssh as a knife plugin. (Dan - 08 Jul 2010)
272+
#
273+
# The correct way to specify version deps is in the gemspec or other packaging.
274+
# However, we don't want to have a gem dep on net-ssh, because it's a hassle
275+
# when you only need the chef-client (e.g., on a managed node). So we have to
276+
# check here that you have a decent version of Net::SSH.
277+
#
278+
# net-ssh of lower versions has a bug that causes 'knife ssh (searchterm) (commandname)"
279+
# to loop infinitely and consume all the CPU of one core.
280+
def assert_net_ssh_version_acceptable!
281+
netssh_version = Net::SSH::Version
282+
# we want version 2.0.23 and higher:
283+
unless (netssh_version::MAJOR == 2) && (netssh_version::TINY >= 23 || netssh_version::MINOR >= 1)
284+
STDERR.puts "ERROR: Please install net-ssh version 2.0.23 or higher, as lower versions cause issues."
285+
exit 1
286+
end
287+
end
288+
257289
end
258290
end
259291
end

0 commit comments

Comments
 (0)