amazon-pricing 0.1.65 → 0.1.66

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWQ4OGZhYmU5NmE2NzZiNGQzZjIxNTBhNGYzYzA1ZjgyYzM5ZTQ5Mw==
4
+ NDFiYTIxOTk0ZDIyMTJiNDhlZGIzYTMyY2NhYmZkMTIzYTQyNTk4Yw==
5
5
  data.tar.gz: !binary |-
6
- ZGMzZTc4NWEwMzM3ZDhiYzMwMjI2OWQ5YmUyODBlY2JkYTcyMzQxNQ==
6
+ NjVhMTVjNDEyNDRlZTM0ZjhhY2Q5YWZjNzNmMTJmOTkxODE3NTI3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWUyZjA3N2QzNTllMjRmZmE3YmU2MGEwMzkxNTBjOWNhMWZiMWY2OTg3ZTRj
10
- OTE5OWRmNTM1Yjg1MTM2NjdkNTU3MDg4OGJjZDZlYTViZjViNzk2YzFlOTI3
11
- YjY5ZTc2OTFiY2E1ODFiMDMxNjRiOTNjMzQ1ZmM3M2VhMzk1ZGQ=
9
+ YTJkMzAyMWJiNDI0ZTUzMWI2N2JiMzRhNDEwYzc4OGNkMGU4MDExYTg3MGVi
10
+ ZDk2MjJhODFkOWEwN2FkZWRlNzM3N2NhNmEyZTgxODQ0MDdlYjNiZTJmOTFm
11
+ Mzg4MGYwNTE1ZjE3ZGYyOWYyMTJmY2FiN2JiZDQ2YjI3NWNmYzQ=
12
12
  data.tar.gz: !binary |-
13
- OTVmNGIyZWU1MmExNTFmYzJlZDM3ZmFkODU1NmYyNDY0YTI3ZjM2NjVjY2Q4
14
- OWVmOTQ5ODliMWU1ODkzNGRkN2FmOGZmYTI1NDkyODRkNjQ1ZGQ5NDM0YjQw
15
- OGUzZGVlNTcxNjIzZDMwMTBjZGIyNWViNjU3NDIxYmQ1NWQwZDI=
13
+ MDNkZjI5MGU5Mjk4MDYzMTVhMjIwZTk1NTQ1NTRjNzQwZTM2ZTNhMjQxMjQ3
14
+ NDhkOGYxMzFkNWE5MGExNTNmZGViYWYzOTIyYTg3ODhjMzMwYjQyMzc0NjA2
15
+ OTM4ODNjZWIyZDVlOTE0NGFiYmI5MzE3NGY1NWYzMGI2ZDEzOTA=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amazon-pricing (0.1.65)
4
+ amazon-pricing (0.1.66)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -41,6 +41,13 @@ task :print_rds_price_list do
41
41
  print_rds_table(pricing)
42
42
  end
43
43
 
44
+ desc "Prints current ElastiCache pricing to CSV format"
45
+ task :print_elasticache_price_list do
46
+ require 'amazon-pricing'
47
+ pricing = AwsPricing::ElastiCachePriceList.new
48
+ print_elasticache_table(pricing)
49
+ end
50
+
44
51
  desc "Prints current GovCloud EC2 pricing in CSV format"
45
52
  task :print_govcloud_ec2_price_list do
46
53
  require 'amazon-pricing'
@@ -88,6 +95,35 @@ def print_ec2_table(pricing, target_region = nil)
88
95
  end
89
96
  end
90
97
 
98
+ def print_elasticache_table(pricing, target_region = nil)
99
+ line = "Region,Node Type,API Name,Memmory (MB),Virtual Cores,Disk Type,OD PPH,"
100
+ [:year1, :year3].each do |term|
101
+ [:partialupfront].each do |res_type|
102
+ [:memcached].each do |cache|
103
+ line += "#{term} #{res_type} #{cache} Prepay,#{term} #{res_type} #{cache} PPH,"
104
+ end
105
+ end
106
+ end
107
+ puts line.chop
108
+ pricing.regions.each do |region|
109
+ next if region.name != target_orgion if target_region
110
+ region.elasticache_node_types.each do |t|
111
+ line = "#{region.name},#{t.name},#{t.api_name},#{t.memory_in_mb},#{t.virtual_cores},"
112
+ [:memcached].each do |cache|
113
+ line += "#{t.price_per_hour(cache, :ondemand)},"
114
+ end
115
+ [:year1, :year3].each do |term|
116
+ [:partialupfront].each do |res_type|
117
+ [:memcached].each do |cache|
118
+ line += "#{t.prepay(cache, res_type, term)},#{t.price_per_hour(cache, res_type, term)},"
119
+ end
120
+ end
121
+ end
122
+ puts line.chop
123
+ end
124
+ end
125
+ end
126
+
91
127
  def print_rds_table(pricing, target_region = nil)
92
128
  line = "Region,Instance Type,API Name,Memory (MB),Disk (GB),Compute Units,Virtual Cores,Disk Type,"
93
129
 
@@ -10,3 +10,4 @@ require 'amazon-pricing/ec2-price-list'
10
10
  require 'amazon-pricing/ec2-di-price-list'
11
11
  require 'amazon-pricing/rds-price-list'
12
12
  require 'amazon-pricing/dynamo-db-price-list'
13
+ require 'amazon-pricing/elasticache-price-list'
@@ -97,9 +97,10 @@ module AwsPricing
97
97
  # region
98
98
  #end
99
99
 
100
- EC2_BASE_URL = "http://a0.awsstatic.com/pricing/1/ec2/"
101
- EBS_BASE_URL = "http://a0.awsstatic.com/pricing/1/ebs/"
102
- RDS_BASE_URL = "http://a0.awsstatic.com/pricing/1/rds/"
100
+ EC2_BASE_URL = "http://a0.awsstatic.com/pricing/1/ec2/"
101
+ EBS_BASE_URL = "http://a0.awsstatic.com/pricing/1/ebs/"
102
+ RDS_BASE_URL = "http://a0.awsstatic.com/pricing/1/rds/"
103
+ ELASTICACHE_BASE_URL = "http://a0.awsstatic.com/pricing/1/elasticache/"
103
104
 
104
105
  DI_OD_BASE_URL = "http://a0.awsstatic.com/pricing/1/dedicated-instances/"
105
106
  RESERVED_DI_BASE_URL = "http://a0.awsstatic.com/pricing/1/ec2/ri-v2/"
@@ -129,4 +130,4 @@ module AwsPricing
129
130
  end
130
131
 
131
132
 
132
- end
133
+ end
@@ -0,0 +1,16 @@
1
+ #--
2
+ # Amazon Web Services Pricing Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-pricing
5
+ # Author:: Joe Kinsella (mailto:joe.kinsella@gmail.com)
6
+ # Copyright:: Copyright (c) 2011-2013 CloudHealth
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/CloudHealth/amazon-pricing
9
+ #++
10
+
11
+ require 'amazon-pricing/definitions/category-type'
12
+
13
+ module AwsPricing
14
+ class Cache < CategoryType
15
+ end
16
+ end
@@ -0,0 +1,74 @@
1
+ require 'amazon-pricing/definitions/instance-type'
2
+
3
+ module AwsPricing
4
+ class ElastiCacheNodeType < InstanceType
5
+
6
+ def initialize(region, api_name, name)
7
+ @category_types = {}
8
+
9
+ @region = region
10
+ @name = name
11
+ @api_name = api_name
12
+
13
+ api_name_for_lookup = api_name.sub("cache.", "")
14
+
15
+ @memory_in_mb = InstanceType.get_memory(api_name)
16
+ @virtual_cores = InstanceType.get_virtual_cores(api_name_for_lookup)
17
+ end
18
+
19
+ def available?(cache_type = :memcached, type_of_instance = :ondemand)
20
+ cache = get_category_type(cache_type)
21
+ return false if cache.nil?
22
+ cache.available?(type_of_instance)
23
+ end
24
+
25
+ def update_pricing(cache_type, type_of_instance, json)
26
+ cache = get_category_type(cache_type)
27
+ if cache.nil?
28
+ cache = Cache.new(self, cache_type)
29
+ @category_types[cache_type] = cache
30
+ end
31
+
32
+ if type_of_instance == :ondemand
33
+ values = ElastiCacheNodeType::get_values(json, cache_type)
34
+ price = coerce_price(values[cache_type.to_s])
35
+ cache.set_price_per_hour(type_of_instance, nil, price)
36
+ else
37
+ json['valueColumns'].each do |val|
38
+
39
+ if val['prices']['USD'].empty?
40
+ next
41
+ end
42
+
43
+ price = coerce_price(val['prices']['USD'])
44
+
45
+ case val['name']
46
+ when "yrTerm1"
47
+ cache.set_prepay(type_of_instance, :year1, price)
48
+ when "yrTerm3"
49
+ cache.set_prepay(type_of_instance, :year3, price)
50
+ when "yearTerm1Hourly"
51
+ cache.set_price_per_hour(type_of_instance, :year1, price)
52
+ when "yearTerm3Hourly"
53
+ cache.set_price_per_hour(type_of_instance, :year3, price)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ protected
60
+
61
+ def self.get_name(instance_type, api_name, is_reserved = false)
62
+ api_name.sub!(" *", "")
63
+
64
+ unless @@Name_Lookup.has_key? api_name
65
+ raise UnknownTypeError, "Unknown instance type #{instance_type} #{api_name}", caller
66
+ end
67
+
68
+ name = @@Name_Lookup.has_key? api_name
69
+
70
+ [api_name, name]
71
+ end
72
+
73
+ end
74
+ end
@@ -86,6 +86,7 @@ module AwsPricing
86
86
  case category
87
87
  when 'os'; 'ec2'
88
88
  when 'db'; 'rds'
89
+ when 'cache'; 'elasticache'
89
90
  else
90
91
  ''
91
92
  end
@@ -253,10 +254,18 @@ module AwsPricing
253
254
  }
254
255
 
255
256
  # NOTE: These are populated by "populate_lookups"
256
- # But... AWS does not always provide memory info (e.g. t2, r3), so those are hardcoded below
257
+ # But... AWS does not always provide memory info (e.g. t2, r3, cache.*), so those are hardcoded below
257
258
  @@Memory_Lookup = {
259
+ 'cache.r3.large' => 13500, 'cache.r3.xlarge' => 28400, 'cache.r3.2xlarge' => 58200, 'cache.r3.4xlarge' => 118000, 'cache.r3.8xlarge' => 237000,
258
260
  'r3.large' => 15250, 'r3.xlarge' => 30500, 'r3.2xlarge' => 61000, 'r3.4xlarge' => 122000, 'r3.8xlarge' => 244000,
261
+ 'cache.m3.medium' => 2780, 'cache.m3.large' => 6050, 'cache.m3.xlarge' => 13300, 'cache.m3.2xlarge' => 27900,
259
262
  't2.micro' => 1000, 't2.small' => 2000, 't2.medium' => 4000, 't2.large' => 8000,
263
+ 'cache.t2.micro' => 555, 'cache.t2.small' => 1550, 'cache.t2.medidium' => 3220,
264
+
265
+ 'cache.m1.small' => 1300, 'cache.m1.medium' => 3350, 'cache.m1.large' => 7100, 'cache.m1.xlarge' => 14600,
266
+ 'cache.m2.xlarge' => 16700, 'cache.m2.2xlarge' => 33800, 'cache.m2.4xlarge' => 68000,
267
+ 'cache.c1.xlarge' => 6600,
268
+ 'cache.t1.micro' => 213,
260
269
  }
261
270
  @@Virtual_Cores_Lookup = {
262
271
  'r3.large' => 2, 'r3.xlarge' => 4, 'r3.2xlarge' => 8, 'r3.4xlarge' => 16, 'r3.8xlarge' => 32,
@@ -15,12 +15,13 @@ module AwsPricing
15
15
  # e.g. us-east, us-west
16
16
  #
17
17
  class Region
18
- attr_accessor :name, :ebs_price, :ec2_instance_types, :rds_instance_types
18
+ attr_accessor :name, :ebs_price, :ec2_instance_types, :rds_instance_types, :elasticache_node_types
19
19
 
20
20
  def initialize(name)
21
21
  @name = name
22
- @ec2_instance_types = {}
23
- @rds_instance_types = {}
22
+ @ec2_instance_types = {}
23
+ @rds_instance_types = {}
24
+ @elasticache_node_types = {}
24
25
  end
25
26
 
26
27
  # Maintained for backward compatibility reasons (retrieves EC2 instance type)
@@ -36,6 +37,10 @@ module AwsPricing
36
37
  @rds_instance_types.values
37
38
  end
38
39
 
40
+ def elasticache_node_types
41
+ @elasticache_node_types.values
42
+ end
43
+
39
44
  # Returns whether an instance_type is available.
40
45
  # operating_system = :linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb
41
46
  # type_of_instance = :ondemand, :light, :medium, :heavy
@@ -64,6 +69,15 @@ module AwsPricing
64
69
  current
65
70
  end
66
71
 
72
+ def add_or_update_elasticache_node_type(api_name, name)
73
+ current = get_elasticache_node_type(api_name)
74
+ if current.nil?
75
+ current = ElastiCacheNodeType.new(self, api_name, name)
76
+ @elasticache_node_types[api_name] = current
77
+ end
78
+ current
79
+ end
80
+
67
81
  # Maintained for backward compatibility reasons (retrieves EC2 instance type)
68
82
  def get_instance_type(api_name)
69
83
  get_ec2_instance_type(api_name)
@@ -77,6 +91,10 @@ module AwsPricing
77
91
  @rds_instance_types[api_name]
78
92
  end
79
93
 
94
+ def get_elasticache_node_type(api_name)
95
+ @elasticache_node_types[api_name]
96
+ end
97
+
80
98
  end
81
99
 
82
- end
100
+ end
@@ -0,0 +1,89 @@
1
+ module AwsPricing
2
+ class ElastiCachePriceList < PriceList
3
+
4
+ def initialize
5
+ super
6
+ get_elasticache_on_demand_node_pricing
7
+ get_elasticache_reserved_node_pricing
8
+ end
9
+
10
+ protected
11
+
12
+ # for now all engines have the save cost
13
+ @@CACHE_TYPES = [:memcached]
14
+
15
+ def get_elasticache_on_demand_node_pricing
16
+ od_url = ELASTICACHE_BASE_URL + "pricing-standard-deployments-elasticache.min.js"
17
+ od_legacy_url = ELASTICACHE_BASE_URL + "previous-generation/pricing-standard-deployments-elasticache.min.js"
18
+ @@CACHE_TYPES.each do |type|
19
+ fetch_on_demand_elasticache_node_pricing(od_url, type)
20
+
21
+ # fetch again for legacy prices
22
+ fetch_on_demand_elasticache_node_pricing(od_legacy_url, type)
23
+ end
24
+ end
25
+
26
+ def get_elasticache_reserved_node_pricing
27
+ rc_url = ELASTICACHE_BASE_URL + "pricing-elasticache-heavy-standard-deployments.min.js"
28
+ rc_legacy_url = ELASTICACHE_BASE_URL + "previous-generation/pricing-elasticache-heavy-standard-deployments.min.js"
29
+ @@CACHE_TYPES.each do |type|
30
+ fetch_reserved_elasticache_node_pricing(rc_url, type)
31
+
32
+ # fetch again for legacy prices
33
+ fetch_reserved_elasticache_node_pricing(rc_legacy_url, type)
34
+ end
35
+ end
36
+
37
+ def fetch_on_demand_elasticache_node_pricing(url, cache_type)
38
+ res = PriceList.fetch_url(url)
39
+ res['config']['regions'].each do |reg|
40
+ region_name = reg['region']
41
+ region = get_region(region_name)
42
+ if region.nil?
43
+ $stderr.puts "[fetch_elasticache_od_node_pricing] WARNING: unable to find region #{region_name}"
44
+ next
45
+ end # region.nil?
46
+
47
+ reg['types'].each do |type|
48
+ name = type['name']
49
+
50
+ type['tiers'].each do |tier|
51
+ begin
52
+ api_name = tier['name']
53
+ node_type = region.add_or_update_elasticache_node_type(api_name, name)
54
+ node_type.update_pricing(cache_type, :ondemand, tier)
55
+ rescue UnknownTypeError
56
+ $stderr.puts "[fetch_on_demand_elasticache_node_pricing] WARNING: encountered #{$!.message}"
57
+ end # begin
58
+ end # do |tier|
59
+ end # do |type|
60
+ end # do |reg|
61
+ end
62
+
63
+ def fetch_reserved_elasticache_node_pricing(url, cache_type)
64
+ res = PriceList.fetch_url(url)
65
+ res['config']['regions'].each do |reg|
66
+ region_name = reg['region']
67
+ region = get_region(region_name)
68
+ if region.nil?
69
+ $stderr.puts "[fetch_elasticache_rc_node_pricing] WARNING: unable to find region #{region_name}"
70
+ next
71
+ end #region.nil?
72
+
73
+ reg['instanceTypes'].each do |type|
74
+ name = type['generation']
75
+ type['tiers'].each do |tier|
76
+ begin
77
+ api_name = tier['size']
78
+ node_type = region.add_or_update_elasticache_node_type(api_name, name)
79
+ node_type.update_pricing(cache_type, :partialupfront, tier)
80
+ rescue UnknownTypeError
81
+ $stderr.puts "[fetch_reserved_rds_instance_pricing] WARNING: encountered #{$!.message}"
82
+ end
83
+ end # do |tier|
84
+ end # do |type|
85
+ end # do |reg|
86
+ end
87
+
88
+ end
89
+ end
@@ -8,5 +8,5 @@
8
8
  # Home:: http://github.com/CloudHealth/amazon-pricing
9
9
  #++
10
10
  module AwsPricing
11
- VERSION = '0.1.65'
11
+ VERSION = '0.1.66'
12
12
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe AwsPricing::ElastiCachePriceList do
4
+ before(:all) do
5
+ @pricing = AwsPricing::ElastiCachePriceList.new
6
+ @node_types = [:memcached]
7
+ end
8
+
9
+ describe 'new' do
10
+ it 'ElastiCachePriceList.new should return the valid response' do
11
+ @pricing.regions.each do |region|
12
+ # Result have valid node name
13
+ expect(@node_types).to include(region.elasticache_node_types.first.category_types.first.name)
14
+ # values should not be nil
15
+ region.elasticache_node_types.first.category_types.first.ondemand_price_per_hour.should_not be_nil
16
+ # other prices per hour
17
+ region.elasticache_node_types.first.category_types.first.partialupfront_prepay_1_year.should_not be_nil
18
+ region.elasticache_node_types.first.category_types.first.partialupfront_prepay_3_year.should_not be_nil
19
+ region.elasticache_node_types.first.category_types.first.partialupfront_price_per_hour_1_year.should_not be_nil
20
+ region.elasticache_node_types.first.category_types.first.partialupfront_price_per_hour_3_year.should_not be_nil
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '::get_api_name' do
26
+ it "raises an UnknownTypeError on an unexpected instance type" do
27
+ expect {
28
+ AwsPricing::ElastiCacheNodeType::get_name 'IDK', 'MoreIDK'
29
+ }.to raise_error(AwsPricing::UnknownTypeError)
30
+ end
31
+ end
32
+
33
+ describe 'get_breakeven_months' do
34
+ it "test_fetch_all_breakeven_months" do
35
+ @pricing.regions.each do |region|
36
+ region.elasticache_node_types.each do |node|
37
+ [:year1, :year3].each do |term|
38
+ [:partialupfront].each do |res_type|
39
+ [:memcached].each do |cache|
40
+ node.get_breakeven_month(cache, res_type, term).should_not be_nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ 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.65
4
+ version: 0.1.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Kinsella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby library for retrieving pricing for Amazon Web Services
14
14
  email:
@@ -35,10 +35,12 @@ files:
35
35
  - lib/amazon-pricing.rb
36
36
  - lib/amazon-pricing/aws-price-list.rb
37
37
  - lib/amazon-pricing/common/ec2_common.rb
38
+ - lib/amazon-pricing/definitions/cache-type.rb
38
39
  - lib/amazon-pricing/definitions/category-type.rb
39
40
  - lib/amazon-pricing/definitions/database-type.rb
40
41
  - lib/amazon-pricing/definitions/ebs-price.rb
41
42
  - lib/amazon-pricing/definitions/ec2-instance-type.rb
43
+ - lib/amazon-pricing/definitions/elasticache_node_type.rb
42
44
  - lib/amazon-pricing/definitions/instance-type.rb
43
45
  - lib/amazon-pricing/definitions/operating-system.rb
44
46
  - lib/amazon-pricing/definitions/rds-instance-type.rb
@@ -46,10 +48,12 @@ files:
46
48
  - lib/amazon-pricing/dynamo-db-price-list.rb
47
49
  - lib/amazon-pricing/ec2-di-price-list.rb
48
50
  - lib/amazon-pricing/ec2-price-list.rb
51
+ - lib/amazon-pricing/elasticache-price-list.rb
49
52
  - lib/amazon-pricing/helpers/instance-type.rb
50
53
  - lib/amazon-pricing/rds-price-list.rb
51
54
  - lib/amazon-pricing/version.rb
52
55
  - spec/lib/amazon-pricing/definitions/database-type_spec.rb
56
+ - spec/lib/amazon-pricing/elasticache_pricing_spec.rb
53
57
  - spec/lib/amazon-pricing/rds_pricing_spec.rb
54
58
  - spec/spec_helper.rb
55
59
  - spec/support/.gitignore
@@ -80,9 +84,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
84
  version: '0'
81
85
  requirements: []
82
86
  rubyforge_project: amazon-pricing
83
- rubygems_version: 2.3.0
87
+ rubygems_version: 2.4.6
84
88
  signing_key:
85
89
  specification_version: 4
86
90
  summary: Amazon Web Services Pricing Ruby gem
87
- test_files: []
88
- has_rdoc:
91
+ test_files:
92
+ - spec/lib/amazon-pricing/definitions/database-type_spec.rb
93
+ - spec/lib/amazon-pricing/elasticache_pricing_spec.rb
94
+ - spec/lib/amazon-pricing/rds_pricing_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/support/.gitignore
97
+ - test/ec2_instance_types_test.rb
98
+ - test/helper.rb