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..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 @@ -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