amazon-pricing 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTZlOTJmYmE3NDE5MGZkN2I4Yzg1N2M1MTBmZjhiZmMwNmFjOTBjNQ==
5
+ data.tar.gz: !binary |-
6
+ OThkNzhjOWRjOTQ4YjRhNDU2MmZiNzI4YjBiNzY2NDYwMWFmYTViZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzBkMWI3ZjY0NWNkMmM3ZmJiNTc2NzI0ZTk1MmNmZjg0YmViMDhiNjVjYWZj
10
+ ZTkxMDI3MDA2Y2Q2YjVlMGE4N2QxYjZkYTVmYmFkMGY1ODBkODYwNWRmZjky
11
+ NDA2OTY2NDZlNTkxZGU5YmQ1ODJiNTE5MTM1MDA5ZGFjNzIxYjA=
12
+ data.tar.gz: !binary |-
13
+ NWZkYTk1MDg0NDEwMGZmNzYxNzFkODFlOWJhOWRiYjZhODE2NDA0N2ZlNWY5
14
+ OGU2ZTFlNGNiZTIyYTA4MTliNDg3NTAzZGM5ZmFkYmQ4YWNiODdiNTA0OWE1
15
+ N2Q1ZjI4MTU0NDlkZmQwYTc2ODBlMzA4ZTNkNmRmYjAwNWZmNTQ=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amazon-pricing (0.1.23)
4
+ amazon-pricing (0.1.22)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -52,7 +52,7 @@ module AwsPricing
52
52
  # Returns [api_name, name]
53
53
  def self.get_name(instance_type, api_name, is_reserved = false)
54
54
  # Let's handle new instances more gracefully
55
- unless @@Memory_Lookup.has_key? api_name
55
+ unless @@Name_Lookup.has_key? api_name
56
56
  raise UnknownTypeError, "Unknown instance type #{instance_type} #{api_name}", caller
57
57
  end
58
58
 
@@ -28,12 +28,12 @@ module AwsPricing
28
28
  @name = name
29
29
  @api_name = api_name
30
30
 
31
- @memory_in_mb = @@Memory_Lookup[@api_name]
32
- @disk_in_gb = @@Disk_Lookup[@api_name]
33
- @platform = @@Platform_Lookup[@api_name]
34
- @compute_units = @@Compute_Units_Lookup[@api_name]
35
- @virtual_cores = @@Virtual_Cores_Lookup[@api_name]
36
- @disk_type = @@Disk_Type_Lookup[@api_name]
31
+ @disk_in_gb = InstanceType.get_disk(api_name)
32
+ @platform = InstanceType.get_platform(api_name)
33
+ @disk_type = InstanceType.get_disk_type(api_name)
34
+ @memory_in_mb = InstanceType.get_memory(api_name)
35
+ @compute_units = InstanceType.get_compute_units(api_name)
36
+ @virtual_cores = InstanceType.get_virtual_cores(api_name)
37
37
  end
38
38
 
39
39
  # Keep this in for backwards compatibility within current major version of gem
@@ -91,8 +91,55 @@ module AwsPricing
91
91
  end
92
92
  end
93
93
 
94
+ def self.populate_lookups
95
+ return unless @@Memory_Lookup.empty? && @@Compute_Units_Lookup.empty? && @@Virtual_Cores_Lookup.empty?
96
+
97
+ res = AwsPricing::PriceList.fetch_url("http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/ec2/linux-od.js")
98
+ res['config']['regions'].each do |reg|
99
+ reg['instanceTypes'].each do |type|
100
+ items = type['sizes']
101
+ items = [type] if items.nil?
102
+ items.each do |size|
103
+ begin
104
+ api_name = size["size"]
105
+ @@Memory_Lookup[api_name] = size["memoryGiB"].to_f * 1000
106
+ @@Compute_Units_Lookup[api_name] = size["ECU"].to_i
107
+ @@Virtual_Cores_Lookup[api_name] = size["vCPU"].to_i
108
+ rescue UnknownTypeError
109
+ $stderr.puts "WARNING: encountered #{$!.message}"
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ end
116
+
94
117
  protected
95
118
 
119
+ def self.get_disk(api_name)
120
+ @@Disk_Lookup[api_name]
121
+ end
122
+
123
+ def self.get_platform(api_name)
124
+ @@Platform_Lookup[api_name]
125
+ end
126
+
127
+ def self.get_disk_type(api_name)
128
+ @@Disk_Type_Lookup[api_name]
129
+ end
130
+
131
+ def self.get_memory(api_name)
132
+ @@Memory_Lookup[api_name]
133
+ end
134
+
135
+ def self.get_compute_units(api_name)
136
+ @@Compute_Units_Lookup[api_name]
137
+ end
138
+
139
+ def self.get_virtual_cores(api_name)
140
+ @@Virtual_Cores_Lookup[api_name]
141
+ end
142
+
96
143
  def coerce_price(price)
97
144
  return nil if price.nil? || price == "N/A"
98
145
  price.gsub(",","").to_f
@@ -125,24 +172,6 @@ module AwsPricing
125
172
  'c3.large' => 'High-Compute Large', 'c3.xlarge' => 'High-Compute Extra Large', 'c3.2xlarge' => 'High-Compute Double Extra Large', 'c3.4xlarge' => 'High-Compute Quadruple Extra Large', 'c3.8xlarge' => 'High-Compute Eight Extra Large',
126
173
  'i2.xlarge' => 'High I/O Extra Large', 'i2.2xlarge' => 'High I/O Double Extra Large', 'i2.4xlarge' => 'High I/O Quadruple Extra Large', 'i2.8xlarge' => 'High I/O Eight Extra Large',
127
174
  }
128
- @@Memory_Lookup = {
129
- 'm1.small' => 1700, 'm1.medium' => 3750, 'm1.large' => 7500, 'm1.xlarge' => 15000,
130
- 'm2.xlarge' => 17100, 'm2.2xlarge' => 34200, 'm2.4xlarge' => 68400,
131
- 'm3.medium' => 3750, 'm3.large' => 7500, 'm3.xlarge' => 15000, 'm3.2xlarge' => 30000,
132
- 'c1.medium' => 1700, 'c1.xlarge' => 7000,
133
- 'hi1.4xlarge' => 60500,
134
- 'cg1.4xlarge' => 22000,
135
- 'cc1.4xlarge' => 23000, 'cc2.8xlarge' => 60500,
136
- 't1.micro' => 1700,
137
- 'cr1.8xlarge' => 244000,
138
- 'hs1.8xlarge' => 117000,
139
- 'g2.2xlarge' => 15000,
140
- 'db.m1.small' => 1700, 'db.m1.medium' => 3750, 'db.m1.large' => 7500, 'db.m1.xlarge' => 15000,
141
- 'db.m2.xlarge' => 17100, 'db.m2.2xlarge' => 34000, 'db.m2.4xlarge' => 68000, 'db.cr1.8xlarge' => 244000,
142
- 'db.t1.micro' => 613,
143
- 'c3.large' => 3750, 'c3.xlarge' => 7000, 'c3.2xlarge' => 15000, 'c3.4xlarge' => 30000, 'c3.8xlarge' => 60000,
144
- 'i2.large' => 15000, 'i2.xlarge' => 30500, 'i2.2xlarge' => 61000, 'i2.4xlarge' => 122000, 'i2.8xlarge' => 244000,
145
- }
146
175
  @@Disk_Lookup = {
147
176
  'm1.small' => 160, 'm1.medium' => 410, 'm1.large' =>850, 'm1.xlarge' => 1690,
148
177
  'm2.xlarge' => 420, 'm2.2xlarge' => 850, 'm2.4xlarge' => 1690,
@@ -179,45 +208,6 @@ module AwsPricing
179
208
  'c3.large' => 64, 'c3.xlarge' => 64, 'c3.2xlarge' => 64, 'c3.4xlarge' => 64, 'c3.8xlarge' => 64,
180
209
  'i2.large' => 64, 'i2.xlarge' => 64, 'i2.2xlarge' => 64, 'i2.4xlarge' => 64, 'i2.8xlarge' => 64,
181
210
  }
182
- @@Compute_Units_Lookup = {
183
- 'm1.small' => 1, 'm1.medium' => 2, 'm1.large' => 4, 'm1.xlarge' => 8,
184
- 'm2.xlarge' => 6.5, 'm2.2xlarge' => 13, 'm2.4xlarge' => 26,
185
- 'm3.medium' => 3, 'm3.large' => 6.5, 'm3.xlarge' => 13, 'm3.2xlarge' => 26,
186
- 'c1.medium' => 5, 'c1.xlarge' => 20,
187
- 'hi1.4xlarge' => 35,
188
- 'cg1.4xlarge' => 34,
189
- 'cc1.4xlarge' => 34, 'cc2.8xlarge' => 88,
190
- 't1.micro' => 2,
191
- 'cr1.8xlarge' => 88,
192
- 'hs1.8xlarge' => 35,
193
- 'g2.2xlarge' => 26,
194
- 'unknown' => 0,
195
- 'db.m1.small' => 1, 'db.m1.medium' => 2, 'db.m1.large' => 4, 'db.m1.xlarge' => 8,
196
- 'db.m2.xlarge' => 6.5, 'db.m2.2xlarge' => 13, 'db.m2.4xlarge' => 26, 'db.cr1.8xlarge' => 88,
197
- 'db.t1.micro' => 1,
198
- 'c3.large' => 7, 'c3.xlarge' => 14, 'c3.2xlarge' => 28, 'c3.4xlarge' => 55, 'c3.8xlarge' => 108,
199
- # Since I2 is not released, the cpmpute units are not yet published, so this is estimate
200
- 'i2.large' => 6.5, 'i2.xlarge' => 13, 'i2.2xlarge' => 26, 'i2.4xlarge' => 52, 'i2.8xlarge' => 104,
201
- }
202
- @@Virtual_Cores_Lookup = {
203
- 'm1.small' => 1, 'm1.medium' => 1, 'm1.large' => 2, 'm1.xlarge' => 4,
204
- 'm2.xlarge' => 2, 'm2.2xlarge' => 4, 'm2.4xlarge' => 8,
205
- 'm3.medium' => 1, 'm3.large' => 2, 'm3.xlarge' => 4, 'm3.2xlarge' => 8,
206
- 'c1.medium' => 2, 'c1.xlarge' => 8,
207
- 'hi1.4xlarge' => 16,
208
- 'cg1.4xlarge' => 8,
209
- 'cc1.4xlarge' => 8, 'cc2.8xlarge' => 16,
210
- 't1.micro' => 0,
211
- 'cr1.8xlarge' => 16,
212
- 'hs1.8xlarge' => 16,
213
- 'g2.2xlarge' => 8,
214
- 'unknown' => 0,
215
- 'db.m1.small' => 1, 'db.m1.medium' => 1, 'db.m1.large' => 2, 'db.m1.xlarge' => 4,
216
- 'db.m2.xlarge' => 2, 'db.m2.2xlarge' => 4, 'db.m2.4xlarge' => 8, 'db.cr1.8xlarge' => 16,
217
- 'db.t1.micro' => 0,
218
- 'c3.large' => 2, 'c3.xlarge' => 4, 'c3.2xlarge' => 8, 'c3.4xlarge' => 16, 'c3.8xlarge' => 32,
219
- 'i2.large' => 2, 'i2.xlarge' => 4, 'i2.2xlarge' => 8, 'i2.4xlarge' => 16, 'i2.8xlarge' => 32,
220
- }
221
211
  @@Disk_Type_Lookup = {
222
212
  'm1.small' => :ephemeral, 'm1.medium' => :ephemeral, 'm1.large' => :ephemeral, 'm1.xlarge' => :ephemeral,
223
213
  'm2.xlarge' => :ephemeral, 'm2.2xlarge' => :ephemeral, 'm2.4xlarge' => :ephemeral,
@@ -237,6 +227,14 @@ module AwsPricing
237
227
  'c3.large' => :ssd, 'c3.xlarge' => :ssd, 'c3.2xlarge' => :ssd, 'c3.4xlarge' => :ssd, 'c3.8xlarge' => :ssd,
238
228
  'i2.large' => :ssd, 'i2.xlarge' => :ssd, 'i2.2xlarge' => :ssd, 'i2.4xlarge' => :ssd, 'i2.8xlarge' => :ssd,
239
229
  }
230
+
231
+ # Due to fact AWS pricing API only reports these for EC2, we will fetch from EC2 and keep around for lookup
232
+ # e.g. EC2 = http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/ec2/linux-od.js
233
+ # e.g. RDS = http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/rds/mysql/pricing-standard-deployments.js
234
+ @@Memory_Lookup = {}
235
+ @@Compute_Units_Lookup = {}
236
+ @@Virtual_Cores_Lookup = {}
237
+
240
238
  end
241
239
 
242
240
  end
@@ -12,12 +12,12 @@ module AwsPricing
12
12
  # Let's look up using the standard name but need to remove leading "db." to do so
13
13
  api_name_for_lookup = api_name.sub("db.", "")
14
14
 
15
- @memory_in_mb = @@Memory_Lookup[api_name_for_lookup]
16
- @disk_in_gb = @@Disk_Lookup[api_name_for_lookup]
17
- @platform = @@Platform_Lookup[api_name_for_lookup]
18
- @compute_units = @@Compute_Units_Lookup[api_name_for_lookup]
19
- @virtual_cores = @@Virtual_Cores_Lookup[api_name_for_lookup]
20
- @disk_type = @@Disk_Type_Lookup[api_name_for_lookup]
15
+ @disk_in_gb = InstanceType.get_disk(api_name_for_lookup)
16
+ @platform = InstanceType.get_platform(api_name_for_lookup)
17
+ @disk_type = InstanceType.get_disk_type(api_name_for_lookup)
18
+ @memory_in_mb = InstanceType.get_memory(api_name_for_lookup)
19
+ @compute_units = InstanceType.get_compute_units(api_name_for_lookup)
20
+ @virtual_cores = InstanceType.get_virtual_cores(api_name_for_lookup)
21
21
  end
22
22
 
23
23
 
@@ -109,6 +109,7 @@ module AwsPricing
109
109
 
110
110
  [api_name, name]
111
111
  end
112
+
112
113
  end
113
114
 
114
115
  end
@@ -8,5 +8,5 @@
8
8
  # Home:: http://github.com/CloudHealth/amazon-pricing
9
9
  #++
10
10
  module AwsPricing
11
- VERSION = '0.1.23'
11
+ VERSION = '0.1.24'
12
12
  end
@@ -35,7 +35,7 @@ module AwsPricing
35
35
  region.get_instance_type(api_name)
36
36
  end
37
37
 
38
- def fetch_url(url)
38
+ def self.fetch_url(url)
39
39
  uri = URI.parse(url)
40
40
  page = Net::HTTP.get_response(uri)
41
41
  # Now that AWS switched from json to jsonp, remove first/last lines
@@ -88,6 +88,7 @@ module AwsPricing
88
88
 
89
89
  def initialize
90
90
  @_regions = {}
91
+ InstanceType.populate_lookups
91
92
  get_ec2_on_demand_instance_pricing
92
93
  get_ec2_reserved_instance_pricing
93
94
  fetch_ec2_ebs_pricing
@@ -115,7 +116,7 @@ module AwsPricing
115
116
  # Retrieves the EC2 on-demand instance pricing.
116
117
  # type_of_instance = :ondemand, :light, :medium, :heavy
117
118
  def fetch_ec2_instance_pricing(url, type_of_instance, operating_system)
118
- res = fetch_url(url)
119
+ res = PriceList.fetch_url(url)
119
120
  res['config']['regions'].each do |reg|
120
121
  region_name = reg['region']
121
122
  region = find_or_create_region(region_name)
@@ -139,7 +140,7 @@ module AwsPricing
139
140
  end
140
141
 
141
142
  def fetch_ec2_ebs_pricing
142
- res = fetch_url(EC2_BASE_URL + "pricing-ebs.js")
143
+ res = PriceList.fetch_url(EC2_BASE_URL + "pricing-ebs.js")
143
144
  res["config"]["regions"].each do |ebs_types|
144
145
  region = get_region(ebs_types["region"])
145
146
  region.ebs_price = EbsPrice.new(region, ebs_types)
@@ -152,8 +153,9 @@ module AwsPricing
152
153
 
153
154
  def initialize
154
155
  @_regions = {}
155
- get_rds_on_demand_instance_pricing
156
- get_rds_reserved_instance_pricing
156
+ InstanceType.populate_lookups
157
+ get_rds_on_demand_instance_pricing
158
+ get_rds_reserved_instance_pricing
157
159
  end
158
160
 
159
161
  protected
@@ -231,7 +233,7 @@ module AwsPricing
231
233
  end
232
234
 
233
235
  def fetch_on_demand_rds_instance_pricing(url, type_of_rds_instance, db_type, is_byol)
234
- res = fetch_url(url)
236
+ res = PriceList.fetch_url(url)
235
237
  res['config']['regions'].each do |reg|
236
238
  region_name = reg['region']
237
239
  region = find_or_create_region(region_name)
@@ -257,7 +259,7 @@ module AwsPricing
257
259
  end
258
260
 
259
261
  def fetch_reserved_rds_instance_pricing(url, type_of_rds_instance, db_type, is_byol)
260
- res = fetch_url(url)
262
+ res = PriceList.fetch_url(url)
261
263
  res['config']['regions'].each do |reg|
262
264
  region_name = reg['region']
263
265
  region = find_or_create_region(region_name)
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon-pricing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
5
- prerelease:
4
+ version: 0.1.24
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joe Kinsella
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A Ruby library for retrieving pricing for Amazon Web Services
15
14
  email:
@@ -47,6 +46,7 @@ files:
47
46
  homepage: http://github.com/CloudHealth/amazon-pricing
48
47
  licenses:
49
48
  - MIT
49
+ metadata: {}
50
50
  post_install_message:
51
51
  rdoc_options:
52
52
  - --title
@@ -57,28 +57,20 @@ rdoc_options:
57
57
  require_paths:
58
58
  - lib
59
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
60
  requirements:
62
61
  - - ! '>='
63
62
  - !ruby/object:Gem::Version
64
63
  version: '0'
65
- segments:
66
- - 0
67
- hash: -4471370739960301886
68
64
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
65
  requirements:
71
66
  - - ! '>='
72
67
  - !ruby/object:Gem::Version
73
68
  version: '0'
74
- segments:
75
- - 0
76
- hash: -4471370739960301886
77
69
  requirements: []
78
70
  rubyforge_project: amazon-pricing
79
- rubygems_version: 1.8.25
71
+ rubygems_version: 2.2.2
80
72
  signing_key:
81
- specification_version: 3
73
+ specification_version: 4
82
74
  summary: Amazon Web Services Pricing Ruby gem
83
75
  test_files:
84
76
  - spec/instance_type_spec.rb
@@ -88,3 +80,4 @@ test_files:
88
80
  - spec/support/.gitignore
89
81
  - test/ec2_instance_types_test.rb
90
82
  - test/helper.rb
83
+ has_rdoc: