class AwsPricing::RdsInstanceType

Public Class Methods

new(region, api_name, name) click to toggle source
   # File lib/amazon-pricing/definitions/rds-instance-type.rb
 6 def initialize(region, api_name, name)
 7   @category_types = {}
 8 
 9   @region = region
10   @name = name
11   @api_name = api_name
12 
13   # Let's look up using the standard name but need to remove leading "db." to do so
14   api_name_for_lookup = api_name.sub("db.", "")
15 
16   @disk_in_gb = InstanceType.get_disk(api_name_for_lookup)
17   @platform = InstanceType.get_platform(api_name_for_lookup)
18   @disk_type = InstanceType.get_disk_type(api_name_for_lookup)
19   @memory_in_mb = InstanceType.get_memory(api_name_for_lookup)
20   @compute_units = InstanceType.get_compute_units(api_name_for_lookup)
21   @virtual_cores = InstanceType.get_virtual_cores(api_name_for_lookup)
22 end

Protected Class Methods

get_name(instance_type, api_name, is_reserved = false) click to toggle source

Returns [api_name, name] e.g. memDBCurrentGen, db.m3.medium

    # File lib/amazon-pricing/definitions/rds-instance-type.rb
176 def self.get_name(instance_type, api_name, is_reserved = false)
177   # Temporary hack: Amazon has released r3 instances but pricing has api_name with asterisk (e.g. "r3.large *")
178   api_name.sub!(" *", "")
179 
180 
181   # Note: These api names are specific to RDS, not sure why Amazon has given them different API names (note: they have leading "db.")
182   #'cr1.8xl' => 'High-Memory Cluster Eight Extra Large',
183   #'micro' => 'Micro',
184   #'sm' => 'Standard Small',
185   #'xxlHiMem' => 'Hi-Memory Double Extra Large'
186   if ["db.cr1.8xl", "db.micro", "db.sm", "db.xxlHiMem", "sm", "micro", "xxlHiMem"].include? api_name
187     case api_name
188     when "db.cr1.8xl"
189       api_name = "db.cr1.8xlarge"
190     when "db.xxlHiMem", "xxlHiMem"
191       api_name = "db.m2.2xlarge"
192     when "db.micro", "micro"
193       api_name = "db.t1.micro"
194     when "db.sm", "sm"
195       api_name = "db.m1.small"
196     end
197   end
198 
199   # Let's look up using the standard name but need to remove leading "db." to do so
200   api_name_for_lookup = api_name.sub("db.", "")
201 
202   # Let's handle new instances more gracefully
203   unless @@Name_Lookup.has_key? api_name_for_lookup
204     raise UnknownTypeError, "Unknown instance type #{instance_type} #{api_name}", caller
205   end
206 
207   name = @@Name_Lookup[api_name_for_lookup]
208 
209   [api_name, name]
210 end

Public Instance Methods

available?(database_type = :mysql, type_of_instance = :ondemand, is_multi_az, is_byol) click to toggle source

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

   # File lib/amazon-pricing/definitions/rds-instance-type.rb
28 def available?(database_type = :mysql, type_of_instance = :ondemand, is_multi_az, is_byol)
29   db = get_category_type(database_type, is_multi_az, is_byol)
30   return false if db.nil?
31   db.available?(type_of_instance)
32 end
update_pricing(database_type, type_of_instance, json, is_multi_az, is_byol) click to toggle source
   # File lib/amazon-pricing/definitions/rds-instance-type.rb
34 def update_pricing(database_type, type_of_instance, json, is_multi_az, is_byol)
35   db = get_category_type(database_type, is_multi_az, is_byol)
36   if db.nil?
37     db = DatabaseType.new(self, database_type)        
38 
39     if is_multi_az == true and is_byol == true
40       @category_types["#{database_type}_byol_multiaz"] = db
41     elsif is_multi_az == true and is_byol == false
42       @category_types["#{database_type}_multiaz"] = db
43     elsif is_multi_az == false and is_byol == true
44       @category_types["#{database_type}_byol"] = db
45     else
46       @category_types[database_type] = db
47     end    
48 
49   end
50 
51   if type_of_instance == :ondemand
52     values = RdsInstanceType::get_values(json, database_type)
53     price = coerce_price(values[database_type.to_s])
54     db.set_price_per_hour(type_of_instance, nil, price)
55   else
56     # 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).
57     # Just warn and continue.
58     if db.ondemand_price_per_hour.nil?
59       $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"
60       return
61     end
62 
63     json['valueColumns'].each do |val|
64       # As of 2014-04-02 we see entries w/o pricing, e.g. sqlserver_web heavy 1 year reservation = {"prices"=>{"USD"=>{}}, "name"=>"yrTerm1"}
65       if val['prices']['USD'].empty?
66         #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}"
67         next
68       end
69 
70       price = coerce_price(val['prices']['USD'])
71 
72       case val["name"]
73       when "yrTerm1", "yrTerm1Standard"
74         db.set_prepay(type_of_instance, :year1, price)
75       when "yrTerm3", "yrTerm3Standard"
76         db.set_prepay(type_of_instance, :year3, price)
77       when "yrTerm1Hourly"
78         db.set_price_per_hour(type_of_instance, :year1, price)
79       when "yrTerm3Hourly"
80         db.set_price_per_hour(type_of_instance, :year3, price)
81       when "yearTerm1Hourly"
82         db.set_price_per_hour(type_of_instance, :year1, price)
83       when "yearTerm3Hourly"
84         db.set_price_per_hour(type_of_instance, :year3, price)
85       else
86         $stderr.puts "[#{__method__}] WARNING: unknown term:#{val["name"]}"
87       end
88     end
89   end
90   # Copy byol prices from oracle_se to oracle_{ee,se1,se2}
91   if database_type == :oracle_se && is_byol
92     update_pricing :oracle_ee,  type_of_instance, json, is_multi_az, is_byol
93     update_pricing :oracle_se1, type_of_instance, json, is_multi_az, is_byol
94     update_pricing :oracle_se2, type_of_instance, json, is_multi_az, is_byol
95   end
96 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) click to toggle source
    # File lib/amazon-pricing/definitions/rds-instance-type.rb
147 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)
148   db = get_category_type(database_type, is_multi_az, is_byol)
149   if db.nil?
150     db = DatabaseType.new(self, database_type)        
151     
152     if is_multi_az == true and is_byol == true
153       @category_types["#{database_type}_byol_multiaz"] = db
154     elsif is_multi_az == true and is_byol == false
155       @category_types["#{database_type}_multiaz"] = db
156     elsif is_multi_az == false and is_byol == true
157       @category_types["#{database_type}_byol"] = db
158     else
159       @category_types[database_type] = db
160     end    
161 
162   end
163 
164   db.set_price_per_hour(type_of_instance, nil, coerce_price(ondemand_pph)) unless ondemand_pph.nil?
165   db.set_prepay(type_of_instance, :year1, coerce_price(year1_prepay)) unless year1_prepay.nil?
166   db.set_prepay(type_of_instance, :year3, coerce_price(year3_prepay)) unless year3_prepay.nil?
167   db.set_price_per_hour(type_of_instance, :year1, coerce_price(year1_pph)) unless year1_pph.nil?
168   db.set_price_per_hour(type_of_instance, :year3, coerce_price(year3_pph)) unless year3_pph.nil?
169 end
update_pricing_new(database_type, type_of_instance, prices, term = nil, is_multi_az, is_byol) click to toggle source
    # File lib/amazon-pricing/definitions/rds-instance-type.rb
 98 def update_pricing_new(database_type, type_of_instance, prices, term = nil, is_multi_az, is_byol)
 99   db = get_category_type(database_type, is_multi_az, is_byol)
100   if db.nil?
101     db = DatabaseType.new(self, database_type)
102 
103     if is_multi_az == true and is_byol == true
104       @category_types["#{database_type}_byol_multiaz"] = db
105     elsif is_multi_az == true and is_byol == false
106       @category_types["#{database_type}_multiaz"] = db
107     elsif is_multi_az == false and is_byol == true
108       @category_types["#{database_type}_byol"] = db
109     else
110       @category_types[database_type] = db
111     end
112 
113   end
114 
115   terms_to_years = {
116       "yrTerm1" => :year1,
117       "yrTerm3" => :year3,
118       "yrTerm1Standard" => :year1,
119       "yrTerm3Standard" => :year3
120   }
121   years = terms_to_years[term]
122   if years.nil?
123     $stderr.puts "[#{__method__}] WARNING: unknown term:#{val["name"]}"
124   end
125 
126   prices.each do |price|
127     p = coerce_price(price['prices']['USD'])
128     case price['name']
129       when 'upfront'
130         db.set_prepay(type_of_instance, years, p.to_f) unless type_of_instance == :noupfront || p == "N/A"
131       when 'monthlyStar'
132         # note for partialupfront, this purposely differs from AWS' "effective hourly" since we do not
133         # include the amortization of the partialupfront cost into this rate.
134         db.set_price_per_hour(type_of_instance, years, p.to_f * 12 / 365 / 24) unless type_of_instance == :allupfront || p == "N/A"
135       else
136         # Do nothing for other names
137     end
138   end
139   # Copy byol prices from oracle_se to oracle_{ee,se1,se2}
140   if database_type == :oracle_se && is_byol
141     update_pricing_new :oracle_ee,  type_of_instance, prices, term, is_multi_az, is_byol
142     update_pricing_new :oracle_se1, type_of_instance, prices, term, is_multi_az, is_byol
143     update_pricing_new :oracle_se2, type_of_instance, prices, term, is_multi_az, is_byol
144   end
145 end