amazon-pricing 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -35,13 +35,13 @@ desc "Prints current EC2 pricing to console"
35
35
  task :print_price_list do
36
36
  require 'lib/amazon-pricing'
37
37
  pricing = AwsPricing::PriceList.new
38
- puts "Region,Instance Type,Linux PPH,Windows PPH,Prepay 1 Year,Prepay 3 Year"
38
+ puts "Region,Instance Type,Prepay 1 Year,Prepay 3 Year,Linux PPH,Windows PPH,RHEL PPH,SLES PPH,MSWinSQL PPH,MsWinSQLWeb PPH,3 Year Linux PPH,3 Year Windows PPH,3 Year RHEL PPH,3 Year SLES PPH,3 Year MSWinSQL PPH,3 Year MsWinSQLWeb PPH"
39
39
  pricing.regions.each do |region|
40
40
  region.ec2_on_demand_instance_types.each do |t|
41
- puts "#{region.name},on-demand,#{t.api_name},#{t.linux_price_per_hour},#{t.windows_price_per_hour},,,,"
41
+ puts "#{region.name},on-demand,#{t.api_name},0,0,#{t.linux_price_per_hour},#{t.windows_price_per_hour},#{t.rhel_price_per_hour},#{t.sles_price_per_hour},#{t.mswinSQL_price_per_hour},#{t.mswinSQLWeb_price_per_hour},N/A,N/A,N/A,N/A,N/A,N/A"
42
42
  end
43
43
  region.ec2_reserved_instance_types.each do |t|
44
- puts "#{region.name},#{t.usage_type},#{t.api_name},#{t.linux_price_per_hour_1_year},#{t.windows_price_per_hour_1_year},#{t.linux_price_per_hour_3_year},#{t.windows_price_per_hour_3_year}#{t.prepay_1_year},#{t.prepay_3_year}"
44
+ puts "#{region.name},#{t.usage_type},#{t.api_name},#{t.prepay_1_year},#{t.prepay_3_year},#{t.linux_price_per_hour},#{t.windows_price_per_hour},#{t.rhel_price_per_hour},#{t.sles_price_per_hour},#{t.mswinSQL_price_per_hour},#{t.mswinSQLWeb_price_per_hour},#{t.linux_price_per_hour_3_year},#{t.windows_price_per_hour_3_year},#{t.rhel_price_per_hour_3_year},#{t.sles_price_per_hour_3_year},#{t.mswinSQL_price_per_hour_3_year},#{t.mswinSQLWeb_price_per_hour_3_year}"
45
45
  end
46
46
  end
47
47
  end
@@ -64,9 +64,26 @@ module AwsPricing
64
64
 
65
65
  protected
66
66
 
67
- # Retrieves the EC2 on-demand instance pricing.
67
+ @@OS_TYPES = [:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb]
68
+ @@RES_TYPES = [:light, :medium, :heavy]
69
+
68
70
  def get_ec2_on_demand_instance_pricing
69
- res = fetch_url(EC2_BASE_URL + "pricing-on-demand-instances.json")
71
+ @@OS_TYPES.each do |os|
72
+ fetch_ec2_on_demand_instance_pricing(EC2_BASE_URL + "json/#{os}-od.json", os)
73
+ end
74
+ end
75
+
76
+ def get_ec2_reserved_instance_pricing
77
+ @@OS_TYPES.each do |os|
78
+ @@RES_TYPES.each do |res_type|
79
+ fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "json/#{os}-ri-#{res_type}.json", res_type, os)
80
+ end
81
+ end
82
+ end
83
+
84
+ # Retrieves the EC2 on-demand instance pricing.
85
+ def fetch_ec2_on_demand_instance_pricing(url, platform)
86
+ res = fetch_url(url)
70
87
  @version_ec2_on_demand_instance = res['vers']
71
88
  res['config']['regions'].each do |reg|
72
89
  region_name = reg['region']
@@ -74,7 +91,7 @@ module AwsPricing
74
91
  reg['instanceTypes'].each do |type|
75
92
  type['sizes'].each do |size|
76
93
  begin
77
- region.add_or_update_instance_type(:on_demand, InstanceType.new(region, type['type'], size))
94
+ region.add_or_update_instance_type(:on_demand, InstanceType.new(region, type['type'], size, platform))
78
95
  rescue UnknownTypeError
79
96
  $stderr.puts "WARNING: encountered #{$!.message}"
80
97
  end
@@ -82,16 +99,6 @@ module AwsPricing
82
99
  end
83
100
  end
84
101
  end
85
-
86
- def get_ec2_reserved_instance_pricing
87
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-light-linux.json", :light, :linux)
88
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-light-mswin.json", :light, :windows)
89
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-medium-linux.json", :medium, :linux)
90
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-medium-mswin.json", :medium, :windows)
91
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-heavy-linux.json", :heavy, :linux)
92
- fetch_ec2_reserved_instance_pricing(EC2_BASE_URL + "ri-heavy-mswin.json", :heavy, :windows)
93
- end
94
-
95
102
  # Retrieves the EC2 on-demand instance pricing.
96
103
  # reserved_usage_type = :light, :medium, :heavy
97
104
  def fetch_ec2_reserved_instance_pricing(url, reserved_usage_type, platform)
@@ -20,19 +20,37 @@ module AwsPricing
20
20
  #
21
21
  class InstanceType
22
22
  attr_accessor :name, :api_name, :linux_price_per_hour, :windows_price_per_hour,
23
- :memory_in_mb, :disk_in_mb, :platform, :compute_units, :virtual_cores
23
+ :memory_in_mb, :disk_in_mb, :platform, :compute_units, :virtual_cores,
24
+ :rhel_price_per_hour, :sles_price_per_hour, :mswinSQL_price_per_hour, :mswinSQLWeb_price_per_hour
24
25
 
25
26
  # Initializes and InstanceType object given a region, the internal
26
27
  # type (e.g. stdODI) and the json for the specific instance. The json is
27
28
  # based on the current undocumented AWS pricing API.
28
- def initialize(region, instance_type, json)
29
+ def initialize(region, instance_type, json, platform)
30
+ # e.g. json = {"size"=>"sm", "valueColumns"=>[{"name"=>"linux", "prices"=>{"USD"=>"0.060"}}]}
31
+
32
+ # e.g. {"linux"=>"0.060"}
29
33
  values = InstanceType::get_values(json)
30
34
 
31
35
  @size = json['size']
32
- @linux_price_per_hour = values['linux'].to_f
33
- @linux_price_per_hour = nil if @linux_price_per_hour == 0
34
- @windows_price_per_hour = values['mswin'].to_f
35
- @windows_price_per_hour = nil if @windows_price_per_hour == 0
36
+
37
+ pph = values[platform.to_s]
38
+ pph = nil if pph == "N/A"
39
+
40
+ if platform == :mswin
41
+ @windows_price_per_hour = pph
42
+ elsif platform == :linux
43
+ @linux_price_per_hour = pph
44
+ elsif platform == :rhel
45
+ @rhel_price_per_hour = pph
46
+ elsif platform == :sles
47
+ @sles_price_per_hour = pph
48
+ elsif platform == :mswinSQL
49
+ @mswinSQL_price_per_hour = pph
50
+ elsif platform == :mswinSQLWeb
51
+ @mswinSQLWeb_price_per_hour = pph
52
+ end
53
+
36
54
  @instance_type = instance_type
37
55
 
38
56
  @api_name = self.class.get_api_name(@instance_type, @size)
@@ -50,7 +68,12 @@ module AwsPricing
50
68
  def available?(platform = nil)
51
69
  return @linux_price_per_hour != nil if platform == :linux
52
70
  return @windows_price_per_hour != nil if platform == :windows
53
- return @linux_price_per_hour != nil || @windows_price_per_hour != nil
71
+ return @rhel_price_per_hour != nil if platform == :rhel
72
+ return @sles_price_per_hour != nil if platform == :sles
73
+ return @mswinSQL_price_per_hour != nil if platform == :mswinSQL
74
+ return @mswinSQLWeb_price_per_hour != nil if platform == :mswinSQLWeb
75
+ return @linux_price_per_hour != nil || @windows_price_per_hour != nil || @rhel_price_per_hour ||
76
+ @sles_price_per_hour != nil || @mswinSQL_price_per_hour != nil || @mswinSQLWeb_price_per_hour
54
77
  end
55
78
 
56
79
  def is_reserved?
@@ -59,8 +82,12 @@ module AwsPricing
59
82
 
60
83
  def update(instance_type)
61
84
  # Due to new AWS json we have to make two passes through to populate an instance
62
- @windows_price_per_hour = instance_type.windows_price_per_hour if @windows_price_per_hour.nil?
63
- @linux_price_per_hour = instance_type.linux_price_per_hour if @linux_price_per_hour.nil?
85
+ @windows_price_per_hour ||= instance_type.windows_price_per_hour
86
+ @linux_price_per_hour ||= instance_type.linux_price_per_hour
87
+ @rhel_price_per_hour ||= instance_type.rhel_price_per_hour
88
+ @sles_price_per_hour ||= instance_type.sles_price_per_hour
89
+ @mswinSQL_price_per_hour ||= instance_type.mswinSQL_price_per_hour
90
+ @mswinSQLWeb_price_per_hour ||= instance_type.mswinSQLWeb_price_per_hour
64
91
  end
65
92
 
66
93
  protected
@@ -15,46 +15,58 @@ module AwsPricing
15
15
  # reserved instances have three usage types: light, medium and heavy.
16
16
  #
17
17
  class ReservedInstanceType < InstanceType
18
- attr_accessor :prepay_1_year, :prepay_3_year, :usage_type, :linux_price_per_hour_3_year, :windows_price_per_hour_3_year
18
+ attr_accessor :prepay_1_year, :prepay_3_year, :usage_type,
19
+ :linux_price_per_hour_3_year, :windows_price_per_hour_3_year, :rhel_price_per_hour_3_year, :sles_price_per_hour_3_year, :mswinSQL_price_per_hour_3_year, :mswinSQLWeb_price_per_hour_3_year
19
20
 
20
21
  # Initializes and InstanceType object given a region, the internal
21
22
  # type (e.g. stdODI) and the json for the specific instance. The json is
22
23
  # based on the current undocumented AWS pricing API.
23
24
  def initialize(region, instance_type, json, usage_type, platform)
24
- super(region, instance_type, json)
25
+ super(region, instance_type, json, platform)
25
26
 
26
27
  # Fixme: calling twice, fix later
27
28
  json['valueColumns'].each do |val|
29
+ price = val['prices']['USD']
30
+ price = nil if price == "N/A"
31
+
28
32
  case val["name"]
29
33
  when "yrTerm1"
30
- @prepay_1_year = val['prices']['USD'].to_f unless val['prices']['USD'].to_f == 0
34
+ @prepay_1_year ||= price
31
35
  when "yrTerm1Hourly"
32
- if platform == :windows
33
- @windows_price_per_hour = val['prices']['USD']
36
+ if platform == :mswin
37
+ @windows_price_per_hour = price
34
38
  elsif platform == :linux
35
- @linux_price_per_hour = val['prices']['USD']
39
+ @linux_price_per_hour = price
40
+ elsif platform == :rhel
41
+ @rhel_price_per_hour = price
42
+ elsif platform == :sles
43
+ @sles_price_per_hour = price
44
+ elsif platform == :mswinSQL
45
+ @mswinSQL_price_per_hour = price
46
+ elsif platform == :mswinSQLWeb
47
+ @mswinSQLWeb_price_per_hour = price
36
48
  end
37
49
  when "yrTerm3"
38
- @prepay_3_year = val['prices']['USD'].to_f unless val['prices']['USD'].to_f == 0
50
+ @prepay_3_year ||= price
39
51
  when "yrTerm3Hourly"
40
- if platform == :windows
41
- @windows_price_per_hour_3_year = val['prices']['USD']
52
+ if platform == :mswin
53
+ @windows_price_per_hour_3_year = price
42
54
  elsif platform == :linux
43
- @linux_price_per_hour_3_year = val['prices']['USD']
55
+ @linux_price_per_hour_3_year = price
56
+ elsif platform == :rhel
57
+ @rhel_price_per_hour_3_year = price
58
+ elsif platform == :sles
59
+ @sles_price_per_hour_3_year = price
60
+ elsif platform == :mswinSQL
61
+ @mswinSQL_price_per_hour_3_year = price
62
+ elsif platform == :mswinSQLWeb
63
+ @mswinSQLWeb_price_per_hour_3_year = price
44
64
  end
45
65
  end
46
66
  end
47
67
  @usage_type = usage_type
48
68
  end
49
69
 
50
- def linux_price_per_hour_1_year
51
- self.linux_price_per_hour
52
- end
53
-
54
- def windows_price_per_hour_1_year
55
- self.windows_price_per_hour
56
- end
57
-
58
70
  def to_s
59
71
  "Reserved Instance Type: #{@region.name} #{@api_name}, 1 Year Prepay=#{@prepay_1_year}, 3 Year Prepay=#{@prepay_3_year}, Linux=$#{@linux_price_per_hour}/hour, Windows=$#{@windows_price_per_hour}/hour"
60
72
  end
@@ -66,8 +78,12 @@ module AwsPricing
66
78
  def update(instance_type)
67
79
  super
68
80
  # Due to new AWS json we have to make two passes through to populate an instance
69
- @linux_price_per_hour_3_year = instance_type.linux_price_per_hour_3_year if @linux_price_per_hour_3_year.nil?
70
- @windows_price_per_hour_3_year = instance_type.windows_price_per_hour_3_year if @windows_price_per_hour_3_year.nil?
81
+ @linux_price_per_hour_3_year ||= instance_type.linux_price_per_hour_3_year
82
+ @windows_price_per_hour_3_year ||= instance_type.windows_price_per_hour_3_year
83
+ @rhel_price_per_hour_3_year ||= instance_type.rhel_price_per_hour_3_year
84
+ @sles_price_per_hour_3_year ||= instance_type.sles_price_per_hour_3_year
85
+ @mswinSQL_price_per_hour_3_year ||= instance_type.mswinSQL_price_per_hour_3_year
86
+ @mswinSQLWeb_price_per_hour_3_year ||= instance_type.mswinSQLWeb_price_per_hour_3_year
71
87
  end
72
88
 
73
89
  protected
@@ -8,5 +8,5 @@
8
8
  # Home:: http://github.com/sonian/amazon-pricing
9
9
  #++
10
10
  module AwsPricing
11
- VERSION = '0.1.5'
11
+ VERSION = '0.1.6'
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon-pricing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby library for retrieving pricing for Amazon Web Services
15
15
  email:
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project: amazon-pricing
64
- rubygems_version: 1.8.24
64
+ rubygems_version: 1.8.25
65
65
  signing_key:
66
66
  specification_version: 3
67
67
  summary: Amazon Web Services Pricing Ruby gem
@@ -70,3 +70,4 @@ test_files:
70
70
  - spec/price_list_spec.rb
71
71
  - test/helper.rb
72
72
  - test/test-ec2-instance-types.rb
73
+ has_rdoc: