Class: AwsPricing::InstanceType

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-pricing/instance-type.rb

Overview

InstanceType is a specific type of instance in a region with a defined price per hour. The price will vary by platform (Linux, Windows).

e.g. m1.large instance in US-East region will cost $0.34/hour for Linux and $0.48/hour for Windows.

Direct Known Subclasses

Ec2InstanceType, RdsInstanceType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, api_name, name) ⇒ InstanceType

Returns a new instance of InstanceType


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

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

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

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

Instance Attribute Details

#api_nameObject

Returns the value of attribute api_name


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def api_name
  @api_name
end

#compute_unitsObject

Returns the value of attribute compute_units


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def compute_units
  @compute_units
end

#disk_in_gbObject

Returns the value of attribute disk_in_gb


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def disk_in_gb
  @disk_in_gb
end

#disk_typeObject

Returns the value of attribute disk_type


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def disk_type
  @disk_type
end

#memory_in_mbObject

Returns the value of attribute memory_in_mb


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def memory_in_mb
  @memory_in_mb
end

#nameObject

Returns the value of attribute name


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def name
  @name
end

#platformObject

Returns the value of attribute platform


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def platform
  @platform
end

#virtual_coresObject

Returns the value of attribute virtual_cores


22
23
24
# File 'lib/amazon-pricing/instance-type.rb', line 22

def virtual_cores
  @virtual_cores
end

Class Method Details

.populate_lookupsObject


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/amazon-pricing/instance-type.rb', line 94

def self.populate_lookups
  # We use Linux on-demand to populate the lookup tables with the basic lookup information
  ["http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js", "http://a0.awsstatic.com/pricing/1/ec2/previous-generation/linux-od.min.js"].each do |url|
    res = AwsPricing::PriceList.fetch_url(url)

    res['config']['regions'].each do |reg|
      reg['instanceTypes'].each do |type|
        items = type['sizes']
        items = [type] if items.nil?
        items.each do |size|
          begin
            api_name = size["size"]
            @@Memory_Lookup[api_name] = size["memoryGiB"].to_f * 1000
            @@Compute_Units_Lookup[api_name] = size["ECU"].to_i 
            @@Virtual_Cores_Lookup[api_name] = size["vCPU"].to_i 
          rescue UnknownTypeError
            $stderr.puts "WARNING: encountered #{$!.message}"
          end
        end
      end
    end
  end
end

.service_type(category) ⇒ Object


85
86
87
88
89
90
91
92
# File 'lib/amazon-pricing/instance-type.rb', line 85

def self.service_type(category)
  case category
    when 'os'; 'ec2'
    when 'db'; 'rds'
    else
      ''
  end
end

Instance Method Details

#category_typesObject


48
49
50
# File 'lib/amazon-pricing/instance-type.rb', line 48

def category_types
  @category_types.values
end

#disk_in_mbObject

Keep this in for backwards compatibility within current major version of gem


40
41
42
# File 'lib/amazon-pricing/instance-type.rb', line 40

def disk_in_mb
  @disk_in_gb * 1000
end

#get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil


80
81
82
83
# File 'lib/amazon-pricing/instance-type.rb', line 80

def get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false)
  cat = get_category_type(category_types, is_multi_az, isByol)
  cat.get_breakeven_month(type_of_instance, term) unless cat.nil?
end

#get_category_type(name, multi_az = false, byol = false) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/amazon-pricing/instance-type.rb', line 52

def get_category_type(name, multi_az = false, byol = false)
  if multi_az == true and byol == true
    db = @category_types["#{name}_byol_multiaz"]
  elsif multi_az == true and byol == false
    db = @category_types["#{name}_multiaz"]
  elsif multi_az == false and byol == true
    db = @category_types["#{name}_byol"]
  else
    db = @category_types[name]
  end
end

#memory_in_gbObject


44
45
46
# File 'lib/amazon-pricing/instance-type.rb', line 44

def memory_in_gb
  @memory_in_mb / 1000
end

#prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil


73
74
75
76
# File 'lib/amazon-pricing/instance-type.rb', line 73

def prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
  cat = get_category_type(category_type, is_multi_az, isByol)
  cat.prepay(type_of_instance, term) unless cat.nil?      
end

#price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil


66
67
68
69
# File 'lib/amazon-pricing/instance-type.rb', line 66

def price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
  cat = get_category_type(category_type, is_multi_az, isByol)
  cat.price_per_hour(type_of_instance, term) unless cat.nil?      
end