Class: EC2Spot

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



8
9
10
# File 'lib/ec2spot.rb', line 8

def self.instance
  @instance ||= new
end

.instance!Object



12
13
14
# File 'lib/ec2spot.rb', line 12

def self.instance!
  @instance = new
end

Instance Method Details

#prices(*instance_types) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ec2spot.rb', line 16

def prices(*instance_types)
  json = spot_price_history(*instance_types).group_by(&:instance_type).map do |instance_type, spot_price_history|
    prices = spot_price_history.map(&:spot_price).map(&:to_f)
      {
        instance: instance_type,
        min: prices.min,
        max: prices.max,
        avg: prices.sum / prices.length,
        full: instance_price(instance_type),
        savings: (1 - (prices.sum / prices.length) / instance_price(instance_type)),
        interrupts: spot_advisor_range(instance_type)
      }
  end
end