Permalink
Browse files

cluster_ssh & cluster_launch: cleaning up SSH usage to handle VPC

  • Loading branch information...
1 parent f89b88e commit 4ced39fe08ede03c5c95d238f32dfa485ffec30d @temujin9 temujin9 committed Jan 14, 2013
Showing with 8 additions and 10 deletions.
  1. +8 −4 lib/chef/knife/cluster_launch.rb
  2. +0 −6 lib/chef/knife/cluster_ssh.rb
@@ -115,7 +115,8 @@ def perform_after_launch_tasks(computer)
# Try SSH
unless config[:dry_run]
Ironfan.step(computer.name, 'trying ssh', :white)
- nil until tcp_test_ssh(computer.machine.dns_name){ sleep @initial_sleep_delay ||= 10 }
+ address = computer.machine.vpc_id.nil? ? computer.machine.public_target : computer.machine.public_ip_address
+ nil until tcp_test_ssh(address){ sleep @initial_sleep_delay ||= 10 }
end
Ironfan.step(computer.name, 'final provisioning', :white)
@@ -128,22 +129,25 @@ def perform_after_launch_tasks(computer)
end
end
- def tcp_test_ssh(hostname)
- tcp_socket = TCPSocket.new(hostname, 22)
+ def tcp_test_ssh(target)
+ tcp_socket = TCPSocket.new(target, 22)
readable = IO.select([tcp_socket], nil, nil, 5)
if readable
- Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
+ Chef::Log.debug("sshd accepting connections on #{target}, banner is #{tcp_socket.gets}")
yield
true
else
false
end
rescue Errno::ETIMEDOUT
+ Chef::Log.debug("ssh to #{target} timed out")
false
rescue Errno::ECONNREFUSED
+ Chef::Log.debug("ssh connection to #{target} refused")
sleep 2
false
rescue Errno::EHOSTUNREACH
+ Chef::Log.debug("ssh host #{target} unreachable")
sleep 2
false
ensure
@@ -47,14 +47,8 @@ def configure_session
config[:attribute] ||= Chef::Config[:knife][:ssh_address_attribute] || "fqdn"
config[:ssh_user] ||= Chef::Config[:knife][:ssh_user]
-# config[:identity_file] ||= target.ssh_identity_file
-# @action_nodes = target.chef_nodes
- #action_nodes needs to be an Array or chef will fail with nil:NilClass Exception
- @action_nodes = []
target = target.select {|t| not t.bogus? }
- #For some reason the ssh_identity_file config above was removed from target.
- config[:identity_file] ||= target.map {|c| c.keypair.key_filename }.compact.first
addresses = target.map {|c| c.machine.vpc_id.nil? ? c.machine.public_hostname : c.machine.public_ip_address }.compact
(ui.fatal("No nodes returned from search!"); exit 10) if addresses.nil? || addresses.length == 0

0 comments on commit 4ced39f

Please sign in to comment.