amazon-pricing 0.1.29 → 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amazon-pricing (0.1.29)
4
+ amazon-pricing (0.1.30)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -96,12 +96,14 @@ module AwsPricing
96
96
 
97
97
  class GovCloudEc2PriceList < PriceList
98
98
  GOV_CLOUD_URL = "http://aws.amazon.com/govcloud-us/pricing/ec2/"
99
+ GOV_CLOUD_EBS_URL = "http://aws.amazon.com/govcloud-us/pricing/ebs/"
99
100
 
100
101
  def initialize
101
102
  @_regions = {}
102
103
  @_regions["us-gov-west"] = Region.new("us-gov-west")
103
104
  InstanceType.populate_lookups
104
105
  get_ec2_instance_pricing
106
+ fetch_ec2_ebs_pricing
105
107
  end
106
108
 
107
109
  protected
@@ -164,6 +166,27 @@ module AwsPricing
164
166
  end
165
167
  end
166
168
 
169
+ def fetch_ec2_ebs_pricing
170
+ client = Mechanize.new
171
+ page = client.get(GOV_CLOUD_EBS_URL)
172
+ ebs_costs = page.search("//div[@class='text section']//li")
173
+ @_regions.values.each do |region|
174
+ region.ebs_price = EbsPrice.new(region)
175
+ region.ebs_price.standard_per_gb = get_ebs_price(ebs_costs[0])
176
+ region.ebs_price.standard_per_million_io = get_ebs_price(ebs_costs[1])
177
+ region.ebs_price.preferred_per_gb = get_ebs_price(ebs_costs[2])
178
+ region.ebs_price.preferred_per_iops = get_ebs_price(ebs_costs[3])
179
+ region.ebs_price.s3_snaps_per_gb = get_ebs_price(ebs_costs[4])
180
+ end
181
+
182
+ end
183
+
184
+ # e.g. $0.065 per GB-Month of provisioned storage
185
+ def get_ebs_price(xml_element)
186
+ tokens = xml_element.text.split(" ")
187
+ tokens[0].gsub("$", "").to_f
188
+ end
189
+
167
190
  def get_os(val)
168
191
  case val
169
192
  when "Amazon Linux"
@@ -352,7 +375,8 @@ module AwsPricing
352
375
  res = PriceList.fetch_url(EBS_BASE_URL + "pricing-ebs.min.js")
353
376
  res["config"]["regions"].each do |ebs_types|
354
377
  region = get_region(ebs_types["region"])
355
- region.ebs_price = EbsPrice.new(region, ebs_types)
378
+ region.ebs_price = EbsPrice.new(region)
379
+ region.ebs_price.update_from_json(ebs_types)
356
380
  end
357
381
  end
358
382
 
@@ -10,10 +10,14 @@
10
10
  module AwsPricing
11
11
 
12
12
  class EbsPrice
13
- attr_reader :standard_per_gb, :standard_per_million_io,
13
+ attr_accessor :region, :standard_per_gb, :standard_per_million_io,
14
14
  :preferred_per_gb, :preferred_per_iops, :s3_snaps_per_gb
15
15
 
16
- def initialize(region, json)
16
+ def initialize(region)
17
+ @region = region
18
+ end
19
+
20
+ def update_from_json(json)
17
21
  json["types"].each do |t|
18
22
  case t["name"]
19
23
  when "ebsVols"
@@ -8,5 +8,5 @@
8
8
  # Home:: http://github.com/CloudHealth/amazon-pricing
9
9
  #++
10
10
  module AwsPricing
11
- VERSION = '0.1.29'
11
+ VERSION = '0.1.30'
12
12
  end
@@ -40,4 +40,13 @@ class TestGovCloud < Test::Unit::TestCase
40
40
  assert instance.virtual_cores == 2
41
41
  end
42
42
 
43
+ def test_ebs
44
+ region = @@ec2_pricing.get_region('us-gov-west')
45
+ assert region.ebs_price.standard_per_gb == 0.065
46
+ assert region.ebs_price.standard_per_million_io == 0.065
47
+ assert region.ebs_price.preferred_per_gb == 0.15
48
+ assert region.ebs_price.preferred_per_iops == 0.12
49
+ assert region.ebs_price.s3_snaps_per_gb == 0.125
50
+ end
51
+
43
52
  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.29
4
+ version: 0.1.30
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  segments:
67
67
  - 0
68
- hash: 1325936641347822274
68
+ hash: -4082041594937074380
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  segments:
76
76
  - 0
77
- hash: 1325936641347822274
77
+ hash: -4082041594937074380
78
78
  requirements: []
79
79
  rubyforge_project: amazon-pricing
80
80
  rubygems_version: 1.8.25