Class: AwsPricing::ElastiCacheNodeType

Inherits:
InstanceType show all
Defined in:
lib/amazon-pricing/definitions/elasticache_node_type.rb

Instance Attribute Summary

Attributes inherited from InstanceType

#api_name, #compute_units, #disk_in_gb, #disk_type, #memory_in_mb, #name, #platform, #virtual_cores

Instance Method Summary collapse

Methods inherited from InstanceType

#category_types, disk_bytes_per_sec_capacity, #disk_in_mb, disk_ops_per_sec_capacity, #get_breakeven_month, #get_category_type, get_descriptive_cache_name, get_descriptive_name, #memory_in_gb, populate_lookups, #prepay, #price_per_hour, service_type

Constructor Details

#initialize(region, api_name, name) ⇒ ElastiCacheNodeType

Returns a new instance of ElastiCacheNodeType.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/amazon-pricing/definitions/elasticache_node_type.rb', line 6

def initialize(region, api_name, name)
  @category_types = {}
  
  @region   = region
  @name     = name
  @api_name = api_name

  api_name_for_lookup = api_name.sub("cache.", "")
  
  @memory_in_mb  = InstanceType.get_memory(api_name)
  @virtual_cores = InstanceType.get_virtual_cores(api_name_for_lookup)
end

Instance Method Details

#available?(cache_type = :memcached, type_of_instance = :ondemand) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/amazon-pricing/definitions/elasticache_node_type.rb', line 19

def available?(cache_type = :memcached, type_of_instance = :ondemand)
  cache = get_category_type(cache_type)
  return false if cache.nil?
  cache.available?(type_of_instance)
end

#update_pricing(cache_type, type_of_instance, json) ⇒ Object



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
# File 'lib/amazon-pricing/definitions/elasticache_node_type.rb', line 25

def update_pricing(cache_type, type_of_instance, json)
  cache = get_category_type(cache_type)
  if cache.nil?
    cache = Cache.new(self, cache_type)
    @category_types[cache_type] = cache
  end
  
  if type_of_instance == :ondemand
    values = ElastiCacheNodeType::get_values(json, cache_type)
    price = coerce_price(values[cache_type.to_s])
    cache.set_price_per_hour(type_of_instance, nil, price)
  else
    json['valueColumns'].each do |val|

      if val['prices']['USD'].empty?
        next
      end

      price = coerce_price(val['prices']['USD'])

      case val['name']
      when "yrTerm1", "yrTerm1Standard"
        cache.set_prepay(type_of_instance, :year1, price)
      when "yrTerm3", "yrTerm3Standard"
        cache.set_prepay(type_of_instance, :year3, price)
      when "yearTerm1Hourly"
        cache.set_price_per_hour(type_of_instance, :year1, price)
      when "yearTerm3Hourly"
        cache.set_price_per_hour(type_of_instance, :year3, price)
      else
        $stderr.puts "[#{__method__}] WARNING: unknown term:#{val["name"]}"
      end
    end
  end
end