From aa1d8d0bd880affd1e5b89c2cb2ce52127227224 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Fri, 27 Dec 2013 12:26:29 -0800 Subject: [PATCH] [aws] mock block device mapping on run_instances --- lib/fog/aws/parsers/compute/run_instances.rb | 2 +- lib/fog/aws/requests/compute/run_instances.rb | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/parsers/compute/run_instances.rb b/lib/fog/aws/parsers/compute/run_instances.rb index 7b321edad..27916395b 100644 --- a/lib/fog/aws/parsers/compute/run_instances.rb +++ b/lib/fog/aws/parsers/compute/run_instances.rb @@ -75,7 +75,7 @@ module Fog when 'ebsOptimized' @instance['ebsOptimized'] = (value == 'true') when 'associatePublicIP' - @instance['associatePublicIP'] = (value == 'true') + @instance['associatePublicIP'] = (value == 'true') end end diff --git a/lib/fog/aws/requests/compute/run_instances.rb b/lib/fog/aws/requests/compute/run_instances.rb index ba5bac68e..d375d6f94 100644 --- a/lib/fog/aws/requests/compute/run_instances.rb +++ b/lib/fog/aws/requests/compute/run_instances.rb @@ -139,11 +139,25 @@ module Fog min_count.times do |i| instance_id = Fog::AWS::Mock.instance_id + availability_zone = options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone(@region) + + block_device_mapping = (options['BlockDeviceMapping'] || []).inject([]) do |mapping, device| + volume_id = create_volume(availability_zone, device["Ebs.VolumeSize"]).data[:body]["volumeId"] + + mapping << { + "deviceName" => device["DeviceName"], + "volumeId" => volume_id, + "status" => "attached", + "attachTime" => Time.now, + "deleteOnTermination" => true, + } + end + instance = { 'amiLaunchIndex' => i, 'associatePublicIP' => options['associatePublicIP'] || false, 'architecture' => 'i386', - 'blockDeviceMapping' => [], + 'blockDeviceMapping' => block_device_mapping, 'clientToken' => options['clientToken'], 'dnsName' => nil, 'ebsOptimized' => options['EbsOptimized'] || false, @@ -156,7 +170,7 @@ module Fog 'keyName' => options['KeyName'], 'launchTime' => Time.now, 'monitoring' => { 'state' => options['Monitoring.Enabled'] || false }, - 'placement' => { 'availabilityZone' => options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone(@region), 'groupName' => nil, 'tenancy' => options['Placement.Tenancy'] || 'default' }, + 'placement' => { 'availabilityZone' => availability_zone, 'groupName' => nil, 'tenancy' => options['Placement.Tenancy'] || 'default' }, 'privateDnsName' => nil, 'productCodes' => [], 'reason' => nil,