From a0ee50f963b7736870123a6ce5316669b178e24d Mon Sep 17 00:00:00 2001 From: Naoto TAKAHASHI Date: Mon, 17 Nov 2014 10:47:56 +0900 Subject: [PATCH] fixup! --- .../compute/block_device_mapping_v2.rb | 17 ++++---- .../requests/compute/create_server.rb | 42 +++++++++---------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb b/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb index d967bfed4..b3460a554 100644 --- a/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb +++ b/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb @@ -16,12 +16,15 @@ compute_client ||= ::Fog::Compute.new(:provider => :openstack, vm = compute_client.servers.create(:name => name, :flavor_ref => flavor, - :block_device_mapping_v2 => [ - :device_name => "/dev/sda1", - :source_type => "volume", - :destination_type => "volume", - :delete_on_termination => false, - :uuid => cinder_uddi, - :boot_index => 0 + :block_device_mapping => [ + { + :api_ver => "v2", + :device_name => "/dev/vda1", + :source_type => "volume", + :destination_type => "volume", + :delete_on_termination => false, + :uuid => cinder_uddi, + :boot_index => 0 + } ] ) diff --git a/lib/fog/openstack/requests/compute/create_server.rb b/lib/fog/openstack/requests/compute/create_server.rb index 4b302ecbc..319a26519 100644 --- a/lib/fog/openstack/requests/compute/create_server.rb +++ b/lib/fog/openstack/requests/compute/create_server.rb @@ -58,28 +58,28 @@ module Fog end if options['block_device_mapping'] - data['server']['block_device_mapping'] = [options['block_device_mapping']].flatten.map do |mapping| - { - 'volume_size' => mapping[:volume_size], - 'volume_id' => mapping[:volume_id], - 'delete_on_termination' => mapping[:delete_on_termination], - 'device_name' => mapping[:device_name] - } - end - end - - if options['block_device_mapping_v2'] - data['server']['block_device_mapping_v2'] = - [options['block_device_mapping']].flatten.map do |mapping| - { - 'device_name' => mapping[:device_name], - 'source_type' => mapping[:source_type], - 'destination_type' => mapping[:destination_type], - 'delete_on_termination' => mapping[:delete_on_termination], - 'uuid' => mapping[:uuid], - 'boot_index' => mapping[:boot_index] - } + if mapping[:api_ver] == "v2" + data['server']['block_device_mapping_v2'] = + [ + { + 'device_name' => mapping[:device_name], + 'source_type' => mapping[:source_type], + 'destination_type' => mapping[:destination_type], + 'delete_on_termination' => mapping[:delete_on_termination], + 'uuid' => mapping[:uuid], + 'boot_index' => mapping[:boot_index] + } + ] + else + data['server']['block_device_mapping'] = + { + 'volume_size' => mapping[:volume_size], + 'volume_id' => mapping[:volume_id], + 'delete_on_termination' => mapping[:delete_on_termination], + 'device_name' => mapping[:device_name] + } + end end end