Permalink
Browse files

Updated spot pricing to understand t1.micro instance type.

  • Loading branch information...
1 parent 14b2ea1 commit 5be297c8062ba122ff4064215f039f01b8f2b783 @grempe committed Nov 21, 2010
@@ -37,6 +37,7 @@ def request_spot_instances( options = {} )
raise ArgumentError, ":addressing_type has been deprecated." if options[:addressing_type]
raise ArgumentError, ":spot_price must be provided" if options[:spot_price].nil? || options[:spot_price].empty?
raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless [true, false].include?(options[:base64_encoded])
+ raise ArgumentError, ":instance_type must specify a valid instance type" unless options[:instance_type].nil? || ["t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge", "cc1.4xlarge"].include?(options[:instance_type])
user_data = extract_user_data(options)
@@ -2,7 +2,7 @@ module AWS
module EC2
class Base < AWS::Base
-
+
# This method returns historical information about spot prices.
#
# Amazon periodically sets the spot price for each instance type based on
@@ -16,15 +16,15 @@ class Base < AWS::Base
def describe_spot_price_history( options = {} )
raise ArgumentError, ":start_time must be a Time object" unless options[:start_time].nil? || options[:start_time].kind_of?(Time)
raise ArgumentError, ":end_time must be a Time object" unless options[:end_time].nil? || options[:end_time].kind_of?(Time)
- raise ArgumentError, ":instance_type must specify a valid instance type" unless options[:instance_type].nil? || ["m1.small", "m1.large", "m1.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge","cc1.4xlarge"].include?(options[:instance_type])
+ raise ArgumentError, ":instance_type must specify a valid instance type" unless options[:instance_type].nil? || ["t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge", "cc1.4xlarge"].include?(options[:instance_type])
raise ArgumentError, ":product_description must be 'Linux/UNIX' or 'Windows'" unless options[:product_description].nil? || ["Linux/UNIX", "Windows"].include?(options[:product_description])
params = {}
params.merge!("StartTime" => options[:start_time].iso8601) if options[:start_time]
params.merge!("EndTime" => options[:end_time].iso8601) if options[:end_time]
params.merge!("InstanceType" => options[:instance_type]) if options[:instance_type]
params.merge!("ProductDescription" => options[:product_description]) if options[:product_description]
-
+
return response_generator(:action => "DescribeSpotPriceHistory", :params => params)
end
@@ -107,6 +107,17 @@
end
+ specify "should be able to be requested with various instance sizes" do
+ ["t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge", "cc1.4xlarge"].each do |type|
+ @ec2.stubs(:make_request).with('RequestSpotInstances', {"SpotPrice"=>"0.50", 'LaunchSpecification.InstanceType' => type, 'LaunchSpecification.ImageId' => 'ami-60a54009', "InstanceCount"=>"1"}).
+ returns stub(:body => @create_spot_instances_request_response_body, :is_a? => true)
+ lambda { @ec2.request_spot_instances( :image_id => "ami-60a54009", :instance_type => type, :spot_price => '0.50' ) }.should.not.raise(AWS::ArgumentError)
+ end
+ end
+
+ specify "should raise an exception with a bad instance type" do
+ lambda { @ec2.request_spot_instances({"SpotPrice"=>"0.50", 'LaunchSpecification.InstanceType' => 'm1.notarealsize', "InstanceCount"=>"1"}) }.should.raise(AWS::ArgumentError)
+ end
specify "should be able to be created" do
@ec2.stubs(:make_request).with('RequestSpotInstances', {"SpotPrice"=>"0.50", 'LaunchSpecification.InstanceType' => 'm1.small', "InstanceCount"=>"1"}).
@@ -39,13 +39,21 @@
specify "should reject an end_time which is not a Time object" do
lambda { @ec2.describe_spot_price_history(:end_time => 42) }.should.raise(AWS::ArgumentError)
end
-
+
+ specify "should be able to be requested with various instance types" do
+ ["t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge", "cc1.4xlarge"].each do |type|
+ @ec2.stubs(:make_request).with('DescribeSpotPriceHistory', {'InstanceType' => type}).
+ returns stub(:body => @describe_spot_price_history_response_body, :is_a? => true)
+ lambda { @ec2.describe_spot_price_history( :instance_type => type ) }.should.not.raise(AWS::ArgumentError)
+ end
+ end
+
specify "should reject an invalid instance type" do
lambda { @ec2.describe_spot_price_history(:instance_type => 'm1.tiny') }.should.raise(AWS::ArgumentError)
end
-
+
specify "should reject an invalid product description" do
lambda { @ec2.describe_spot_price_history(:product_description => 'Solaris') }.should.raise(AWS::ArgumentError)
end
-
+
end

0 comments on commit 5be297c

Please sign in to comment.