Skip to content

Commit

Permalink
Merge pull request #1115 from turley/master
Browse files Browse the repository at this point in the history
Enable AWS spot requests in a VPC by specifying subnet_id
  • Loading branch information
geemus committed Aug 27, 2012
2 parents d1fbbe6 + a0acfec commit 646f754
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/fog/aws/models/compute/spot_request.rb
Expand Up @@ -28,6 +28,7 @@ class SpotRequest < Fog::Model
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
Expand Down Expand Up @@ -109,10 +110,21 @@ def save
'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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/compute/spot_instance_requests.rb
Expand Up @@ -48,7 +48,7 @@ def end_element(name)
@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')
Expand Down
Expand Up @@ -25,6 +25,7 @@ class Real
# * '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
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/aws/requests/compute/request_spot_instances.rb
Expand Up @@ -24,6 +24,7 @@ class Real
# * '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
Expand All @@ -47,6 +48,7 @@ class Real
# * '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
Expand Down
3 changes: 2 additions & 1 deletion tests/aws/requests/compute/spot_instance_tests.rb
Expand Up @@ -11,7 +11,8 @@
'keyName' => Fog::Nullable::String,
'imageId' => String,
'instanceType' => String,
'monitoring' => Fog::Boolean
'monitoring' => Fog::Boolean,
'subnetId' => String
},
'productDescription' => String,
'spotInstanceRequestId' => String,
Expand Down

0 comments on commit 646f754

Please sign in to comment.