This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Rakefile
237 lines (212 loc) · 8.79 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
require 'bundler'
require 'rake/testtask'
$: << File.expand_path(File.dirname(__FILE__), 'lib')
require File.join('amazon-pricing','version')
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.pattern = 'test/*_test.rb'
test.verbose = true
end
desc "Build the gem"
task :gem do
sh 'gem build *.gemspec'
end
desc "Publish the gem"
task :publish do
sh "gem push amazon-pricing-#{AwsPricing::VERSION}.gem"
end
desc "Installs the gem"
task :install => :gem do
sh "sudo gem install amazon-pricing-#{AwsPricing::VERSION}.gem --no-rdoc --no-ri"
end
desc "Prints current EC2 pricing in CSV format"
task :print_ec2_price_list do
require 'amazon-pricing'
pricing = AwsPricing::Ec2PriceList.new
print_ec2_table(pricing)
end
desc "Prints current EC2 DI pricing in CSV format"
task :print_ec2_di_price_list do
require 'amazon-pricing'
pricing = AwsPricing::Ec2DiPriceList.new
print_ec2_table(pricing)
end
desc "Prints current EC2 Dedicated Host pricing in CSV format"
task :print_ec2_dh_price_list do
require 'amazon-pricing'
pricing = AwsPricing::Ec2DedicatedHostPriceList.new
print_ec2_dh_table(pricing)
end
desc "Prints current RDS pricing in CSV format"
task :print_rds_price_list do
require 'amazon-pricing'
pricing = AwsPricing::RdsPriceList.new
print_rds_table(pricing)
end
desc "Prints current ElastiCache pricing to CSV format"
task :print_elasticache_price_list do
require 'amazon-pricing'
pricing = AwsPricing::ElastiCachePriceList.new
print_elasticache_table(pricing)
end
desc "Prints current GovCloud EC2 pricing in CSV format"
task :print_govcloud_ec2_price_list do
require 'amazon-pricing'
pricing = AwsPricing::Ec2PriceList.new
print_ec2_table(pricing, "us-gov-west-1")
end
desc "Prints current GovCloud RDS pricing in CSV format"
task :print_govcloud_rds_price_list do
require 'amazon-pricing'
pricing = AwsPricing::Ec2PriceList.new
print_rds_table(pricing, "us-gov-west-1")
end
task :default => [:test]
#########################################
def print_ec2_table(pricing, target_region = nil)
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,"
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{term} #{res_type} #{os} Prepay,#{term} #{res_type} #{os} PPH,"
end
end
end
puts line.chop
pricing.regions.each do |region|
next if region.name != target_region if target_region
region.ec2_instance_types.each do |t|
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},"
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{t.price_per_hour(os, :ondemand)},"
end
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{t.prepay(os, res_type, term)},#{t.price_per_hour(os, res_type, term)},"
end
end
end
puts line.chop
end
end
end
def print_ec2_dh_table(pricing, target_region = nil)
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,"
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{term} #{res_type} #{os} Prepay,#{term} #{res_type} #{os} PPH,"
end
end
end
puts line.chop
pricing.regions.each do |region|
next if region.name != target_region if target_region
region.ec2_dh_types.each do |t|
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},"
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{t.price_per_hour(os, :ondemand)},"
end
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
[:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
line += "#{t.prepay(os, res_type, term)},#{t.price_per_hour(os, res_type, term)},"
end
end
end
puts line.chop
end
end
end
def print_elasticache_table(pricing, target_region = nil)
line = "Region,Node Type,API Name,Memmory (MB),Virtual Cores,Disk Type,OD PPH,"
[:year1, :year3].each do |term|
[:partialupfront].each do |res_type|
[:memcached].each do |cache|
line += "#{term} #{res_type} #{cache} Prepay,#{term} #{res_type} #{cache} PPH,"
end
end
end
puts line.chop
pricing.regions.each do |region|
next if region.name != target_orgion if target_region
region.elasticache_node_types.each do |t|
line = "#{region.name},#{t.name},#{t.api_name},#{t.memory_in_mb},#{t.virtual_cores},"
[:memcached].each do |cache|
line += "#{t.price_per_hour(cache, :ondemand)},"
end
[:year1, :year3].each do |term|
[:partialupfront].each do |res_type|
[:memcached].each do |cache|
line += "#{t.prepay(cache, res_type, term)},#{t.price_per_hour(cache, res_type, term)},"
end
end
end
puts line.chop
end
end
end
def print_rds_table(pricing, target_region = nil)
line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,"
AwsPricing::DatabaseType.get_database_name.each do |db|
unless AwsPricing::DatabaseType.get_available_types(db).nil?
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
line += "OD "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" PPH,"
end
else
line += "OD "+ AwsPricing::DatabaseType.display_name(db.to_s) +" PPH,"
end
end
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
AwsPricing::DatabaseType.get_database_name.each do |db|
unless AwsPricing::DatabaseType.get_available_types(db).nil?
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
line += "#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" Prepay,#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name("#{db}_#{deploy_type}") +" PPH,"
end
else
line += "#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name(db.to_s) +" Prepay,#{term} #{res_type} "+ AwsPricing::DatabaseType.display_name(db.to_s) +" PPH,"
end
end
end
end
puts line.chop
pricing.regions.each do |region|
next if region.name != target_region if target_region
region.rds_instance_types.each do |t|
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},"
AwsPricing::DatabaseType.get_database_name.each do |db|
unless AwsPricing::DatabaseType.get_available_types(db).nil?
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
if deploy_type == :byol_multiaz
line += "#{t.price_per_hour(db, :ondemand, nil, true, true)},"
else
line += "#{t.price_per_hour(db, :ondemand, nil, deploy_type == :multiaz, deploy_type == :byol)},"
end
end
else
line += "#{t.price_per_hour(db, :ondemand, nil)},"
end
end
[:year1, :year3].each do |term|
[:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
AwsPricing::DatabaseType.get_database_name.each do |db|
unless AwsPricing::DatabaseType.get_available_types(db).nil?
AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
if deploy_type == :byol_multiaz
line += "#{t.prepay(db, res_type, term, true, true)},#{t.price_per_hour(db, res_type, term, true, true)},"
else
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)},"
end
end
else
line += "#{t.prepay(db, res_type, term)},#{t.price_per_hour(db, res_type, term)},"
end
end
end
end
puts line.chop
end
end
end