From d716ba1c1da6174e5eef3499d845b9806e9c31fb Mon Sep 17 00:00:00 2001 From: Akshay Moghe Date: Tue, 13 Aug 2013 13:53:01 -0700 Subject: [PATCH] Fix up the 'disk' api A recent patch to introduce support for creating disks from snapshots had a few problems: 1. Incorrect URL (to the snapshot resource) was being sent 2. Ruby syntax errors. I looked into adding Shindo tests for this, but am not able to since this request relies on a pre-existing snapshot which we use for disk creation. --- lib/fog/google/models/compute/snapshot.rb | 2 +- lib/fog/google/requests/compute/insert_disk.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/fog/google/models/compute/snapshot.rb b/lib/fog/google/models/compute/snapshot.rb index f7908f379..1c460d2e2 100644 --- a/lib/fog/google/models/compute/snapshot.rb +++ b/lib/fog/google/models/compute/snapshot.rb @@ -26,7 +26,7 @@ module Fog end def resource_url - "#{self.project}/global/snapshots/#{name}" + "#{self.service.project}/global/snapshots/#{name}" end end diff --git a/lib/fog/google/requests/compute/insert_disk.rb b/lib/fog/google/requests/compute/insert_disk.rb index 9218b2791..06815289d 100644 --- a/lib/fog/google/requests/compute/insert_disk.rb +++ b/lib/fog/google/requests/compute/insert_disk.rb @@ -30,14 +30,16 @@ module Fog # These must be present if image_name is not specified if image_name.nil? - unless opts.has_key?(:sourceSnapshot) and opts.has_key?(:sizeGb) + unless opts.has_key?('sourceSnapshot') and opts.has_key?('sizeGb') raise ArgumentError.new('Must specify image OR snapshot and '\ 'disk size when creating a disk.') end - body_object['sizeGb'] = opts['sizeGb'].delete - # TODO 'get' the sourceSnapshot to validate that it exists? - body_object['sourceSnapshot'] = opts['sourceSnapshot'].delete + body_object['sizeGb'] = opts.delete('sizeGb') + + snap = snapshots.get(opts.delete('sourceSnapshot')) + raise ArgumentError.new('Invalid source snapshot') unless snap + body_object['sourceSnapshot'] = @api_url + snap.resource_url end # Merge in any remaining options (only 'description' should remain)