lib/aws/rikanjo.rb in aws-rikanjo-0.0.4 vs lib/aws/rikanjo.rb in aws-rikanjo-0.0.5
- old
+ new
@@ -86,17 +86,17 @@
region = "ap-southeast-2"
when "sa-east-1"
region = "sa-east-1"
end
- get_ri_price
+ get_ri_price(region)
end
- def get_ri_price
+ def get_ri_price(region)
ri_util = @ri_util
- region = @region
+ region = region
instance_type = @instance_type
json = nil
reservedjson_data = nil
uri = URI.parse("#{price_url}/#{ri_price_file}")
@@ -166,9 +166,26 @@
om_get_hr_price
ri_get_hr_price_and_upfront
calc_year_cost
discount_per = (100 - ((@ri_info[@ri_util][:yr_price] / @om_info[:yr_price]) * 100)).round(2)
+
+ # If the Reserved Instance does not become cheaper than the On-demand Instance.
+ if @ri_info[@ri_util][:sweet_spot_start_day].nil?
+ puts "\"Price of the Reserved Instance is higher than the price of On-Demand Instances.\""
+ puts "\"region\" : #{@region}"
+ puts "\"instance_type\" : #{@instance_type}"
+ puts "\"ri_util\" : #{@ri_util}"
+ puts "\"discont percent (percent)\" : #{discount_per}"
+ puts "\"ondemand hour price (doller)\" : #{@om_info[:hr_price]}"
+ puts "\"reserved hour price (doller)\" : #{@ri_info[@ri_util][:hr_price]}"
+ puts "\"ondemand year price (doller)\" : #{@om_info[:yr_price]}"
+ puts "\"reserved year price (doller)\" : #{@ri_info[@ri_util][:yr_price]}"
+ puts "\"reserved upfront (doller)\" : #{@ri_info[@ri_util][:upfront]}"
+
+ exit 1
+ end
+
sweet_spot_date = Date.today + @ri_info[@ri_util][:sweet_spot_start_day]
puts "\"region\" : #{@region}"
puts "\"instance_type\" : #{@instance_type}"
puts "\"ri_util\" : #{@ri_util}"