amazon-pricing 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +53 -48
- data/lib/amazon-pricing.rb +32 -21
- data/lib/amazon-pricing/category-type.rb +1 -1
- data/lib/amazon-pricing/database-type.rb +43 -0
- data/lib/amazon-pricing/instance-type.rb +11 -7
- data/lib/amazon-pricing/rds-instance-type.rb +11 -5
- data/lib/amazon-pricing/region.rb +2 -2
- data/lib/amazon-pricing/version.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -67,67 +67,72 @@ desc "Prints current RDS pricing in CSV format"
|
|
67
67
|
task :print_rds_price_list do
|
68
68
|
require 'amazon-pricing'
|
69
69
|
pricing = AwsPricing::RdsPriceList.new
|
70
|
-
|
70
|
+
|
71
71
|
line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,"
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
line += "OD #{db} #{deploy_type} PPH,"
|
72
|
+
|
73
|
+
AwsPricing::DatabaseType.get_database_name.each do |db|
|
74
|
+
unless AwsPricing::DatabaseType.get_available_types(db).nil?
|
75
|
+
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
|
76
|
+
line += "OD "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" PPH,"
|
78
77
|
end
|
79
78
|
else
|
80
|
-
line += "OD
|
81
|
-
end
|
79
|
+
line += "OD "+ AwsPricing::DatabaseType.display_name(db.to_s) +" PPH,"
|
80
|
+
end
|
82
81
|
end
|
83
82
|
|
84
|
-
|
85
83
|
[:year1, :year3].each do |term|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
[:light, :medium, :heavy].each do |res_type|
|
85
|
+
AwsPricing::DatabaseType.get_database_name.each do |db|
|
86
|
+
unless AwsPricing::DatabaseType.get_available_types(db).nil?
|
87
|
+
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
|
88
|
+
line += "#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" Prepay,#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" PPH,"
|
89
|
+
end
|
90
|
+
else
|
91
|
+
line += "#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name(db.to_s) +" Prepay,#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name(db.to_s) +" PPH,"
|
91
92
|
end
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
93
|
+
end
|
94
|
+
end
|
97
95
|
end
|
98
96
|
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
98
|
+
puts line.chop
|
99
|
+
|
100
|
+
pricing.regions.each do |region|
|
101
|
+
region.rds_instance_types.each do |t|
|
102
|
+
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
|
+
AwsPricing::DatabaseType.get_database_name.each do |db|
|
104
|
+
unless AwsPricing::DatabaseType.get_available_types(db).nil?
|
105
|
+
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
|
106
|
+
if deploy_type == :byol_multiaz
|
107
|
+
line += "#{t.price_per_hour(db, :ondemand, nil, true, true)},"
|
108
|
+
else
|
109
|
+
line += "#{t.price_per_hour(db, :ondemand, nil, deploy_type == :multiaz, deploy_type == :byol)},"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
else
|
113
|
+
line += "#{t.price_per_hour(db, :ondemand, nil)},"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
[:year1, :year3].each do |term|
|
117
|
+
[:light, :medium, :heavy].each do |res_type|
|
118
|
+
AwsPricing::DatabaseType.get_database_name.each do |db|
|
119
|
+
unless AwsPricing::DatabaseType.get_available_types(db).nil?
|
120
|
+
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
|
121
|
+
if deploy_type == :byol_multiaz
|
122
|
+
line += "#{t.prepay(db, res_type, term, true, true)},#{t.price_per_hour(db, res_type, term, true, true)},"
|
123
|
+
else
|
124
|
+
line += "#{t.prepay(db, res_type, term, deploy_type == :multiaz, deploy_type == :byol)},#{t.price_per_hour(db, res_type, term, deploy_type == :multiaz, deploy_type == :byol)},"
|
125
|
+
end
|
121
126
|
end
|
122
127
|
else
|
123
|
-
line += "#{t.prepay(db, res_type, term
|
128
|
+
line += "#{t.prepay(db, res_type, term)},#{t.price_per_hour(db, res_type, term)},"
|
124
129
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
puts line.chop
|
134
|
+
end
|
135
|
+
end
|
131
136
|
end
|
132
137
|
|
133
138
|
task :default => [:test]
|
data/lib/amazon-pricing.rb
CHANGED
@@ -137,8 +137,6 @@ module AwsPricing
|
|
137
137
|
|
138
138
|
end
|
139
139
|
|
140
|
-
|
141
|
-
|
142
140
|
class RdsPriceList < PriceList
|
143
141
|
|
144
142
|
def initialize
|
@@ -154,30 +152,39 @@ module AwsPricing
|
|
154
152
|
|
155
153
|
@@OD_DB_DEPLOY_TYPE = {
|
156
154
|
:mysql=> {:mysql=>["standard","multiAZ"]},
|
157
|
-
:oracle=> {:
|
158
|
-
:sqlserver=> {:
|
155
|
+
:oracle=> {:oracle_se1=>["li-standard","li-multiAZ","byol-standard","byol-multiAZ"], :oracle_se=>["byol-standard","byol-multiAZ"], :oracle_ee=>["byol-standard","byol-multiAZ"]},
|
156
|
+
:sqlserver=> {:sqlserver_ex=>["li-ex"], :sqlserver_web=>["li-web"], :sqlserver_se=>["li-se", "byol"], :sqlserver_ee=>["byol"]}
|
159
157
|
}
|
160
158
|
|
161
159
|
|
162
160
|
@@RESERVED_DB_DEPLOY_TYPE = {
|
163
|
-
:oracle=> {:
|
164
|
-
:sqlserver=> {:
|
161
|
+
:oracle=> {:oracle_se1=>["li","byol"], :oracle_se=>["byol"], :oracle_ee=>["byol"]},
|
162
|
+
:sqlserver=> {:sqlserver_ex=>["li-ex"], :sqlserver_web=>["li-web"], :sqlserver_se=>["li-se","byol"], :sqlserver_ee=>["byol"]}
|
165
163
|
}
|
166
164
|
|
167
165
|
|
168
166
|
def is_multi_az?(type)
|
169
167
|
return true if type.match("multiAZ")
|
170
168
|
false
|
169
|
+
end
|
170
|
+
|
171
|
+
def is_byol?(type)
|
172
|
+
return true if type.match("byol")
|
173
|
+
false
|
171
174
|
end
|
172
175
|
|
173
176
|
def get_rds_on_demand_instance_pricing
|
174
177
|
@@DB_TYPE.each do |db|
|
175
178
|
@@OD_DB_DEPLOY_TYPE[db].each {|db_type, db_instances|
|
176
179
|
db_instances.each do |dp_type|
|
180
|
+
#
|
181
|
+
# to find out the byol type
|
182
|
+
is_byol = is_byol? dp_type
|
183
|
+
|
177
184
|
if db == :mysql or db == :oracle
|
178
|
-
fetch_on_demand_rds_instance_pricing(RDS_BASE_URL+"#{db}/pricing-#{dp_type}-deployments.json",:ondemand, db_type)
|
185
|
+
fetch_on_demand_rds_instance_pricing(RDS_BASE_URL+"#{db}/pricing-#{dp_type}-deployments.json",:ondemand, db_type, is_byol)
|
179
186
|
elsif db == :sqlserver
|
180
|
-
fetch_on_demand_rds_instance_pricing(RDS_BASE_URL+"#{db}/sqlserver-#{dp_type}-ondemand.json",:ondemand, db_type)
|
187
|
+
fetch_on_demand_rds_instance_pricing(RDS_BASE_URL+"#{db}/sqlserver-#{dp_type}-ondemand.json",:ondemand, db_type, is_byol)
|
181
188
|
end
|
182
189
|
end
|
183
190
|
}
|
@@ -188,20 +195,26 @@ module AwsPricing
|
|
188
195
|
@@DB_TYPE.each do |db|
|
189
196
|
if db == :mysql
|
190
197
|
@@RES_TYPES.each do |res_type|
|
191
|
-
fetch_reserved_rds_instance_pricing(RDS_BASE_URL+"#{db}/pricing-#{res_type}-utilization-reserved-instances.json", res_type, db)
|
198
|
+
fetch_reserved_rds_instance_pricing(RDS_BASE_URL+"#{db}/pricing-#{res_type}-utilization-reserved-instances.json", res_type, db, false)
|
192
199
|
end
|
193
200
|
else
|
194
201
|
@@RESERVED_DB_DEPLOY_TYPE[db].each {|db_type, db_instance|
|
195
202
|
@@RES_TYPES.each do |res_type|
|
196
|
-
|
197
|
-
|
203
|
+
db_instance.each do |dp_type|
|
204
|
+
is_byol = is_byol? dp_type
|
205
|
+
if db == :oracle
|
206
|
+
fetch_reserved_rds_instance_pricing(RDS_BASE_URL+"#{db}/pricing-#{dp_type}-#{res_type}-utilization-reserved-instances.json", res_type, db_type, is_byol)
|
207
|
+
elsif db == :sqlserver
|
208
|
+
fetch_reserved_rds_instance_pricing(RDS_BASE_URL+"#{db}/sqlserver-#{dp_type}-#{res_type}-ri.json", res_type, db_type, is_byol)
|
209
|
+
end
|
210
|
+
end
|
198
211
|
end
|
199
212
|
}
|
200
213
|
end
|
201
214
|
end
|
202
215
|
end
|
203
216
|
|
204
|
-
def fetch_on_demand_rds_instance_pricing(url, type_of_rds_instance, db_type)
|
217
|
+
def fetch_on_demand_rds_instance_pricing(url, type_of_rds_instance, db_type, is_byol)
|
205
218
|
res = fetch_url(url)
|
206
219
|
res['config']['regions'].each do |reg|
|
207
220
|
region_name = reg['region']
|
@@ -212,22 +225,22 @@ module AwsPricing
|
|
212
225
|
#
|
213
226
|
# this is special case URL, it is oracle - multiAZ type of deployment but it doesn't have mutliAZ attributes in json.
|
214
227
|
if url == "http://aws.amazon.com/rds/pricing/oracle/pricing-li-multiAZ-deployments.json"
|
215
|
-
|
228
|
+
is_multi_az = true
|
216
229
|
else
|
217
|
-
|
230
|
+
is_multi_az = is_multi_az? type["name"]
|
218
231
|
end
|
219
232
|
api_name, name = RdsInstanceType.get_name(type["name"], tier["name"], type_of_rds_instance != :ondemand)
|
220
233
|
|
221
|
-
region.add_or_update_rds_instance_type(api_name, name, db_type, type_of_rds_instance, tier,
|
234
|
+
region.add_or_update_rds_instance_type(api_name, name, db_type, type_of_rds_instance, tier, is_multi_az, is_byol)
|
222
235
|
rescue UnknownTypeError
|
223
236
|
$stderr.puts "WARNING: encountered #{$!.message}"
|
224
237
|
end
|
225
238
|
end
|
226
|
-
end
|
239
|
+
end
|
227
240
|
end
|
228
241
|
end
|
229
242
|
|
230
|
-
def fetch_reserved_rds_instance_pricing(url, type_of_rds_instance, db_type)
|
243
|
+
def fetch_reserved_rds_instance_pricing(url, type_of_rds_instance, db_type, is_byol)
|
231
244
|
res = fetch_url(url)
|
232
245
|
res['config']['regions'].each do |reg|
|
233
246
|
region_name = reg['region']
|
@@ -235,10 +248,10 @@ module AwsPricing
|
|
235
248
|
reg['instanceTypes'].each do |type|
|
236
249
|
type['tiers'].each do |tier|
|
237
250
|
begin
|
238
|
-
|
251
|
+
is_multi_az = is_multi_az? type["type"]
|
239
252
|
api_name, name = RdsInstanceType.get_name(type["type"], tier["size"], true)
|
240
253
|
|
241
|
-
region.add_or_update_rds_instance_type(api_name, name, db_type, type_of_rds_instance, tier,
|
254
|
+
region.add_or_update_rds_instance_type(api_name, name, db_type, type_of_rds_instance, tier, is_multi_az, is_byol)
|
242
255
|
rescue UnknownTypeError
|
243
256
|
$stderr.puts "WARNING: encountered #{$!.message}"
|
244
257
|
end
|
@@ -247,6 +260,4 @@ module AwsPricing
|
|
247
260
|
end
|
248
261
|
end
|
249
262
|
end
|
250
|
-
|
251
|
-
|
252
263
|
end
|
@@ -16,7 +16,7 @@ module AwsPricing
|
|
16
16
|
:light_prepay_1_year, :light_prepay_3_year, :medium_prepay_1_year, :medium_prepay_3_year, :heavy_prepay_1_year, :heavy_prepay_3_year
|
17
17
|
|
18
18
|
|
19
|
-
def initialize(instance_type, name)
|
19
|
+
def initialize(instance_type=nil, name=nil)
|
20
20
|
@instance_type = instance_type
|
21
21
|
@name = name
|
22
22
|
end
|
@@ -9,5 +9,48 @@
|
|
9
9
|
#++
|
10
10
|
module AwsPricing
|
11
11
|
class DatabaseType < CategoryType
|
12
|
+
|
13
|
+
@@Database_Name_Lookup = {
|
14
|
+
'mysql_standard'=> 'MySQL Community Edition',
|
15
|
+
'mysql_multiaz'=> 'MySQL Community Edition (Multi-AZ)',
|
16
|
+
'oracle_se1_standard'=> 'Oracle Database Standard Edition One',
|
17
|
+
'oracle_se1_multiaz'=> 'Oracle Database Standard Edition One (Multi-AZ)',
|
18
|
+
'oracle_se1_byol'=> 'Oracle Database Standard Edition One (BYOL)',
|
19
|
+
'oracle_se1_byol_multiaz'=> 'Oracle Database Standard Edition One (BYOL Multi-AZ)',
|
20
|
+
'oracle_se_byol'=> 'Oracle Database Standard Edition (BYOL)',
|
21
|
+
'oracle_se_byol_multiaz'=> 'Oracle Database Standard Edition (BYOL Multi-AZ)',
|
22
|
+
'oracle_ee_byol'=> 'Oracle Database Enterprise Edition (BYOL)',
|
23
|
+
'oracle_ee_byol_multiaz'=> 'Oracle Database Enterprise Edition (BYOL Multi-AZ)',
|
24
|
+
'sqlserver_ex'=> 'Microsoft SQL Server Express Edition',
|
25
|
+
'sqlserver_web'=> 'Microsoft SQL Server Web Edition',
|
26
|
+
'sqlserver_se_standard'=> 'Microsoft SQL Server Standard Edition',
|
27
|
+
'sqlserver_se_byol'=> 'Microsoft SQL Server Standard Edition (BYOL)',
|
28
|
+
'sqlserver_ee_byol'=> 'Microsoft SQL Server Enterprise Edition (BYOL)'
|
29
|
+
}
|
30
|
+
|
31
|
+
@@DB_Deploy_Types = {
|
32
|
+
:mysql=>[:standard, :multiaz],
|
33
|
+
:oracle_se1=>[:standard, :multiaz, :byol, :byol_multiaz],
|
34
|
+
:oracle_se=>[:byol, :byol_multiaz],
|
35
|
+
:oracle_ee=>[:byol, :byol_multiaz],
|
36
|
+
:sqlserver_se=>[:standard, :byol],
|
37
|
+
:sqlserver_ee=>[:byol]
|
38
|
+
}
|
39
|
+
|
40
|
+
def self.display_name(name)
|
41
|
+
@@Database_Name_Lookup[name]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_database_name
|
45
|
+
[:mysql, :oracle_se1, :oracle_se, :oracle_ee, :sqlserver_ex, :sqlserver_web, :sqlserver_se, :sqlserver_ee]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get_available_types(db)
|
49
|
+
@@DB_Deploy_Types[db]
|
50
|
+
end
|
51
|
+
|
52
|
+
def display_name
|
53
|
+
self.class.display_name(name)
|
54
|
+
end
|
12
55
|
end
|
13
56
|
end
|
@@ -49,9 +49,13 @@ module AwsPricing
|
|
49
49
|
@category_types.values
|
50
50
|
end
|
51
51
|
|
52
|
-
def get_category_type(name,
|
53
|
-
if
|
54
|
-
db = @category_types["#{name}
|
52
|
+
def get_category_type(name, multi_az = false, byol = false)
|
53
|
+
if multi_az == true and byol == true
|
54
|
+
db = @category_types["#{name}_byol_multiaz"]
|
55
|
+
elsif multi_az == true and byol == false
|
56
|
+
db = @category_types["#{name}_multiaz"]
|
57
|
+
elsif multi_az == false and byol == true
|
58
|
+
db = @category_types["#{name}_byol"]
|
55
59
|
else
|
56
60
|
db = @category_types[name]
|
57
61
|
end
|
@@ -59,15 +63,15 @@ module AwsPricing
|
|
59
63
|
|
60
64
|
# type_of_instance = :ondemand, :light, :medium, :heavy
|
61
65
|
# term = :year_1, :year_3, nil
|
62
|
-
def price_per_hour(category_type, type_of_instance, term = nil,
|
63
|
-
cat = get_category_type(category_type,
|
66
|
+
def price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
|
67
|
+
cat = get_category_type(category_type, is_multi_az, isByol)
|
64
68
|
cat.price_per_hour(type_of_instance, term) unless cat.nil?
|
65
69
|
end
|
66
70
|
|
67
71
|
# type_of_instance = :ondemand, :light, :medium, :heavy
|
68
72
|
# term = :year_1, :year_3, nil
|
69
|
-
def prepay(category_type, type_of_instance, term = nil,
|
70
|
-
cat = get_category_type(category_type,
|
73
|
+
def prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
|
74
|
+
cat = get_category_type(category_type, is_multi_az, isByol)
|
71
75
|
cat.prepay(type_of_instance, term) unless cat.nil?
|
72
76
|
end
|
73
77
|
|
@@ -3,15 +3,21 @@ module AwsPricing
|
|
3
3
|
class RdsInstanceType < InstanceType
|
4
4
|
# database_type = :mysql, :oracle, :sqlserver
|
5
5
|
# type_of_instance = :ondemand, :light, :medium, :heavy
|
6
|
-
def update_pricing(database_type, type_of_instance, json,
|
7
|
-
db = get_category_type(database_type,
|
6
|
+
def update_pricing(database_type, type_of_instance, json, is_multi_az, is_byol)
|
7
|
+
db = get_category_type(database_type, is_multi_az, is_byol)
|
8
8
|
if db.nil?
|
9
9
|
db = DatabaseType.new(self, database_type)
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
if is_multi_az == true and is_byol == true
|
12
|
+
@category_types["#{database_type}_byol_multiaz"] = db
|
13
|
+
elsif is_multi_az == true and is_byol == false
|
14
|
+
@category_types["#{database_type}_multiaz"] = db
|
15
|
+
elsif is_multi_az == false and is_byol == true
|
16
|
+
@category_types["#{database_type}_byol"] = db
|
12
17
|
else
|
13
18
|
@category_types[database_type] = db
|
14
|
-
end
|
19
|
+
end
|
20
|
+
|
15
21
|
end
|
16
22
|
|
17
23
|
if type_of_instance == :ondemand
|
@@ -56,13 +56,13 @@ module AwsPricing
|
|
56
56
|
current
|
57
57
|
end
|
58
58
|
|
59
|
-
def add_or_update_rds_instance_type(api_name, name, db_type, type_of_instance, json,
|
59
|
+
def add_or_update_rds_instance_type(api_name, name, db_type, type_of_instance, json, is_multi_az, is_byol)
|
60
60
|
current = get_rds_instance_type(api_name)
|
61
61
|
if current.nil?
|
62
62
|
current = RdsInstanceType.new(self, api_name, name)
|
63
63
|
@rds_instance_types[api_name] = current
|
64
64
|
end
|
65
|
-
current.update_pricing(db_type, type_of_instance, json,
|
65
|
+
current.update_pricing(db_type, type_of_instance, json, is_multi_az, is_byol)
|
66
66
|
current
|
67
67
|
end
|
68
68
|
|
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.13
|
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-11-
|
12
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby library for retrieving pricing for Amazon Web Services
|
15
15
|
email:
|