1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Enable AWS spot requests in a VPC by specifying subnet_id

This commit is contained in:
Ben Turley 2012-08-24 01:31:32 -06:00
parent d1fbbe65b4
commit a0acfecaa2
5 changed files with 18 additions and 2 deletions

View file

@ -28,6 +28,7 @@ module Fog
attribute :image_id, :aliases => 'LaunchSpecification.ImageId'
attribute :monitoring, :aliases => 'LaunchSpecification.Monitoring'
attribute :block_device_mapping, :aliases => 'LaunchSpecification.BlockDeviceMapping'
attribute :subnet_id, :aliases => 'LaunchSpecification.SubnetId'
attribute :tags, :aliases => 'tagSet'
attribute :fault, :squash => 'message'
attribute :user_data
@ -109,10 +110,21 @@ module Fog
'LaunchSpecification.Placement.AvailabilityZone' => availability_zone,
'LaunchSpecification.SecurityGroup' => groups,
'LaunchSpecification.UserData' => user_data,
'LaunchSpecification.SubnetId' => subnet_id,
'Type' => request_type,
'ValidFrom' => valid_from,
'ValidUntil' => valid_until }
options.delete_if {|key, value| value.nil?}
# If subnet is defined then this is a Virtual Private Cloud.
# subnet & security group cannot co-exist. Attempting to specify
# both subnet and groups will cause an error. Instead please make
# use of Security Group Ids when working in a VPC.
if subnet_id
options.delete('LaunchSpecification.SecurityGroup')
else
options.delete('LaunchSpecification.SubnetId')
end
data = connection.request_spot_instances(image_id, flavor_id, price, options).body
spot_instance_request = data['spotInstanceRequestSet'].first

View file

@ -48,7 +48,7 @@ module Fog
@response['spotInstanceRequestSet'] << @spot_instance_request
@spot_instance_request = { 'launchSpecification' => { 'blockDeviceMapping' => [], 'groupSet' => [] } }
end
when 'imageId', 'instanceType', 'keyname'
when 'imageId', 'instanceType', 'keyname', 'subnetId'
@spot_instance_request['launchSpecification'][name] = value
when 'enabled'
@spot_instance_request['launchSpecification']['monitoring'] = (value == 'true')

View file

@ -25,6 +25,7 @@ module Fog
# * 'imageId'<~String> - AMI for instance
# * 'instanceType'<~String> - type for instance
# * 'monitoring'<~Boolean> - monitoring status for instance
# * 'subnetId'<~String> - VPC subnet ID for instance
# * 'productDescription'<~String> - general description of AMI
# * 'spotInstanceRequestId'<~String> - id of spot instance request
# * 'spotPrice'<~Float> - maximum price for instances to be launched

View file

@ -24,6 +24,7 @@ module Fog
# * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination
# * 'LaunchSpecification.KeyName'<~String> - Name of a keypair to add to booting instances
# * 'LaunchSpecification.Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to disabled
# * 'LaunchSpecification.SubnetId'<~String> - VPC subnet ID in which to launch the instance
# * 'LaunchSpecification.Placement.AvailabilityZone'<~String> - Placement constraint for instances
# * 'LaunchSpecification.SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances, not supported in VPC
# * 'LaunchSpecification.SecurityGroupId'<~Array> or <~String> - Id of security group(s) for instances, use this or LaunchSpecification.SecurityGroup
@ -47,6 +48,7 @@ module Fog
# * 'imageId'<~String> - AMI for instance
# * 'instanceType'<~String> - type for instance
# * 'monitoring'<~Boolean> - monitoring status for instance
# * 'subnetId'<~String> - VPC subnet ID for instance
# * 'productDescription'<~String> - general description of AMI
# * 'spotInstanceRequestId'<~String> - id of spot instance request
# * 'spotPrice'<~Float> - maximum price for instances to be launched

View file

@ -11,7 +11,8 @@ Shindo.tests('Fog::Compute[:aws] | spot instance requests', ['aws']) do
'keyName' => Fog::Nullable::String,
'imageId' => String,
'instanceType' => String,
'monitoring' => Fog::Boolean
'monitoring' => Fog::Boolean,
'subnetId' => String
},
'productDescription' => String,
'spotInstanceRequestId' => String,