CID-471: add mappings for ephemeral storages
This commit is contained in:
		
							parent
							
								
									ac540e6f9c
								
							
						
					
					
						commit
						7fb5862f85
					
				| @ -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 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Anton Chuchkalov
						Anton Chuchkalov