Class: AwsPricing::Ec2InstanceType

Inherits:
InstanceType show all
Defined in:
lib/amazon-pricing/ec2-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, #initialize, #memory_in_gb, populate_lookups, #prepay, #price_per_hour, service_type

Constructor Details

This class inherits a constructor from AwsPricing::InstanceType

Instance Method Details

#available?(type_of_instance = :ondemand, operating_system = :linux) ⇒ Boolean

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


14
15
16
17
18
# File 'lib/amazon-pricing/ec2-instance-type.rb', line 14

def available?(type_of_instance = :ondemand, operating_system = :linux)
  os = get_category_type(operating_system)
  return false if os.nil?
  os.available?(type_of_instance)
end

#get_operating_system(type) ⇒ Object

Returns OperatingSystem pricing e.g. :linux


7
8
9
# File 'lib/amazon-pricing/ec2-instance-type.rb', line 7

def get_operating_system(type)
  get_category_type(type)
end

#operating_systemsObject

Maintained for backward compatibility reasons


94
95
96
# File 'lib/amazon-pricing/ec2-instance-type.rb', line 94

def operating_systems
  @category_types
end

#update_pricing(operating_system, type_of_instance, json) ⇒ Object

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


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

def update_pricing(operating_system, type_of_instance, json)
  os = get_category_type(operating_system)
  if os.nil?
    os = OperatingSystem.new(self, operating_system)
    @category_types[operating_system] = os
  end

  if type_of_instance == :ondemand
    # e.g. {"size"=>"sm", "valueColumns"=>[{"name"=>"linux", "prices"=>{"USD"=>"0.060"}}]}
    values = Ec2InstanceType::get_values(json, operating_system, true)
    category = operating_system.to_s
    # 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
    category = "os" if values.has_key?("os")
    price = coerce_price(values[category])
    os.set_price_per_hour(type_of_instance, nil, price)
  else
    json['valueColumns'].each do |val|
      price = coerce_price(val['prices']['USD'])

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

#update_pricing2(operating_system, res_type, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/amazon-pricing/ec2-instance-type.rb', line 78

def update_pricing2(operating_system, res_type, ondemand_pph = nil, year1_prepay = nil, year3_prepay = nil, year1_pph = nil, year3_pph = nil)

  os = get_category_type(operating_system)
  if os.nil?
    os = OperatingSystem.new(self, operating_system)
    @category_types[operating_system] = os
  end

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

#update_pricing_new(operating_system, type_of_instance, price, term = nil, is_prepay = false) ⇒ Object

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


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/amazon-pricing/ec2-instance-type.rb', line 23

def update_pricing_new(operating_system, type_of_instance, price, term = nil, is_prepay = false)
  os = get_category_type(operating_system)
  if os.nil?
    os = OperatingSystem.new(self, operating_system)
    @category_types[operating_system] = os
  end

  if type_of_instance == :ondemand
    os.set_price_per_hour(type_of_instance, nil, price)
  else
    years = :year1 if term == "yrTerm1"
    years = :year3 if term == "yrTerm3"
    if is_prepay
      os.set_prepay(type_of_instance, years, price)
    else
      os.set_price_per_hour(type_of_instance, years, price)
    end
  end
end