From 6ee69750f657efbce0d801113d08e54ce8a1ea45 Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 2 Dec 2010 13:37:03 -0800 Subject: [PATCH] [aws|compute] better ssh handling for bootstrap Closes #68 --- lib/fog/aws/models/compute/server.rb | 13 +++++++++++-- lib/fog/core/ssh.rb | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/fog/aws/models/compute/server.rb b/lib/fog/aws/models/compute/server.rb index 8e2b63e55..39d3d8f9e 100644 --- a/lib/fog/aws/models/compute/server.rb +++ b/lib/fog/aws/models/compute/server.rb @@ -152,7 +152,7 @@ module Fog def setup(credentials = {}) requires :identity, :ip_address, :username require 'json' - sleep(10) # takes a bit before EC2 instances will play nice + commands = [ %{mkdir .ssh}, %{passwd -l root}, @@ -161,7 +161,16 @@ module Fog if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end - Fog::SSH.new(ip_address, username, credentials).run(commands) + # allow some retries over the first 120 seconds because aws is weird + Timeout::timeout(120) do + begin + Timeout::timeout(4) do + Fog::SSH.new(ip_address, username, credentials).run(commands) + end + rescue Net::SSH::AuthenticationFailed, Timeout::Error + retry + end + end rescue Errno::ECONNREFUSED => e sleep(1) retry diff --git a/lib/fog/core/ssh.rb b/lib/fog/core/ssh.rb index 94ad1b2b6..0e2486376 100644 --- a/lib/fog/core/ssh.rb +++ b/lib/fog/core/ssh.rb @@ -42,8 +42,7 @@ module Fog require 'net/ssh' @address = address @username = username - @options = options.merge(:paranoid => false) - @options.merge(:verbose => true) + @options = { :paranoid => false }.merge(options) end def run(commands)