From 09dfd8ee5e11f4fbe35afa7c573323264895a2bf Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 5 May 2016 12:48:58 +0200 Subject: [PATCH] Feature #4256: script that generates the instance types yaml --- share/ec2/get-instance-types.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 share/ec2/get-instance-types.rb diff --git a/share/ec2/get-instance-types.rb b/share/ec2/get-instance-types.rb new file mode 100755 index 0000000000..c8273d0106 --- /dev/null +++ b/share/ec2/get-instance-types.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require 'json' +require 'pp' +require 'yaml' +require 'open-uri' + +puts "Very slow script... hold on tight for a couple of minutes..." +puts + +content = open('https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json').read +content = JSON.parse(content) + +types = {} +content["products"].each do |k,v| + instanceType = v["attributes"]["instanceType"] + memory = v["attributes"]["memory"].split[0] rescue nil + cpu = v["attributes"]["vcpu"] + + if types[instanceType].nil? && instanceType && memory && cpu + types[instanceType] = {"cpu" => cpu, "memory" => memory} + end +end + +puts ({"instance_types" => types.sort.to_h}).to_yaml(:indentation=>4)