Class: Ec2spec::OfferFile

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ec2spec/offer_file.rb

Constant Summary collapse

OFFER_FILE_NAME =
'price_list.json'

Instance Method Summary collapse

Instance Method Details

#memory(instance_type) ⇒ Object



31
32
33
34
35
# File 'lib/ec2spec/offer_file.rb', line 31

def memory(instance_type)
  sku_instance_type = sku(instance_type)
  product = products[sku_instance_type]['attributes']
  product['memory']
end

#prepare(region) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ec2spec/offer_file.rb', line 9

def prepare(region)
  @region = region

  if File.exist?(offer_file_path)
    Ec2spec.logger.debug('Read from cached offer file')
  else
    Ec2spec.logger.info('Downloading: offer file')
    download
    Ec2spec.logger.info("Downloaded: offer file (#{offer_file_path})")
  end
end

#price_per_unit(instance_type) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ec2spec/offer_file.rb', line 37

def price_per_unit(instance_type)
  sku_instance_type = sku(instance_type)
  on_demand = offer_file_json['terms']['OnDemand']
  sku_value = on_demand[sku_instance_type].first[1]
  price_dimensions = sku_value['priceDimensions']
  price_dimensions.first[1]['pricePerUnit']['USD'].to_f
end

#productsObject



21
22
23
# File 'lib/ec2spec/offer_file.rb', line 21

def products
  offer_file_json['products']
end

#vcpu(instance_type) ⇒ Object



25
26
27
28
29
# File 'lib/ec2spec/offer_file.rb', line 25

def vcpu(instance_type)
  sku_instance_type = sku(instance_type)
  product = products[sku_instance_type]['attributes']
  product['vcpu']
end