lib/aws/rikanjo.rb in aws-rikanjo-0.0.3 vs lib/aws/rikanjo.rb in aws-rikanjo-0.0.4
- old
+ new
@@ -13,10 +13,12 @@
@region = region
@instance_type = instance_type
@ri_util = ri_util
@om_info = Hash.new
@ri_info = Hash.new
+ @current_price_url = 'http://a0.awsstatic.com/pricing/1/ec2'
+ @previous_price_url = 'http://a0.awsstatic.com/pricing/1/ec2/previous-generation'
end
def om_get_hr_price
region = @region
instance_type = @instance_type
@@ -38,11 +40,11 @@
when "sa-east-1"
region = "sa-east-1"
end
# TODO: merge om and ri
- uri = URI.parse('http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js')
+ uri = URI.parse("#{price_url}/linux-od.min.js")
Net::HTTP.start(uri.host, uri.port) do |http|
response = http.get(uri.request_uri)
json = response.body
end
@@ -95,17 +97,17 @@
region = @region
instance_type = @instance_type
json = nil
reservedjson_data = nil
- uri = URI.parse("http://a0.awsstatic.com/pricing/1/ec2/linux-ri-#{ri_util}.min.js")
+ uri = URI.parse("#{price_url}/#{ri_price_file}")
Net::HTTP.start(uri.host, uri.port) do |http|
response = http.get(uri.request_uri)
json = response.body
end
- json = json.gsub("/*\n * This file is intended for use only on aws.amazon.com. We do not guarantee its availability or accuracy.\n *\n * Copyright 2014 Amazon.com, Inc. or its affiliates. All rights reserved.\n */\ncallback({vers:0.01,",'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":')
+ json = json.gsub("/*\n * This file is intended for use only on aws.amazon.com. We do not guarantee its availability or accuracy.\n *\n * Copyright 2014 Amazon.com, Inc. or its affiliates. All rights reserved.\n */\ncallback({",'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":')
reservedjson_data = Yajl::Parser.parse(json)
reservedjson_data["config"]["regions"].each do |r|
next unless r["region"] == region
r["instanceTypes"].each do |type|
@@ -179,9 +181,26 @@
puts "\"reserved upfront (doller)\" : #{@ri_info[@ri_util][:upfront]}"
puts "\"sweet spot day (day)\" : #{@ri_info[@ri_util][:sweet_spot_start_day]}"
puts "\"sweet spot date (date)\" : #{sweet_spot_date}"
puts "\"sweet spot price (doller)\" : #{@ri_info[@ri_util][:sweet_spot_price]}"
end
+
+ def price_url
+ return (previous_generation_type) ? @previous_price_url : @current_price_url
+ end
+
+ def ri_price_file
+ return (previous_generation_type) ? "#{@ri_util}_linux.min.js" : "linux-ri-#{@ri_util}.min.js"
+ end
+
+ def previous_generation_type
+ case @instance_type
+ when /^(c1|m2|cc2\.8xlarge|cr1\.8xlarge|hi1\.4xlarge|cg1\.4xlarge)/ then true
+ when /^m1/ then (@instance_type == "m1.small") ? false : true
+ else false
+ end
+ end
+
end
end
# m = Aws::RiKanjoo.new(region = "ap-northeast-1", instance_type = "m3.large", ri_util = "medium")
# m.total_cost_year