From 090fda0c31b0e556c5b362f13dd186c5334e18d1 Mon Sep 17 00:00:00 2001 From: Ryan Stout Date: Fri, 6 Apr 2012 15:10:11 -0600 Subject: [PATCH 1/2] Be sure to reload when checking for a started spot instance, also add private/public key options into spot_requests, then set those on the server when loaded --- lib/fog/aws/models/compute/spot_request.rb | 20 ++++++++++++++++++++ lib/fog/aws/models/compute/spot_requests.rb | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/fog/aws/models/compute/spot_request.rb b/lib/fog/aws/models/compute/spot_request.rb index 46bf45051..7ed29a765 100644 --- a/lib/fog/aws/models/compute/spot_request.rb +++ b/lib/fog/aws/models/compute/spot_request.rb @@ -31,6 +31,8 @@ module Fog attribute :tags, :aliases => 'tagSet' attribute :fault, :squash => 'message' attribute :user_data + + attr_writer :private_key, :private_key_path, :public_key, :public_key_path attr_writer :username @@ -71,6 +73,24 @@ module Fog def key_pair=(new_keypair) self.key_name = new_keypair && new_keypair.name end + + def private_key_path + @private_key_path ||= Fog.credentials[:private_key_path] + @private_key_path &&= File.expand_path(@private_key_path) + end + + def private_key + @private_key ||= private_key_path && File.read(private_key_path) + end + + def public_key_path + @public_key_path ||= Fog.credentials[:public_key_path] + @public_key_path &&= File.expand_path(@public_key_path) + end + + def public_key + @public_key ||= public_key_path && File.read(public_key_path) + end def ready? state == 'active' diff --git a/lib/fog/aws/models/compute/spot_requests.rb b/lib/fog/aws/models/compute/spot_requests.rb index bd155a0c6..28d16eb61 100644 --- a/lib/fog/aws/models/compute/spot_requests.rb +++ b/lib/fog/aws/models/compute/spot_requests.rb @@ -62,7 +62,7 @@ module Fog spot_request.save spot_request.wait_for { ready? } - Fog.wait_for { server = connection.servers.get(spot_request.instance_id) } + Fog.wait_for { server = connection.servers.get(spot_request.reload.instance_id) } server = connection.servers.get(spot_request.instance_id) if spot_request.tags for key, value in spot_request.tags @@ -74,7 +74,7 @@ module Fog end end server.wait_for { ready? } - server.setup(:key_data => [server.private_key]) + server.setup(:key_data => [spot_request.private_key]) server end From 6630d4fdfacc50ef1dd8a3f74f3e1339b1458023 Mon Sep 17 00:00:00 2001 From: Ryan Stout Date: Fri, 6 Apr 2012 16:13:35 -0600 Subject: [PATCH 2/2] Use spot request's public_key when setting up keypair --- lib/fog/aws/models/compute/spot_requests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/aws/models/compute/spot_requests.rb b/lib/fog/aws/models/compute/spot_requests.rb index 28d16eb61..08f961e5d 100644 --- a/lib/fog/aws/models/compute/spot_requests.rb +++ b/lib/fog/aws/models/compute/spot_requests.rb @@ -43,7 +43,7 @@ module Fog unless spot_request.key_pair = connection.key_pairs.get("fog_#{name}") spot_request.key_pair = connection.key_pairs.create( :name => "fog_#{name}", - :public_key => server.public_key + :public_key => spot_request.public_key ) end end