Class: AWSCosts::EC2ReservedInstances

Inherits:
Object
  • Object
show all
Defined in:
lib/awscosts/ec2_reserved_instances.rb

Constant Summary collapse

TERMS =
{ one_year: 'yrTerm1', three_year: 'yrTerm3' }
TYPE_TRANSLATION =
{ 'stdResI.sm' => 'm1.small',
'stdResI.med' => 'm1.medium',
'stdResI.lg' => 'm1.large',
'stdResI.xl' => 'm1.xlarge',
'secgenstdResI.xl' => 'm3.xlarge',
'secgenstdResI.xxl' => 'm3.2xlarge',
'uResI.u' => 't1.micro',
'hiMemResI.xl' => 'm2.xlarge',
'hiMemResI.xxl' => 'm2.2xlarge',
'hiMemResI.xxxxl' => 'm2.4xlarge',
'hiCPUResI.med' => 'c1.medium',
'hiCPUResI.xl' => 'c1.xlarge',
'clusterComputeI.xxxxl' => 'cc1.4xlarge',
'clusterComputeI.xxxxxxxxl' => 'cc2.8xlarge',
'clusterGPUI.xxxxl' => 'cg1.4xlarge',
'clusterHiMemResI.xxxxxxxxl' => 'cr1.8xlarge',
'hiStoreResI.xxxxxxxxl' => 'hs1.8xlarge',
'hiIoResI.xxxxl' => 'hi1.4xlarge' }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ EC2ReservedInstances

Returns a new instance of EC2ReservedInstances.



24
25
26
# File 'lib/awscosts/ec2_reserved_instances.rb', line 24

def initialize data
  @data= data
end

Class Method Details

.fetch(type, utilisation, region) ⇒ Object



44
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
# File 'lib/awscosts/ec2_reserved_instances.rb', line 44

def self.fetch type, utilisation, region
  transformed = AWSCosts::Cache.get_jsonp("/pricing/1/ec2/#{type}-ri-#{utilisation}.min.js") do |data|
    result = {}
    data['config']['regions'].each do |r|
      platforms = {}
      r['instanceTypes'].each do |instance_type|
        instance_type['sizes'].each do |instance_size|
          size = instance_size['size']
          platform_cost = Hash.new({})

          instance_size['valueColumns'].each do |value|
            # Don't return 0.0 for "N/A" since that is misleading
            platform_cost[value['name']] = value['prices']['USD'] == 'N/A' ? nil : value['prices']['USD'].to_f
          end

          platform_cost.each_pair do |p,v|
            platforms[p] = {} unless platforms.key?(p)
            platforms[p][size] = v
          end
        end
      end
      result[r['region']] = platforms
    end
    result
  end
  self.new(transformed[region])
end

Instance Method Details

#hourly(term, size = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/awscosts/ec2_reserved_instances.rb', line 36

def hourly term, size=nil
  if size
    @data["#{TERMS[term]}Hourly"][size]
  else
    @data["#{TERMS[term]}Hourly"]
  end
end

#upfront(term, size = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/awscosts/ec2_reserved_instances.rb', line 28

def upfront term, size=nil
  if size
    @data[TERMS[term]][size]
  else
    @data[TERMS[term]]
  end
end