From 7fb5862f8590c71522d5001405f9d4744456b4c0 Mon Sep 17 00:00:00 2001 From: Anton Chuchkalov Date: Tue, 15 Mar 2016 16:56:58 +0200 Subject: [PATCH] CID-471: add mappings for ephemeral storages --- devops-service/providers/ec2.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/devops-service/providers/ec2.rb b/devops-service/providers/ec2.rb index 3a83a98..e122c1b 100644 --- a/devops-service/providers/ec2.rb +++ b/devops-service/providers/ec2.rb @@ -101,7 +101,8 @@ module Provider # "Placement.AvailabilityZone" => s.options[:availability_zone], "KeyName" => self.ssh_key, "PrivateIpAddress" => s.private_ip, - "EbsOptimized" => ebs_optimized?(flavor) + "EbsOptimized" => ebs_optimized?(flavor), + "BlockDeviceMapping" => ephemeral_storages_mappings(flavor) } vpcId = nil unless subnets.empty? @@ -413,9 +414,28 @@ module Provider end end - def ebs_optimized?(instance_type) + # When you create an instance with one of these flavors within AWS console, + # EbsOptimized is automatically set to true. But in case of creating within API we should set it manually. + def ebs_optimized?(flavor) always_ebs_optimized = ['c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'd2.xlarge', 'd2.2xlarge', 'd2.4xlarge', 'd2.8xlarge', 'm4.large', 'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge'] - always_ebs_optimized.include?(instance_type) + always_ebs_optimized.include?(flavor) + end + + # When you create an instance with with ephemeral storages available within AWS console, + # they are mapped automatically. But in case of creating within API we should map them manually. + def ephemeral_storages_mappings(flavor) + require 'fog/aws/models/compute/flavors' + details = Fog::Compute::AWS::FLAVORS.detect {|f| f[:id] == flavor} + return [] unless details + + mappings = [] + details[:instance_store_volumes].times do |i| + mappings << { + 'VirtualName' => "ephemeral#{i}", + 'DeviceName' => "/dev/xvd#{('b'.ord + i).chr}" + } + end + mappings end end