amazon-pricing 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/Gemfile.lock +27 -2
- data/Rakefile +37 -19
- data/lib/amazon-pricing.rb +206 -4
- data/lib/amazon-pricing/ec2-instance-type.rb +16 -1
- data/lib/amazon-pricing/instance-type.rb +4 -4
- data/lib/amazon-pricing/rds-instance-type.rb +26 -1
- data/lib/amazon-pricing/region.rb +4 -6
- data/lib/amazon-pricing/version.rb +1 -1
- data/test/ec2_instance_types_test.rb +1 -1
- data/test/govcloud_test.rb +43 -0
- metadata +6 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,33 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
amazon-pricing (0.1.
|
4
|
+
amazon-pricing (0.1.29)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.1.3)
|
10
|
-
|
10
|
+
domain_name (0.5.18)
|
11
|
+
unf (>= 0.0.5, < 1.0.0)
|
12
|
+
http-cookie (1.0.2)
|
13
|
+
domain_name (~> 0.5)
|
14
|
+
mechanize (2.7.3)
|
15
|
+
domain_name (~> 0.5, >= 0.5.1)
|
16
|
+
http-cookie (~> 1.0)
|
17
|
+
mime-types (~> 2.0)
|
18
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
19
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
20
|
+
nokogiri (~> 1.4)
|
21
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
22
|
+
webrobots (>= 0.0.9, < 0.2)
|
23
|
+
mime-types (2.2)
|
24
|
+
mini_portile (0.5.3)
|
25
|
+
net-http-digest_auth (1.4)
|
26
|
+
net-http-persistent (2.9.4)
|
27
|
+
nokogiri (1.6.1)
|
28
|
+
mini_portile (~> 0.5.0)
|
29
|
+
ntlm-http (0.1.1)
|
30
|
+
rake (10.2.2)
|
11
31
|
rspec (2.11.0)
|
12
32
|
rspec-core (~> 2.11.0)
|
13
33
|
rspec-expectations (~> 2.11.0)
|
@@ -17,12 +37,17 @@ GEM
|
|
17
37
|
diff-lcs (~> 1.1.3)
|
18
38
|
rspec-mocks (2.11.3)
|
19
39
|
test-unit (2.5.5)
|
40
|
+
unf (0.1.4)
|
41
|
+
unf_ext
|
42
|
+
unf_ext (0.0.6)
|
43
|
+
webrobots (0.1.1)
|
20
44
|
|
21
45
|
PLATFORMS
|
22
46
|
ruby
|
23
47
|
|
24
48
|
DEPENDENCIES
|
25
49
|
amazon-pricing!
|
50
|
+
mechanize (~> 2.7.3)
|
26
51
|
rake
|
27
52
|
rspec (~> 2.11.0)
|
28
53
|
test-unit
|
data/Rakefile
CHANGED
@@ -6,8 +6,8 @@ $: << File.expand_path(File.dirname(__FILE__), 'lib')
|
|
6
6
|
require File.join('amazon-pricing','version')
|
7
7
|
|
8
8
|
Rake::TestTask.new(:test) do |test|
|
9
|
-
test.libs << '
|
10
|
-
test.pattern = 'test
|
9
|
+
test.libs << 'test'
|
10
|
+
test.pattern = 'test/*_test.rb'
|
11
11
|
test.verbose = true
|
12
12
|
end
|
13
13
|
|
@@ -27,14 +27,39 @@ task :install => :gem do
|
|
27
27
|
sh "sudo gem install amazon-pricing-#{AwsPricing::VERSION}.gem --no-rdoc --no-ri"
|
28
28
|
end
|
29
29
|
|
30
|
-
task :test do
|
31
|
-
ruby 'test/ec2_instance_types_test.rb'
|
32
|
-
end
|
33
|
-
|
34
30
|
desc "Prints current EC2 pricing in CSV format"
|
35
31
|
task :print_ec2_price_list do
|
36
32
|
require 'amazon-pricing'
|
37
33
|
pricing = AwsPricing::Ec2PriceList.new
|
34
|
+
print_ec2_table(pricing)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Prints current RDS pricing in CSV format"
|
38
|
+
task :print_rds_price_list do
|
39
|
+
require 'amazon-pricing'
|
40
|
+
pricing = AwsPricing::RdsPriceList.new
|
41
|
+
print_rds_table(pricing)
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Prints current GovCloud EC2 pricing in CSV format"
|
45
|
+
task :print_govcloud_ec2_price_list do
|
46
|
+
require 'amazon-pricing'
|
47
|
+
pricing = AwsPricing::GovCloudEc2PriceList.new
|
48
|
+
print_ec2_table(pricing)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Prints current GovCloud RDS pricing in CSV format"
|
52
|
+
task :print_govcloud_rds_price_list do
|
53
|
+
require 'amazon-pricing'
|
54
|
+
pricing = AwsPricing::GovCloudRdsPriceList.new
|
55
|
+
print_rds_table(pricing)
|
56
|
+
end
|
57
|
+
|
58
|
+
task :default => [:test]
|
59
|
+
|
60
|
+
#########################################
|
61
|
+
|
62
|
+
def print_ec2_table(pricing)
|
38
63
|
line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,OD Linux PPH,OD Windows PPH,OD RHEL PPH,OD SLES PPH,OD MsWinSQL PPH,OD MsWinSQLWeb PPH,"
|
39
64
|
[:year1, :year3].each do |term|
|
40
65
|
[:light, :medium, :heavy].each do |res_type|
|
@@ -62,14 +87,9 @@ task :print_ec2_price_list do
|
|
62
87
|
end
|
63
88
|
end
|
64
89
|
|
65
|
-
|
66
|
-
desc "Prints current RDS pricing in CSV format"
|
67
|
-
task :print_rds_price_list do
|
68
|
-
require 'amazon-pricing'
|
69
|
-
pricing = AwsPricing::RdsPriceList.new
|
70
|
-
|
90
|
+
def print_rds_table(pricing)
|
71
91
|
line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,"
|
72
|
-
|
92
|
+
|
73
93
|
AwsPricing::DatabaseType.get_database_name.each do |db|
|
74
94
|
unless AwsPricing::DatabaseType.get_available_types(db).nil?
|
75
95
|
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
|
@@ -94,10 +114,10 @@ task :print_rds_price_list do
|
|
94
114
|
end
|
95
115
|
end
|
96
116
|
|
97
|
-
|
98
|
-
puts line.chop
|
99
117
|
|
100
|
-
|
118
|
+
puts line.chop
|
119
|
+
|
120
|
+
pricing.regions.each do |region|
|
101
121
|
region.rds_instance_types.each do |t|
|
102
122
|
line = "#{region.name},#{t.name},#{t.api_name},#{t.memory_in_mb},#{t.disk_in_gb},#{t.compute_units},#{t.virtual_cores},#{t.disk_type},"
|
103
123
|
AwsPricing::DatabaseType.get_database_name.each do |db|
|
@@ -132,7 +152,5 @@ task :print_rds_price_list do
|
|
132
152
|
end
|
133
153
|
puts line.chop
|
134
154
|
end
|
135
|
-
|
155
|
+
end
|
136
156
|
end
|
137
|
-
|
138
|
-
task :default => [:test]
|
data/lib/amazon-pricing.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
+
require 'mechanize'
|
3
4
|
|
4
5
|
Dir[File.join(File.dirname(__FILE__), 'amazon-pricing/*.rb')].sort.each { |lib| require lib }
|
5
6
|
|
@@ -18,7 +19,7 @@ module AwsPricing
|
|
18
19
|
# Upon instantiating a PriceList object, all the corresponding pricing
|
19
20
|
# information will be retrieved from Amazon via currently undocumented
|
20
21
|
# json APIs.
|
21
|
-
|
22
|
+
class PriceList
|
22
23
|
attr_accessor :regions
|
23
24
|
|
24
25
|
def get_region(name)
|
@@ -93,6 +94,204 @@ module AwsPricing
|
|
93
94
|
end
|
94
95
|
|
95
96
|
|
97
|
+
class GovCloudEc2PriceList < PriceList
|
98
|
+
GOV_CLOUD_URL = "http://aws.amazon.com/govcloud-us/pricing/ec2/"
|
99
|
+
|
100
|
+
def initialize
|
101
|
+
@_regions = {}
|
102
|
+
@_regions["us-gov-west"] = Region.new("us-gov-west")
|
103
|
+
InstanceType.populate_lookups
|
104
|
+
get_ec2_instance_pricing
|
105
|
+
end
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def get_ec2_instance_pricing
|
110
|
+
|
111
|
+
client = Mechanize.new
|
112
|
+
page = client.get(GOV_CLOUD_URL)
|
113
|
+
tables = page.search("//div[@class='aws-table section']")
|
114
|
+
|
115
|
+
create_ondemand_instances(get_rows(tables[0]))
|
116
|
+
create_ondemand_instances(get_rows(tables[1]))
|
117
|
+
|
118
|
+
for i in 2..7
|
119
|
+
create_reserved_instances(get_rows(tables[i]), :light)
|
120
|
+
end
|
121
|
+
for i in 8..13
|
122
|
+
create_reserved_instances(get_rows(tables[i]), :medium)
|
123
|
+
end
|
124
|
+
for i in 14..19
|
125
|
+
create_reserved_instances(get_rows(tables[i]), :heavy)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
# e.g. [["Prices / Hour", "Amazon Linux", "RHEL", "SLES"], ["m1.small", "$0.053", "$0.083", "$0.083"]]
|
131
|
+
def create_ondemand_instances(rows)
|
132
|
+
header = rows[0]
|
133
|
+
@_regions.values.each do |region|
|
134
|
+
|
135
|
+
rows.slice(1, rows.size).each do |row|
|
136
|
+
api_name = row[0]
|
137
|
+
instance_type = region.get_ec2_instance_type(api_name)
|
138
|
+
if instance_type.nil?
|
139
|
+
api_name, name = Ec2InstanceType.get_name(nil, row[0], false)
|
140
|
+
instance_type = region.add_or_update_ec2_instance_type(api_name, name)
|
141
|
+
end
|
142
|
+
instance_type.update_pricing2(get_os(header[1]), :ondemand, row[1])
|
143
|
+
instance_type.update_pricing2(get_os(header[2]), :ondemand, row[2])
|
144
|
+
instance_type.update_pricing2(get_os(header[3]), :ondemand, row[3])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# e.g. [["RHEL", "1 yr Term Upfront", "1 yr TermHourly", "3 yr TermUpfront", "3 yr Term Hourly"], ["m1.small", "$68.00", "$0.099", "$105.00", "$0.098"]]
|
150
|
+
def create_reserved_instances(rows, res_type)
|
151
|
+
header = rows[0]
|
152
|
+
operating_system = get_os(header[0])
|
153
|
+
@_regions.values.each do |region|
|
154
|
+
|
155
|
+
rows.slice(1, rows.size).each do |row|
|
156
|
+
api_name = row[0]
|
157
|
+
instance_type = region.get_instance_type(api_name)
|
158
|
+
if instance_type.nil?
|
159
|
+
api_name, name = Ec2InstanceType.get_name(nil, row[0], true)
|
160
|
+
instance_type = region.add_or_update_ec2_instance_type(api_name, name)
|
161
|
+
end
|
162
|
+
instance_type.update_pricing2(operating_system, res_type, nil, row[1], row[2], row[3], row[4])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def get_os(val)
|
168
|
+
case val
|
169
|
+
when "Amazon Linux"
|
170
|
+
:linux
|
171
|
+
when "RHEL"
|
172
|
+
:rhel
|
173
|
+
when "SLES"
|
174
|
+
:sles
|
175
|
+
when "Windows"
|
176
|
+
:mswin
|
177
|
+
when "Windows SQL Server Web", "Windows SQL Server Web Edition"
|
178
|
+
:mswinSQL
|
179
|
+
when "Windows SQL Server Standard", "Windows SQL Server Standard Edition"
|
180
|
+
:mswinSQLWeb
|
181
|
+
else
|
182
|
+
raise "Unable to identify operating system '#{val}'"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_rows(html_table)
|
187
|
+
rows = []
|
188
|
+
html_table.search(".//tr").each do |tr|
|
189
|
+
row = []
|
190
|
+
tr.search(".//td").each do |td|
|
191
|
+
row << td.inner_text.strip.sub("\n", " ").sub(" ", " ")
|
192
|
+
end
|
193
|
+
next if row.size == 1
|
194
|
+
rows << row unless row.empty?
|
195
|
+
end
|
196
|
+
rows
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
class GovCloudRdsPriceList < PriceList
|
202
|
+
GOV_CLOUD_URL = "http://aws.amazon.com/govcloud-us/pricing/rds/"
|
203
|
+
|
204
|
+
def initialize
|
205
|
+
@_regions = {}
|
206
|
+
@_regions["us-gov-west"] = Region.new("us-gov-west")
|
207
|
+
InstanceType.populate_lookups
|
208
|
+
get_rds_instance_pricing
|
209
|
+
end
|
210
|
+
|
211
|
+
protected
|
212
|
+
#@@DB_TYPE = [:mysql, :postgresql, :oracle, :sqlserver]
|
213
|
+
#@@RES_TYPES = [:light, :medium, :heavy]
|
214
|
+
|
215
|
+
def get_rds_instance_pricing
|
216
|
+
|
217
|
+
client = Mechanize.new
|
218
|
+
page = client.get(GOV_CLOUD_URL)
|
219
|
+
tables = page.search("//div[@class='aws-table section']")
|
220
|
+
|
221
|
+
create_ondemand_instances(:mysql, :ondemand, false, false, get_rows(tables[0]))
|
222
|
+
create_ondemand_instances(:mysql, :ondemand, true, false, get_rows(tables[1]))
|
223
|
+
# Mysql
|
224
|
+
no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[2]))
|
225
|
+
create_reserved_instances(:mysql, :light, false, false, no_multi_az_rows)
|
226
|
+
create_reserved_instances(:mysql, :light, true, false, multi_az_rows)
|
227
|
+
no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[3]))
|
228
|
+
create_reserved_instances(:mysql, :medium, false, false, no_multi_az_rows)
|
229
|
+
create_reserved_instances(:mysql, :medium, true, false, multi_az_rows)
|
230
|
+
no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[4]))
|
231
|
+
create_reserved_instances(:mysql, :heavy, false, false, no_multi_az_rows)
|
232
|
+
create_reserved_instances(:mysql, :heavy, true, false, multi_az_rows)
|
233
|
+
# Oracle
|
234
|
+
#no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[7]))
|
235
|
+
#create_reserved_instances(:oracle_se1, :ondemand, false, false, no_multi_az_rows)
|
236
|
+
#create_reserved_instances(:oracle_se1, :ondemand, true, false, multi_az_rows)
|
237
|
+
end
|
238
|
+
|
239
|
+
# e.g. [["General Purpose - Previous Generation", "Price Per Hour"], ["m1.small", "$0.090"], ["m1.medium", "$0.185"]]
|
240
|
+
def create_ondemand_instances(db_type, res_type, is_multi_az, is_byol, rows)
|
241
|
+
@_regions.values.each do |region|
|
242
|
+
# Skip header row
|
243
|
+
rows.slice(1, rows.size).each do |row|
|
244
|
+
api_name = row[0]
|
245
|
+
instance_type = region.get_rds_instance_type(api_name)
|
246
|
+
if instance_type.nil?
|
247
|
+
api_name, name = RdsInstanceType.get_name(nil, row[0], false)
|
248
|
+
instance_type = region.add_or_update_rds_instance_type(api_name, name)
|
249
|
+
end
|
250
|
+
instance_type.update_pricing2(db_type, res_type, is_multi_az, is_byol, row[1])
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# e.g. [[" ", "1 yr Term", "3 yr Term"], [" ", "Upfront", "Hourly", "Upfront", "Hourly"], ["m1.small", "$159", "$0.035", "$249", "$0.033"]]
|
256
|
+
def create_reserved_instances(db_type, res_type, is_multi_az, is_byol, rows)
|
257
|
+
@_regions.values.each do |region|
|
258
|
+
rows.each do |row|
|
259
|
+
api_name = row[0]
|
260
|
+
instance_type = region.get_rds_instance_type(api_name)
|
261
|
+
if instance_type.nil?
|
262
|
+
api_name, name = RdsInstanceType.get_name(nil, row[0], true)
|
263
|
+
instance_type = region.add_or_update_rds_instance_type(api_name, name)
|
264
|
+
end
|
265
|
+
instance_type.update_pricing2(db_type, res_type, is_multi_az, is_byol, nil, row[1], row[3], row[2], row[4])
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def get_reserved_rows(rows)
|
271
|
+
# Skip 2 header rows
|
272
|
+
new_rows = rows.slice(2, rows.size)
|
273
|
+
no_multi_az_rows = new_rows.slice(0, new_rows.size / 2)
|
274
|
+
multi_az_rows = new_rows.slice(new_rows.size / 2, new_rows.size / 2)
|
275
|
+
[no_multi_az_rows, multi_az_rows]
|
276
|
+
end
|
277
|
+
|
278
|
+
def get_rows(html_table)
|
279
|
+
rows = []
|
280
|
+
html_table.search(".//tr").each do |tr|
|
281
|
+
row = []
|
282
|
+
tr.search(".//td").each do |td|
|
283
|
+
row << td.inner_text.strip.sub("\n", " ").sub(" ", " ")
|
284
|
+
end
|
285
|
+
# Various <tR> elements contain labels which have only 1 <td> - except heavy multi-az ;)
|
286
|
+
next if row.size == 1 || row[0].include?("Multi-AZ Deployment")
|
287
|
+
rows << row unless row.empty?
|
288
|
+
end
|
289
|
+
rows
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
|
96
295
|
class Ec2PriceList < PriceList
|
97
296
|
|
98
297
|
def initialize
|
@@ -139,7 +338,8 @@ module AwsPricing
|
|
139
338
|
begin
|
140
339
|
api_name, name = Ec2InstanceType.get_name(type["type"], size["size"], type_of_instance != :ondemand)
|
141
340
|
|
142
|
-
region.add_or_update_ec2_instance_type(api_name, name
|
341
|
+
instance_type = region.add_or_update_ec2_instance_type(api_name, name)
|
342
|
+
instance_type.update_pricing(operating_system, type_of_instance, size)
|
143
343
|
rescue UnknownTypeError
|
144
344
|
$stderr.puts "WARNING: encountered #{$!.message}"
|
145
345
|
end
|
@@ -258,7 +458,8 @@ module AwsPricing
|
|
258
458
|
end
|
259
459
|
api_name, name = RdsInstanceType.get_name(type["name"], tier["name"], type_of_rds_instance != :ondemand)
|
260
460
|
|
261
|
-
region.add_or_update_rds_instance_type(api_name, name
|
461
|
+
instance_type = region.add_or_update_rds_instance_type(api_name, name)
|
462
|
+
instance_type.update_pricing(db_type, type_of_rds_instance, tier, is_multi_az, is_byol)
|
262
463
|
rescue UnknownTypeError
|
263
464
|
$stderr.puts "WARNING: encountered #{$!.message}"
|
264
465
|
end
|
@@ -278,7 +479,8 @@ module AwsPricing
|
|
278
479
|
is_multi_az = is_multi_az? type["type"]
|
279
480
|
api_name, name = RdsInstanceType.get_name(type["type"], tier["size"], true)
|
280
481
|
|
281
|
-
region.add_or_update_rds_instance_type(api_name, name
|
482
|
+
instance_type = region.add_or_update_rds_instance_type(api_name, name)
|
483
|
+
instance_type.update_pricing(db_type, type_of_rds_instance, tier, is_multi_az, is_byol)
|
282
484
|
rescue UnknownTypeError
|
283
485
|
$stderr.puts "WARNING: encountered #{$!.message}"
|
284
486
|
end
|
@@ -43,9 +43,24 @@ module AwsPricing
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
def update_pricing2(operating_system, type_of_instance, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil)
|
47
|
+
|
48
|
+
os = get_category_type(operating_system)
|
49
|
+
if os.nil?
|
50
|
+
os = OperatingSystem.new(self, operating_system)
|
51
|
+
@category_types[operating_system] = os
|
52
|
+
end
|
53
|
+
|
54
|
+
os.set_price_per_hour(type_of_instance, nil, coerce_price(ondemand_pph)) unless ondemand_pph.nil?
|
55
|
+
os.set_prepay(type_of_instance, :year1, coerce_price(year1_prepay)) unless year1_prepay.nil?
|
56
|
+
os.set_prepay(type_of_instance, :year3, coerce_price(year3_prepay)) unless year3_prepay.nil?
|
57
|
+
os.set_price_per_hour(type_of_instance, :year1, coerce_price(year1_pph)) unless year1_pph.nil?
|
58
|
+
os.set_price_per_hour(type_of_instance, :year3, coerce_price(year3_pph)) unless year3_pph.nil?
|
59
|
+
end
|
60
|
+
|
46
61
|
# Maintained for backward compatibility reasons
|
47
62
|
def operating_systems
|
48
|
-
category_types
|
63
|
+
@category_types
|
49
64
|
end
|
50
65
|
|
51
66
|
protected
|
@@ -21,7 +21,7 @@ module AwsPricing
|
|
21
21
|
class InstanceType
|
22
22
|
attr_accessor :name, :api_name, :memory_in_mb, :platform, :compute_units, :virtual_cores, :disk_type, :disk_in_gb
|
23
23
|
|
24
|
-
def initialize(region, api_name, name
|
24
|
+
def initialize(region, api_name, name)
|
25
25
|
@category_types = {}
|
26
26
|
|
27
27
|
@region = region
|
@@ -58,7 +58,7 @@ module AwsPricing
|
|
58
58
|
db = @category_types["#{name}_byol"]
|
59
59
|
else
|
60
60
|
db = @category_types[name]
|
61
|
-
end
|
61
|
+
end
|
62
62
|
end
|
63
63
|
|
64
64
|
# type_of_instance = :ondemand, :light, :medium, :heavy
|
@@ -141,8 +141,8 @@ module AwsPricing
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def coerce_price(price)
|
144
|
-
return nil if price.nil? || price == "N/A"
|
145
|
-
price.gsub(",","").to_f
|
144
|
+
return nil if price.nil? || price.upcase == "N/A"
|
145
|
+
price.gsub(",","").gsub("$", "").to_f
|
146
146
|
end
|
147
147
|
|
148
148
|
def self.get_values(json, category_type)
|
@@ -2,7 +2,7 @@ require 'amazon-pricing/instance-type'
|
|
2
2
|
module AwsPricing
|
3
3
|
class RdsInstanceType < InstanceType
|
4
4
|
|
5
|
-
def initialize(region, api_name, name
|
5
|
+
def initialize(region, api_name, name)
|
6
6
|
@category_types = {}
|
7
7
|
|
8
8
|
@region = region
|
@@ -79,6 +79,31 @@ module AwsPricing
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
def update_pricing2(database_type, type_of_instance, is_multi_az, is_byol, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil)
|
83
|
+
db = get_category_type(database_type, is_multi_az, is_byol)
|
84
|
+
if db.nil?
|
85
|
+
db = DatabaseType.new(self, database_type)
|
86
|
+
|
87
|
+
if is_multi_az == true and is_byol == true
|
88
|
+
@category_types["#{database_type}_byol_multiaz"] = db
|
89
|
+
elsif is_multi_az == true and is_byol == false
|
90
|
+
@category_types["#{database_type}_multiaz"] = db
|
91
|
+
elsif is_multi_az == false and is_byol == true
|
92
|
+
@category_types["#{database_type}_byol"] = db
|
93
|
+
else
|
94
|
+
@category_types[database_type] = db
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
db.set_price_per_hour(type_of_instance, nil, coerce_price(ondemand_pph)) unless ondemand_pph.nil?
|
100
|
+
db.set_prepay(type_of_instance, :year1, coerce_price(year1_prepay)) unless year1_prepay.nil?
|
101
|
+
db.set_prepay(type_of_instance, :year3, coerce_price(year3_prepay)) unless year3_prepay.nil?
|
102
|
+
db.set_price_per_hour(type_of_instance, :year1, coerce_price(year1_pph)) unless year1_pph.nil?
|
103
|
+
db.set_price_per_hour(type_of_instance, :year3, coerce_price(year3_pph)) unless year3_pph.nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
|
82
107
|
protected
|
83
108
|
|
84
109
|
# Returns [api_name, name]
|
@@ -46,23 +46,21 @@ module AwsPricing
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# type_of_instance = :ondemand, :light, :medium, :heavy
|
49
|
-
def add_or_update_ec2_instance_type(api_name, name
|
49
|
+
def add_or_update_ec2_instance_type(api_name, name)
|
50
50
|
current = get_ec2_instance_type(api_name)
|
51
51
|
if current.nil?
|
52
|
-
current = Ec2InstanceType.new(self, api_name, name
|
52
|
+
current = Ec2InstanceType.new(self, api_name, name)
|
53
53
|
@ec2_instance_types[api_name] = current
|
54
54
|
end
|
55
|
-
current.update_pricing(operating_system, type_of_instance, json)
|
56
55
|
current
|
57
56
|
end
|
58
57
|
|
59
|
-
def add_or_update_rds_instance_type(api_name, name
|
58
|
+
def add_or_update_rds_instance_type(api_name, name)
|
60
59
|
current = get_rds_instance_type(api_name)
|
61
60
|
if current.nil?
|
62
|
-
current = RdsInstanceType.new(self, api_name, name
|
61
|
+
current = RdsInstanceType.new(self, api_name, name)
|
63
62
|
@rds_instance_types[api_name] = current
|
64
63
|
end
|
65
|
-
current.update_pricing(db_type, type_of_instance, json, is_multi_az, is_byol)
|
66
64
|
current
|
67
65
|
end
|
68
66
|
|
@@ -70,7 +70,7 @@ class TestEc2InstanceTypes < Test::Unit::TestCase
|
|
70
70
|
region = @@ec2_pricing.get_region('us-east')
|
71
71
|
instance = region.get_ec2_instance_type('m1.large')
|
72
72
|
bem = instance.get_breakeven_month(:linux, :heavy, :year1)
|
73
|
-
assert bem ==
|
73
|
+
assert bem == 6
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_memory
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Amazon Web Services Pricing Ruby library
|
5
|
+
#
|
6
|
+
# Ruby Gem Name:: amazon-pricing
|
7
|
+
# Author:: Joe Kinsella (mailto:joe.kinsella@gmail.com)
|
8
|
+
# Copyright:: Copyright (c) 2011-2013 CloudHealth
|
9
|
+
# License:: Distributes under the same terms as Ruby
|
10
|
+
# Home:: http://github.com/CloudHealth/amazon-pricing
|
11
|
+
#++
|
12
|
+
|
13
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
14
|
+
require 'helper'
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
class TestGovCloud < Test::Unit::TestCase
|
18
|
+
class << self
|
19
|
+
def startup
|
20
|
+
#This is expensive, so only do once.
|
21
|
+
@@ec2_pricing = AwsPricing::GovCloudEc2PriceList.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cc8xlarge_issue
|
26
|
+
obj = @@ec2_pricing.get_instance_type('us-gov-west', 'cc2.8xlarge')
|
27
|
+
assert obj.api_name == 'cc2.8xlarge'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_memory
|
31
|
+
# Validate instance types in specific regions are available
|
32
|
+
region = @@ec2_pricing.get_region('us-gov-west')
|
33
|
+
instance = region.get_ec2_instance_type('m1.large')
|
34
|
+
assert instance.memory_in_mb == 7500
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_virtual_cores
|
38
|
+
region = @@ec2_pricing.get_region('us-gov-west')
|
39
|
+
instance = region.get_ec2_instance_type('m1.large')
|
40
|
+
assert instance.virtual_cores == 2
|
41
|
+
end
|
42
|
+
|
43
|
+
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.
|
4
|
+
version: 0.1.29
|
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: 2014-04-
|
12
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby library for retrieving pricing for Amazon Web Services
|
15
15
|
email:
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- spec/spec_helper.rb
|
44
44
|
- spec/support/.gitignore
|
45
45
|
- test/ec2_instance_types_test.rb
|
46
|
+
- test/govcloud_test.rb
|
46
47
|
- test/helper.rb
|
47
48
|
homepage: http://github.com/CloudHealth/amazon-pricing
|
48
49
|
licenses:
|
@@ -64,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
65
|
version: '0'
|
65
66
|
segments:
|
66
67
|
- 0
|
67
|
-
hash:
|
68
|
+
hash: 1325936641347822274
|
68
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
70
|
none: false
|
70
71
|
requirements:
|
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
74
|
version: '0'
|
74
75
|
segments:
|
75
76
|
- 0
|
76
|
-
hash:
|
77
|
+
hash: 1325936641347822274
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project: amazon-pricing
|
79
80
|
rubygems_version: 1.8.25
|
@@ -87,4 +88,5 @@ test_files:
|
|
87
88
|
- spec/spec_helper.rb
|
88
89
|
- spec/support/.gitignore
|
89
90
|
- test/ec2_instance_types_test.rb
|
91
|
+
- test/govcloud_test.rb
|
90
92
|
- test/helper.rb
|