Class: AwsPricing::RdsInstanceType

Inherits:
InstanceType show all
Defined in:
lib/amazon-pricing/rds-instance-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_in_mb, #get_breakeven_month, #get_category_type, #memory_in_gb, populate_lookups, #prepay, #price_per_hour, service_type

Constructor Details

#initialize(region, api_name, name) ⇒ RdsInstanceType


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/amazon-pricing/rds-instance-type.rb', line 5

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

  @region = region
  @name = name
  @api_name = api_name

  # Let's look up using the standard name but need to remove leading "db." to do so
  api_name_for_lookup = api_name.sub("db.", "")

  @disk_in_gb = InstanceType.get_disk(api_name_for_lookup)
  @platform = InstanceType.get_platform(api_name_for_lookup)
  @disk_type = InstanceType.get_disk_type(api_name_for_lookup)
  @memory_in_mb = InstanceType.get_memory(api_name_for_lookup)
  @compute_units = InstanceType.get_compute_units(api_name_for_lookup)
  @virtual_cores = InstanceType.get_virtual_cores(api_name_for_lookup)
end

Instance Method Details

#available?(database_type = :mysql, type_of_instance = :ondemand, is_multi_az, is_byol) ⇒ Boolean

database_type = :mysql, :oracle, :sqlserver type_of_instance = :ondemand, :light, :medium, :heavy


27
28
29
30
31
# File 'lib/amazon-pricing/rds-instance-type.rb', line 27

def available?(database_type = :mysql, type_of_instance = :ondemand, is_multi_az, is_byol)
  db = get_category_type(database_type, is_multi_az, is_byol)
  return false if db.nil?
  db.available?(type_of_instance)
end

#update_pricing(database_type, type_of_instance, json, is_multi_az, is_byol) ⇒ Object


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
# File 'lib/amazon-pricing/rds-instance-type.rb', line 33

def update_pricing(database_type, type_of_instance, json, is_multi_az, is_byol)
  db = get_category_type(database_type, is_multi_az, is_byol)
  if db.nil?
    db = DatabaseType.new(self, database_type)        

    if is_multi_az == true and is_byol == true
      @category_types["#{database_type}_byol_multiaz"] = db
    elsif is_multi_az == true and is_byol == false
      @category_types["#{database_type}_multiaz"] = db
    elsif is_multi_az == false and is_byol == true
      @category_types["#{database_type}_byol"] = db
    else
      @category_types[database_type] = db
    end    

  end

  if type_of_instance == :ondemand
    values = RdsInstanceType::get_values(json, database_type)
    price = coerce_price(values[database_type.to_s])
    db.set_price_per_hour(type_of_instance, nil, price)
  else
    # Amazon has another data error where they are still exposing reserved instance types when they do not actually exist (e.g. SQL Server t1.micro). 
    # Just warn and continue.
    if db.ondemand_price_per_hour.nil?
      $stderr.puts "WARNING: Skipping RDS instance type #{api_name}:#{database_type}:#{type_of_instance}:#{is_multi_az}:#{is_byol} due to lack of on-demand pricing"
      return
    end

    json['valueColumns'].each do |val|
      # As of 2014-04-02 we see entries w/o pricing, e.g. sqlserver_web heavy 1 year reservation = {"prices"=>{"USD"=>{}}, "name"=>"yrTerm1"}
      if val['prices']['USD'].empty?
        #puts "The following instance type does not have pricing: #{@region.name} : #{@api_name} : #{database_type} : #{type_of_instance} : #{val['name']} : #{is_multi_az} : #{is_byol}"
        next
      end

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

      case val["name"]
      when "yrTerm1"
        db.set_prepay(type_of_instance, :year1, price)
      when "yrTerm3"
        db.set_prepay(type_of_instance, :year3, price)
      when "yrTerm1Hourly"
        db.set_price_per_hour(type_of_instance, :year1, price)
      when "yrTerm3Hourly"
        db.set_price_per_hour(type_of_instance, :year3, price)
      when "yearTerm1Hourly"
        db.set_price_per_hour(type_of_instance, :year1, price)
      when "yearTerm3Hourly"
        db.set_price_per_hour(type_of_instance, :year3, price)  
      end
    end
  end
end

#update_pricing2(database_type, type_of_instance, is_multi_az, is_byol, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil) ⇒ Object


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/amazon-pricing/rds-instance-type.rb', line 89

def update_pricing2(database_type, type_of_instance, is_multi_az, is_byol, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil)
  db = get_category_type(database_type, is_multi_az, is_byol)
  if db.nil?
    db = DatabaseType.new(self, database_type)        
    
    if is_multi_az == true and is_byol == true
      @category_types["#{database_type}_byol_multiaz"] = db
    elsif is_multi_az == true and is_byol == false
      @category_types["#{database_type}_multiaz"] = db
    elsif is_multi_az == false and is_byol == true
      @category_types["#{database_type}_byol"] = db
    else
      @category_types[database_type] = db
    end    

  end

  db.set_price_per_hour(type_of_instance, nil, coerce_price(ondemand_pph)) unless ondemand_pph.nil?
  db.set_prepay(type_of_instance, :year1, coerce_price(year1_prepay)) unless year1_prepay.nil?
  db.set_prepay(type_of_instance, :year3, coerce_price(year3_prepay)) unless year3_prepay.nil?
  db.set_price_per_hour(type_of_instance, :year1, coerce_price(year1_pph)) unless year1_pph.nil?
  db.set_price_per_hour(type_of_instance, :year3, coerce_price(year3_pph)) unless year3_pph.nil?
end