Class: AwsPricing::Ec2InstanceType

Inherits:
InstanceType show all
Defined in:
lib/amazon-pricing/definitions/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

Class Method Summary collapse

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, #initialize, #memory_in_gb, populate_lookups, #prepay, #price_per_hour, service_type

Constructor Details

This class inherits a constructor from AwsPricing::InstanceType

Class Method Details

.get_network_information(network_string) ⇒ Object

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



124
125
126
127
128
129
130
131
# File 'lib/amazon-pricing/definitions/ec2-instance-type.rb', line 124

def self.get_network_information(network_string)
  throughput = @Network_String_To_Sym[network_string]
  if throughput.nil?
      $stderr.puts "[#{__method__}] WARNING: unknown network throughput string:#{network_string}"
  end
  network_mbps = @Network_Throughput_MBits_Per_Second[throughput]
  [throughput.to_s, network_mbps]
end

.get_network_mbps(throughput) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/amazon-pricing/definitions/ec2-instance-type.rb', line 113

def self.get_network_mbps(throughput)
  network_mbps = @Network_Throughput_MBits_Per_Second[throughput]
  if not network_mbps
    $stderr.puts "Unknown network throughput for #{throughput}"
  end
  network_mbps
end

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

Returns:

  • (Boolean)


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

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



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

def get_operating_system(type)
  get_category_type(type)
end

#operating_systemsObject

Maintained for backward compatibility reasons



109
110
111
# File 'lib/amazon-pricing/definitions/ec2-instance-type.rb', line 109

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



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
88
89
90
91
# File 'lib/amazon-pricing/definitions/ec2-instance-type.rb', line 58

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", "yrTerm1Standard"
        os.set_prepay(type_of_instance, :year1, price)
      when "yrTerm3", "yrTerm3Standard"
        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)
      else
        $stderr.puts "[#{__method__}] WARNING: unknown term:#{val["name"]}"
      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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/amazon-pricing/definitions/ec2-instance-type.rb', line 93

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



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

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

  p = coerce_price(price)

  if type_of_instance == :ondemand
    os.set_price_per_hour(type_of_instance, nil, p)
  else
    case term
      when "yrTerm1", "yrTerm1Standard"
        years = :year1
      when "yrTerm1Convertible"
        years = :year1_convertible
      when "yrTerm3", "yrTerm3Standard"
        years = :year3
      when "yrTerm3Convertible"
        years = :year3_convertible
      else
        $stderr.puts "[#{__method__}] WARNING: unknown term:#{term} os:#{operating_system},type:#{type_of_instance},prepay:#{is_prepay}"
    end
    if is_prepay
      os.set_prepay(type_of_instance, years, p)
    else
      os.set_price_per_hour(type_of_instance, years, p * 12 / 365 / 24)
    end
  end
end