amazon-pricing 0.1.53 → 0.1.54

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTE5NzY3ZTgxMWJiMzJlN2E5ZjEyN2U0YjZmYTQxODE5OGU0ZjY4Mw==
4
+ YTEzNzRlNDEyOWU3M2IyYmE0Y2IzMTc2ZTMwMjExYjA3OWQyOGJmZQ==
5
5
  data.tar.gz: !binary |-
6
- NDkxOTg3NzlkMGVlNmEwNTRiNjUzZTVlYTlhYTUxMGE3NjYwMmZmYw==
6
+ YThhNmQ4MjM0ZjE3ZGY5MjQ1MzBhYzA5ZGE5ZDRiM2IyMDAyNzIxYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWRlOWM5NDk2NzFjMzUxYzRjNWM3OTIwMTNkMzJmNWQ0OTQ2NzYxY2E3MWQ4
10
- MDI2N2FjOWEwZmUzOTU4YjM4NGU4MzAyZjhkOTY3YzBhZjU1Zjc5NjM0NTMz
11
- ZWUwZTU2MjIzZTFiNzFmMDgyYjg0MTg4MjQ4OTNmNGNlOGE2Mjk=
9
+ YmE3MmQ1NzMxZTlmZjNkZmJjMTE1Y2YwZmI3MTk2NDBmNjIyZjNmMzllMmNm
10
+ MjM2Mjg4ODhiOTkyMDVmMGRkNTc1OTc0YWU4MzMxYjk5OTg5YzEwN2RhMmM4
11
+ ZmQwMjQyODA0YTVhNzc2Y2Y3ZGM1M2UyZDBiNDBiNWRkMWY1YTg=
12
12
  data.tar.gz: !binary |-
13
- YWQyYWI5MjcyYmVhOGIxYjE2NDIyMzFhNWFiMTYwZGUzMjllNDVhNDdjYWNk
14
- NDQ4OGRhNzJkYTk2ZWQyOTgzMDQyZWJiN2FmNWNjNjQ3YjNiMTVhYTU4YjQz
15
- NDQ5ODJkM2NlNjU5ZmY2ZGMyOGZjNzEyM2MwZWQyYzgzMjBhYTg=
13
+ Y2NlNmE4ZDIyODRhNDZkNTAzYmRkZTRkMTYyNzBhNGI1ZDk1ZmVhNjA3MjUw
14
+ YTFhZGZmNDFkZmUxZDJiYTBkYmQ3ZmMyM2M0YzUxNjVjZmRhNDM5OTIzZmRj
15
+ MDk0YzNmYjU5YTZlMjVmMzAwZDM2MjEzZDI5ZTI4YTEzMjM4NjM=
@@ -1,13 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amazon-pricing (0.1.22)
4
+ amazon-pricing (0.1.54)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.1.3)
10
- rake (10.1.0)
10
+ domain_name (0.5.23)
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.4.3)
24
+ mini_portile (0.6.1)
25
+ net-http-digest_auth (1.4)
26
+ net-http-persistent (2.9.4)
27
+ nokogiri (1.6.5)
28
+ mini_portile (~> 0.6.0)
29
+ ntlm-http (0.1.1)
30
+ power_assert (0.2.2)
31
+ rake (10.4.2)
11
32
  rspec (2.11.0)
12
33
  rspec-core (~> 2.11.0)
13
34
  rspec-expectations (~> 2.11.0)
@@ -16,13 +37,19 @@ GEM
16
37
  rspec-expectations (2.11.3)
17
38
  diff-lcs (~> 1.1.3)
18
39
  rspec-mocks (2.11.3)
19
- test-unit (2.5.5)
40
+ test-unit (3.0.8)
41
+ power_assert
42
+ unf (0.1.4)
43
+ unf_ext
44
+ unf_ext (0.0.6)
45
+ webrobots (0.1.1)
20
46
 
21
47
  PLATFORMS
22
48
  ruby
23
49
 
24
50
  DEPENDENCIES
25
51
  amazon-pricing!
52
+ mechanize (~> 2.7.3)
26
53
  rake
27
54
  rspec (~> 2.11.0)
28
55
  test-unit
data/Rakefile CHANGED
@@ -44,22 +44,22 @@ end
44
44
  desc "Prints current GovCloud EC2 pricing in CSV format"
45
45
  task :print_govcloud_ec2_price_list do
46
46
  require 'amazon-pricing'
47
- pricing = AwsPricing::GovCloudEc2PriceList.new
48
- print_ec2_table(pricing)
47
+ pricing = AwsPricing::Ec2PriceList.new
48
+ print_ec2_table(pricing, "us-gov-west-1")
49
49
  end
50
50
 
51
51
  desc "Prints current GovCloud RDS pricing in CSV format"
52
52
  task :print_govcloud_rds_price_list do
53
53
  require 'amazon-pricing'
54
- pricing = AwsPricing::GovCloudRdsPriceList.new
55
- print_rds_table(pricing)
54
+ pricing = AwsPricing::Ec2PriceList.new
55
+ print_rds_table(pricing, "us-gov-west-1")
56
56
  end
57
57
 
58
58
  task :default => [:test]
59
59
 
60
60
  #########################################
61
61
 
62
- def print_ec2_table(pricing)
62
+ def print_ec2_table(pricing, target_region = nil)
63
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,"
64
64
  [:year1, :year3].each do |term|
65
65
  [:light, :medium, :heavy, :allupfront, :partialupfront, :noupfront].each do |res_type|
@@ -70,6 +70,7 @@ def print_ec2_table(pricing)
70
70
  end
71
71
  puts line.chop
72
72
  pricing.regions.each do |region|
73
+ next if region.name != target_region if target_region
73
74
  region.ec2_instance_types.each do |t|
74
75
  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},"
75
76
  [:linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb].each do |os|
@@ -87,7 +88,7 @@ def print_ec2_table(pricing)
87
88
  end
88
89
  end
89
90
 
90
- def print_rds_table(pricing)
91
+ def print_rds_table(pricing, target_region = nil)
91
92
  line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,"
92
93
 
93
94
  AwsPricing::DatabaseType.get_database_name.each do |db|
@@ -118,10 +119,11 @@ def print_rds_table(pricing)
118
119
  puts line.chop
119
120
 
120
121
  pricing.regions.each do |region|
121
- region.rds_instance_types.each do |t|
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},"
123
- AwsPricing::DatabaseType.get_database_name.each do |db|
124
- unless AwsPricing::DatabaseType.get_available_types(db).nil?
122
+ next if region.name != target_region if target_region
123
+ region.rds_instance_types.each do |t|
124
+ 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},"
125
+ AwsPricing::DatabaseType.get_database_name.each do |db|
126
+ unless AwsPricing::DatabaseType.get_available_types(db).nil?
125
127
  AwsPricing::DatabaseType.get_available_types(db).each do |deploy_type|
126
128
  if deploy_type == :byol_multiaz
127
129
  line += "#{t.price_per_hour(db, :ondemand, nil, true, true)},"
@@ -129,11 +131,11 @@ def print_rds_table(pricing)
129
131
  line += "#{t.price_per_hour(db, :ondemand, nil, deploy_type == :multiaz, deploy_type == :byol)},"
130
132
  end
131
133
  end
132
- else
134
+ else
133
135
  line += "#{t.price_per_hour(db, :ondemand, nil)},"
134
- end
135
- end
136
- [:year1, :year3].each do |term|
136
+ end
137
+ end
138
+ [:year1, :year3].each do |term|
137
139
  [:light, :medium, :heavy].each do |res_type|
138
140
  AwsPricing::DatabaseType.get_database_name.each do |db|
139
141
  unless AwsPricing::DatabaseType.get_available_types(db).nil?
@@ -147,10 +149,10 @@ def print_rds_table(pricing)
147
149
  else
148
150
  line += "#{t.prepay(db, res_type, term)},#{t.price_per_hour(db, res_type, term)},"
149
151
  end
150
- end
151
- end
152
- end
153
- puts line.chop
154
- end
152
+ end
153
+ end
154
+ end
155
+ puts line.chop
156
+ end
155
157
  end
156
158
  end
@@ -7,7 +7,6 @@ Dir[File.join(File.dirname(__FILE__), 'amazon-pricing/*.rb')].sort.each { |lib|
7
7
 
8
8
  require 'aws-price-list'
9
9
  require 'ec2-price-list'
10
- require 'gov-cloud-price-list'
11
10
  require 'rds-price-list'
12
11
 
13
12
  require 'logger'
@@ -8,5 +8,5 @@
8
8
  # Home:: http://github.com/CloudHealth/amazon-pricing
9
9
  #++
10
10
  module AwsPricing
11
- VERSION = '0.1.53'
11
+ VERSION = '0.1.54'
12
12
  end
@@ -16,16 +16,11 @@ module AwsPricing
16
16
  class PriceList
17
17
  attr_accessor :regions
18
18
 
19
- def initialize(is_govcloud = false)
19
+ def initialize()
20
20
  @_regions = {}
21
21
 
22
22
  # Creating regions upfront since different json files all use different naming conventions. No more ad-hoc creation.
23
- if is_govcloud
24
- regions = ["us-gov-west-1"]
25
- else
26
- # AWS added some but not all of teh data for us-gov-west-1. Not sure why they have not completed it. If they do not deprecate the screen scraping.
27
- regions = ["eu-west-1", "sa-east-1", "us-east-1", "ap-northeast-1", "us-west-2", "us-west-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1"]
28
- end
23
+ regions = ["eu-west-1", "sa-east-1", "us-east-1", "ap-northeast-1", "us-west-2", "us-west-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "us-gov-west-1"]
29
24
 
30
25
  regions.each do |name|
31
26
  @_regions[name] = Region.new(name)
@@ -146,4 +146,49 @@ class TestEc2InstanceTypes < Test::Unit::TestCase
146
146
  end
147
147
  end
148
148
 
149
+ def test_govcloud_cc8xlarge_issue
150
+ obj = @@ec2_pricing.get_instance_type('us-gov-west-1', 'm3.large')
151
+ assert obj.api_name == 'm3.large'
152
+ end
153
+
154
+ def test_govcloud_memory
155
+ # Validate instance types in specific regions are available
156
+ region = @@ec2_pricing.get_region('us-gov-west-1')
157
+ instance = region.get_ec2_instance_type('m3.large')
158
+ assert instance.memory_in_mb == 7500
159
+ end
160
+
161
+ def test_govcloud_virtual_cores
162
+ region = @@ec2_pricing.get_region('us-gov-west-1')
163
+ instance = region.get_ec2_instance_type('m3.large')
164
+ assert instance.virtual_cores == 2
165
+ end
166
+
167
+ def test_govcloud_ebs
168
+ region = @@ec2_pricing.get_region('us-gov-west-1')
169
+ assert region.ebs_price.standard_per_gb == 0.065
170
+ assert region.ebs_price.standard_per_million_io == 0.065
171
+ assert region.ebs_price.preferred_per_gb == 0.15
172
+ assert region.ebs_price.preferred_per_iops == 0.078
173
+ assert region.ebs_price.s3_snaps_per_gb == 0.125
174
+ end
175
+
176
+ def test_govcloud_new_reservation_types
177
+ region = @@ec2_pricing.get_region('us-gov-west-1')
178
+ instance = region.get_ec2_instance_type('r3.large')
179
+ os = instance.get_operating_system(:linux)
180
+ assert os.ondemand_price_per_hour == 0.210
181
+ assert os.partialupfront_prepay_1_year == 649
182
+ assert os.allupfront_prepay_1_year == 976
183
+ assert os.partialupfront_prepay_3_year == 1239
184
+ assert os.allupfront_prepay_3_year == 1935
185
+ assert os.noupfront_effective_rate_1_year == 0.1320
186
+ assert os.partialupfront_effective_rate_1_year == 0.1131
187
+ assert os.allupfront_effective_rate_1_year == 0.1114
188
+ assert os.partialupfront_effective_rate_3_year == 0.0781
189
+ assert os.allupfront_effective_rate_3_year == 0.0736
190
+ end
191
+
192
+
193
+
149
194
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon-pricing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.53
4
+ version: 0.1.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Kinsella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby library for retrieving pricing for Amazon Web Services
14
14
  email:
@@ -43,7 +43,6 @@ files:
43
43
  - lib/amazon-pricing/version.rb
44
44
  - lib/aws-price-list.rb
45
45
  - lib/ec2-price-list.rb
46
- - lib/gov-cloud-price-list.rb
47
46
  - lib/rds-price-list.rb
48
47
  - spec/instance_type_spec.rb
49
48
  - spec/price_list_spec.rb
@@ -51,7 +50,6 @@ files:
51
50
  - spec/spec_helper.rb
52
51
  - spec/support/.gitignore
53
52
  - test/ec2_instance_types_test.rb
54
- - test/govcloud_test.rb
55
53
  - test/helper.rb
56
54
  homepage: http://github.com/CloudHealth/amazon-pricing
57
55
  licenses:
@@ -89,6 +87,4 @@ test_files:
89
87
  - spec/spec_helper.rb
90
88
  - spec/support/.gitignore
91
89
  - test/ec2_instance_types_test.rb
92
- - test/govcloud_test.rb
93
90
  - test/helper.rb
94
- has_rdoc:
@@ -1,273 +0,0 @@
1
- module AwsPricing
2
-
3
- class GovCloudEc2PriceList < PriceList
4
- GOV_CLOUD_URL = "http://aws.amazon.com/govcloud-us/pricing/ec2/"
5
- GOV_CLOUD_EBS_URL = "http://aws.amazon.com/govcloud-us/pricing/ebs/"
6
-
7
- def initialize
8
- super(true)
9
- InstanceType.populate_lookups
10
- get_ec2_instance_pricing
11
- fetch_ec2_ebs_pricing
12
- end
13
-
14
- protected
15
-
16
- def get_ec2_instance_pricing
17
-
18
- client = Mechanize.new
19
- page = client.get(GOV_CLOUD_URL)
20
- tables = page.search("//div[@class='aws-table ']")
21
- for i in 0..3
22
- create_ondemand_instances(tables[i])
23
- end
24
-
25
- for i in 4..9
26
- # GovCloud no longer supports reservation types
27
- #create_reserved_instances(tables[i], :light)
28
- end
29
- for i in 9..22
30
- # GovCloud no longer supports reservation types
31
- #create_reserved_instances(tables[i], :medium)
32
- end
33
- for i in 23..33
34
- # GovCloud no longer supports reservation types
35
- #create_reserved_instances(tables[i], :heavy)
36
- end
37
-
38
- end
39
-
40
- # e.g. [["Prices / Hour", "Amazon Linux", "RHEL", "SLES"], ["m1.small", "$0.053", "$0.083", "$0.083"]]
41
- def create_ondemand_instances(table)
42
- rows = get_rows(table)
43
- header = rows[0]
44
- @_regions.values.each do |region|
45
-
46
- rows.slice(1, rows.size).each do |row|
47
- api_name = row[0]
48
- instance_type = region.get_ec2_instance_type(api_name)
49
- if instance_type.nil?
50
- api_name, name = Ec2InstanceType.get_name(nil, row[0], false)
51
- instance_type = region.add_or_update_ec2_instance_type(api_name, name)
52
- end
53
- instance_type.update_pricing2(get_os(header[1]), :ondemand, row[1])
54
- instance_type.update_pricing2(get_os(header[2]), :ondemand, row[2])
55
- instance_type.update_pricing2(get_os(header[3]), :ondemand, row[3])
56
- end
57
- end
58
- end
59
-
60
- # 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"]]
61
- def create_reserved_instances(table, res_type)
62
- rows = get_rows(table)
63
- operating_system = get_os(table.search(".//td/p").last.inner_text.strip) # Wow...
64
-
65
- @_regions.values.each do |region|
66
-
67
- rows.slice(1, rows.size).each do |row|
68
- api_name = row[0]
69
- instance_type = region.get_instance_type(api_name)
70
- if instance_type.nil?
71
- api_name, name = Ec2InstanceType.get_name(nil, api_name, true)
72
- instance_type = region.add_or_update_ec2_instance_type(api_name, name)
73
- end
74
- instance_type.update_pricing2(operating_system, res_type, nil, row[1], row[3], row[2], row[4])
75
- end
76
- end
77
- end
78
-
79
- def fetch_ec2_ebs_pricing
80
- client = Mechanize.new
81
- page = client.get(GOV_CLOUD_EBS_URL)
82
- ebs_costs = page.search("//div[@class='text-box section']//li")
83
- @_regions.values.each do |region|
84
- region.ebs_price = EbsPrice.new(region)
85
- region.ebs_price.preferred_per_gb = get_ebs_price(ebs_costs[1])
86
- region.ebs_price.preferred_per_iops = get_ebs_price(ebs_costs[2])
87
- region.ebs_price.standard_per_gb = get_ebs_price(ebs_costs[3])
88
- region.ebs_price.standard_per_million_io = get_ebs_price(ebs_costs[4])
89
- region.ebs_price.ssd_per_gb = nil
90
- region.ebs_price.s3_snaps_per_gb = get_ebs_price(ebs_costs[5])
91
- end
92
-
93
- end
94
-
95
- # e.g. $0.065 per GB-Month of provisioned storage
96
- def get_ebs_price(xml_element)
97
- tokens = xml_element.text.split(" ")
98
- tokens[0].gsub("$", "").to_f
99
- end
100
-
101
- def get_os(val)
102
- case val
103
- when "Amazon Linux"
104
- :linux
105
- when "RHEL"
106
- :rhel
107
- when "SLES"
108
- :sles
109
- when "Windows"
110
- :mswin
111
- when "Windows SQL Server Web", "Windows SQL Server Web Edition", "Windows SQL Server\n Web Edition", "Server Web"
112
- :mswinSQL
113
- when "Windows SQL Server Standard", "Windows SQL Server Standard Edition", "Windows SQL Server\n Standard Edition"
114
- :mswinSQLWeb
115
- else
116
- raise "Unable to identify operating system '#{val}'"
117
- end
118
- end
119
-
120
- def get_rows(html_table)
121
- rows = []
122
- html_table.search(".//tr").each do |tr|
123
- row = []
124
- tr.search(".//td").each do |td|
125
- row << td.inner_text.strip.sub("\n", " ").sub(" ", " ")
126
- end
127
- next if row.size == 1
128
- rows << row unless row.empty?
129
- end
130
- rows
131
- end
132
- end
133
-
134
-
135
- class GovCloudRdsPriceList < PriceList
136
- GOV_CLOUD_URL = "http://aws.amazon.com/govcloud-us/pricing/rds/"
137
-
138
- def initialize
139
- @_regions = {}
140
- @_regions["us-gov-west-1"] = Region.new("us-gov-west-1")
141
- InstanceType.populate_lookups
142
- get_rds_instance_pricing
143
- end
144
-
145
- protected
146
- #@@DB_TYPE = [:mysql, :postgresql, :oracle, :sqlserver]
147
- #@@RES_TYPES = [:light, :medium, :heavy]
148
-
149
- def get_rds_instance_pricing
150
-
151
- client = Mechanize.new
152
- page = client.get(GOV_CLOUD_URL)
153
- tables = page.search("//div[@class='aws-table ']")
154
-
155
- # Mysql
156
- create_ondemand_instances(:mysql, :ondemand, false, false, get_rows(tables[0]))
157
- create_ondemand_instances(:mysql, :ondemand, true, false, get_rows(tables[1]))
158
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[2]))
159
- create_reserved_instances(:mysql, :light, false, false, no_multi_az_rows)
160
- create_reserved_instances(:mysql, :light, true, false, multi_az_rows)
161
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[3]))
162
- create_reserved_instances(:mysql, :medium, false, false, no_multi_az_rows)
163
- create_reserved_instances(:mysql, :medium, true, false, multi_az_rows)
164
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[4]))
165
- create_reserved_instances(:mysql, :heavy, false, false, no_multi_az_rows)
166
- create_reserved_instances(:mysql, :heavy, true, false, multi_az_rows)
167
-
168
- # Oracle
169
- create_ondemand_instances(:oracle_se1, :ondemand, false, false, get_rows(tables[5]))
170
- create_ondemand_instances(:oracle_se1, :ondemand, true, false, get_rows(tables[6]))
171
- create_ondemand_instances(:oracle_se1, :ondemand, false, true, get_rows(tables[7]))
172
- create_ondemand_instances(:oracle_se1, :ondemand, true, true, get_rows(tables[8]))
173
-
174
- row = 9
175
- [false, true].each do |is_byol|
176
- [:light, :medium, :heavy].each do |res_type|
177
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[9]))
178
- create_reserved_instances(:oracle_se1, res_type, false, is_byol, no_multi_az_rows)
179
- create_reserved_instances(:oracle_se1, res_type, true, is_byol, multi_az_rows)
180
- row += 1
181
- end
182
- end
183
-
184
- # SQL Server
185
- create_ondemand_instances(:sqlserver_ex, :ondemand, false, false, get_rows(tables[15]))
186
- create_ondemand_instances(:sqlserver_web, :ondemand, false, false, get_rows(tables[16]))
187
- create_ondemand_instances(:sqlserver_se, :ondemand, false, false, get_rows(tables[17]))
188
- row = 18
189
- [:light, :medium, :heavy].each do |restype|
190
- [:sqlserver_ex, :sqlserver_web, :sqlserver_se].each do |db|
191
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[row]))
192
- create_reserved_instances(db, restype, false, false, no_multi_az_rows)
193
- create_reserved_instances(db, restype, true, false, multi_az_rows)
194
- row += 1
195
- end
196
- end
197
-
198
- # Postgres
199
- # Mysql
200
- create_ondemand_instances(:postgresql, :ondemand, false, false, get_rows(tables[31]))
201
- create_ondemand_instances(:postgresql, :ondemand, true, false, get_rows(tables[32]))
202
- row = 33
203
- [:light, :medium, :heavy].each do |restype|
204
- no_multi_az_rows, multi_az_rows = get_reserved_rows(get_rows(tables[row]))
205
- create_reserved_instances(:postgresql, restype, false, false, no_multi_az_rows)
206
- create_reserved_instances(:postgresql, restype, true, false, multi_az_rows)
207
- row += 1
208
- end
209
-
210
- end
211
-
212
- # e.g. [["General Purpose - Previous Generation", "Price Per Hour"], ["m1.small", "$0.090"], ["m1.medium", "$0.185"]]
213
- def create_ondemand_instances(db_type, res_type, is_multi_az, is_byol, rows)
214
- @_regions.values.each do |region|
215
- # Skip header row
216
- rows.each do |row|
217
- api_name = row[0]
218
- unless api_name.include?("db.")
219
- $stderr.puts "Skipping row containing non-db type: #{api_name}"
220
- next
221
- end
222
- instance_type = region.get_rds_instance_type(api_name)
223
- if instance_type.nil?
224
- api_name, name = RdsInstanceType.get_name(nil, row[0], false)
225
- instance_type = region.add_or_update_rds_instance_type(api_name, name)
226
- end
227
- instance_type.update_pricing2(db_type, res_type, is_multi_az, is_byol, row[1])
228
- end
229
- end
230
- end
231
-
232
- # e.g. [[" ", "1 yr Term", "3 yr Term"], [" ", "Upfront", "Hourly", "Upfront", "Hourly"], ["m1.small", "$159", "$0.035", "$249", "$0.033"]]
233
- def create_reserved_instances(db_type, res_type, is_multi_az, is_byol, rows)
234
- @_regions.values.each do |region|
235
- rows.each do |row|
236
- api_name = row[0]
237
- unless api_name.include?("db.")
238
- $stderr.puts "Skipping row containing non-db type: #{api_name}"
239
- next
240
- end
241
- instance_type = region.get_rds_instance_type(api_name)
242
- if instance_type.nil?
243
- api_name, name = RdsInstanceType.get_name(nil, row[0], true)
244
- instance_type = region.add_or_update_rds_instance_type(api_name, name)
245
- end
246
- instance_type.update_pricing2(db_type, res_type, is_multi_az, is_byol, nil, row[1], row[3], row[2], row[4])
247
- end
248
- end
249
- end
250
-
251
- def get_reserved_rows(rows)
252
- # Skip 2 header rows
253
- new_rows = rows.slice(2, rows.size)
254
- no_multi_az_rows = new_rows.slice(0, new_rows.size / 2)
255
- multi_az_rows = new_rows.slice(new_rows.size / 2, new_rows.size / 2)
256
- [no_multi_az_rows, multi_az_rows]
257
- end
258
-
259
- def get_rows(html_table)
260
- rows = []
261
- html_table.search(".//tr").each do |tr|
262
- row = []
263
- tr.search(".//td").each do |td|
264
- row << td.inner_text.strip.sub("\n", " ").sub(" ", " ")
265
- end
266
- # Various <tR> elements contain labels which have only 1 <td> - except heavy multi-az ;)
267
- next if row.size == 1 || row[0].include?("Multi-AZ Deployment")
268
- rows << row unless row.empty?
269
- end
270
- rows
271
- end
272
- end
273
- end
@@ -1,50 +0,0 @@
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
- def setup
19
- #This is expensive, so only do once.
20
- @@ec2_pricing = AwsPricing::GovCloudEc2PriceList.new
21
- end
22
-
23
- def test_cc8xlarge_issue
24
- obj = @@ec2_pricing.get_instance_type('us-gov-west-1', 'm3.large')
25
- assert obj.api_name == 'm3.large'
26
- end
27
-
28
- def test_memory
29
- # Validate instance types in specific regions are available
30
- region = @@ec2_pricing.get_region('us-gov-west-1')
31
- instance = region.get_ec2_instance_type('m3.large')
32
- assert instance.memory_in_mb == 7500
33
- end
34
-
35
- def test_virtual_cores
36
- region = @@ec2_pricing.get_region('us-gov-west-1')
37
- instance = region.get_ec2_instance_type('m3.large')
38
- assert instance.virtual_cores == 2
39
- end
40
-
41
- def test_ebs
42
- region = @@ec2_pricing.get_region('us-gov-west-1')
43
- assert region.ebs_price.standard_per_gb == 0.065
44
- assert region.ebs_price.standard_per_million_io == 0.065
45
- assert region.ebs_price.preferred_per_gb == 0.15
46
- assert region.ebs_price.preferred_per_iops == 0.078
47
- assert region.ebs_price.s3_snaps_per_gb == 0.125
48
- end
49
-
50
- end