class Ec2spec::OfferFile
Constants
- OFFER_FILE_NAME
Public Instance Methods
memory(instance_type)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
products()
click to toggle source
# File lib/ec2spec/offer_file.rb, line 21 def products offer_file_json['products'] end
vcpu(instance_type)
click to toggle source
# 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
Private Instance Methods
download()
click to toggle source
# File lib/ec2spec/offer_file.rb, line 47 def download http_conn = Faraday.new do |builder| builder.adapter Faraday.default_adapter end offer_file_url = OfferIndexFile.instance.offer_file_url(@region) response = http_conn.get(offer_file_url) File.open(offer_file_path, 'wb') { |fp| fp.write(response.body) } end
offer_file_json()
click to toggle source
# File lib/ec2spec/offer_file.rb, line 63 def offer_file_json @offer_file_json ||= JSON.parse(File.open(offer_file_path).read) end
offer_file_path()
click to toggle source
# File lib/ec2spec/offer_file.rb, line 57 def offer_file_path price_list_dir = File.join(ENV['HOME'], Const::PROJECT_DIR) Dir.mkdir(price_list_dir) unless Dir.exist?(price_list_dir) File.join(price_list_dir, OFFER_FILE_NAME) end
product?(product, instance_type)
click to toggle source
# File lib/ec2spec/offer_file.rb, line 74 def product?(product, instance_type) attributes = product[1]['attributes'] attributes['instanceType'] == instance_type && attributes['operatingSystem'] == 'Linux' && attributes['preInstalledSw'] == 'NA' end
sku(instance_type)
click to toggle source
# File lib/ec2spec/offer_file.rb, line 67 def sku(instance_type) target_product = products.find do |product| product?(product, instance_type) end target_product[1]['sku'] end