class AwsPricing::Ec2InstanceType

Public Class Methods

get_network_information(network_string) click to toggle source

Take in string from amazon pricing api, return network properties Input: String containing network capacity from amazon-pricing-api Output: network throughput as a string, int containing network mbps

    # File lib/amazon-pricing/definitions/ec2-instance-type.rb
124 def self.get_network_information(network_string)
125   throughput = @Network_String_To_Sym[network_string]
126   if throughput.nil?
127       $stderr.puts "[#{__method__}] WARNING: unknown network throughput string:#{network_string}"
128   end
129   network_mbps = @Network_Throughput_MBits_Per_Second[throughput]
130   [throughput.to_s, network_mbps]
131 end
get_network_mbps(throughput) click to toggle source
    # File lib/amazon-pricing/definitions/ec2-instance-type.rb
113 def self.get_network_mbps(throughput)
114   network_mbps = @Network_Throughput_MBits_Per_Second[throughput]
115   if not network_mbps
116     $stderr.puts "Unknown network throughput for #{throughput}"
117   end
118   network_mbps
119 end

Protected Class Methods

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

Returns [api_name, name]

    # File lib/amazon-pricing/definitions/ec2-instance-type.rb
135 def self.get_name(instance_type, api_name, is_reserved = false)
136   # Temporary hack: Amazon has released r3 instances but pricing has api_name with asterisk (e.g. "r3.large *")
137   api_name.sub!(" *", "")
138 
139   # Let's handle new instances more gracefully
140   unless @@Name_Lookup.has_key? api_name
141     raise UnknownTypeError, "Unknown instance type #{instance_type} #{api_name}", caller
142   end
143 
144   name = @@Name_Lookup[api_name]
145 
146   [api_name, name]
147 end

Public Instance Methods

available?(type_of_instance = :ondemand, operating_system = :linux) click to toggle source

Returns whether an instance_type is available. operating_system = :linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb type_of_instance = :ondemand, :light, :medium, :heavy

   # File lib/amazon-pricing/definitions/ec2-instance-type.rb
15 def available?(type_of_instance = :ondemand, operating_system = :linux)
16   os = get_category_type(operating_system)
17   return false if os.nil?
18   os.available?(type_of_instance)
19 end
get_operating_system(type) click to toggle source

Returns OperatingSystem pricing e.g. :linux

   # File lib/amazon-pricing/definitions/ec2-instance-type.rb
 8 def get_operating_system(type)
 9   get_category_type(type)
10 end
operating_systems() click to toggle source

Maintained for backward compatibility reasons

    # File lib/amazon-pricing/definitions/ec2-instance-type.rb
109 def operating_systems
110   @category_types
111 end
update_pricing(operating_system, type_of_instance, json) click to toggle source

operating_system = :linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb type_of_instance = :ondemand, :light, :medium, :heavy

   # File lib/amazon-pricing/definitions/ec2-instance-type.rb
58 def update_pricing(operating_system, type_of_instance, json)
59   os = get_category_type(operating_system)
60   if os.nil?
61     os = OperatingSystem.new(self, operating_system)
62     @category_types[operating_system] = os
63   end
64 
65   if type_of_instance == :ondemand
66     # e.g. {"size"=>"sm", "valueColumns"=>[{"name"=>"linux", "prices"=>{"USD"=>"0.060"}}]}
67     values = Ec2InstanceType::get_values(json, operating_system, true)
68     category = operating_system.to_s
69     # Someone at AWS is fat fingering the pricing data and putting the text "os" where there should be the actual operating system (e.g. "linux") - see http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js
70     category = "os" if values.has_key?("os")
71     price = coerce_price(values[category])
72     os.set_price_per_hour(type_of_instance, nil, price)
73   else
74     json['valueColumns'].each do |val|
75       price = coerce_price(val['prices']['USD'])
76 
77       case val["name"]
78       when "yrTerm1", "yrTerm1Standard"
79         os.set_prepay(type_of_instance, :year1, price)
80       when "yrTerm3", "yrTerm3Standard"
81         os.set_prepay(type_of_instance, :year3, price)
82       when "yrTerm1Hourly"
83         os.set_price_per_hour(type_of_instance, :year1, price)
84       when "yrTerm3Hourly"
85         os.set_price_per_hour(type_of_instance, :year3, price)
86       else
87         $stderr.puts "[#{__method__}] WARNING: unknown term:#{val["name"]}"
88       end
89     end
90   end
91 end
update_pricing2(operating_system, res_type, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil) click to toggle source
    # File lib/amazon-pricing/definitions/ec2-instance-type.rb
 93 def update_pricing2(operating_system, res_type, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil)
 94 
 95   os = get_category_type(operating_system)
 96   if os.nil?
 97     os = OperatingSystem.new(self, operating_system)
 98     @category_types[operating_system] = os
 99   end
100 
101   os.set_price_per_hour(res_type, nil, coerce_price(ondemand_pph)) unless ondemand_pph.nil?
102   os.set_prepay(res_type, :year1, coerce_price(year1_prepay)) unless year1_prepay.nil?
103   os.set_prepay(res_type, :year3, coerce_price(year3_prepay)) unless year3_prepay.nil?
104   os.set_price_per_hour(res_type, :year1, coerce_price(year1_pph)) unless year1_pph.nil?
105   os.set_price_per_hour(res_type, :year3, coerce_price(year3_pph)) unless year3_pph.nil?
106 end
update_pricing_new(operating_system, type_of_instance, price, term = nil, is_prepay = false) click to toggle source

operating_system = :linux, :mswin, :rhel, :sles, :mswinSQL, :mswinSQLWeb type_of_instance = :ondemand, :light, :medium, :heavy, :allupfront, partialupfront, :noupfront term = nil (on demand), yrTerm1, yrTerm3

   # File lib/amazon-pricing/definitions/ec2-instance-type.rb
24 def update_pricing_new(operating_system, type_of_instance, price, term = nil, is_prepay = false)
25   os = get_category_type(operating_system)
26   if os.nil?
27     os = OperatingSystem.new(self, operating_system)
28     @category_types[operating_system] = os
29   end
30 
31   p = coerce_price(price)
32 
33   if type_of_instance == :ondemand
34     os.set_price_per_hour(type_of_instance, nil, p)
35   else
36     case term
37       when "yrTerm1", "yrTerm1Standard"
38         years = :year1
39       when "yrTerm1Convertible"
40         years = :year1_convertible
41       when "yrTerm3", "yrTerm3Standard"
42         years = :year3
43       when "yrTerm3Convertible"
44         years = :year3_convertible
45       else
46         $stderr.puts "[#{__method__}] WARNING: unknown term:#{term} os:#{operating_system},type:#{type_of_instance},prepay:#{is_prepay}"
47     end
48     if is_prepay
49       os.set_prepay(type_of_instance, years, p)
50     else
51       os.set_price_per_hour(type_of_instance, years, p * 12 / 365 / 24)
52     end
53   end
54 end