From dea45e862188a3acf030b3108ed3e3ef95922211 Mon Sep 17 00:00:00 2001 From: Nat Welch Date: Tue, 13 Aug 2013 14:41:52 -0700 Subject: [PATCH 1/2] Fix some issues with GCE examples and disk requests. --- lib/fog/google/examples/get_list_snapshots.rb | 8 +++++--- lib/fog/google/examples/launch_micro_instance.rb | 2 +- lib/fog/google/examples/network.rb | 7 +++++-- lib/fog/google/requests/compute/delete_disk.rb | 4 ++++ lib/fog/google/requests/compute/get_disk.rb | 1 + lib/fog/google/requests/compute/get_snapshot.rb | 4 ++++ 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/fog/google/examples/get_list_snapshots.rb b/lib/fog/google/examples/get_list_snapshots.rb index fbfb15b98..231a85c6d 100644 --- a/lib/fog/google/examples/get_list_snapshots.rb +++ b/lib/fog/google/examples/get_list_snapshots.rb @@ -11,8 +11,10 @@ def test snap = snapshots.first # puts 'Fetching a single image from a global project...' # puts '------------------------------------------------' - snap = connection.snapshots.get(snap) - raise 'Could not GET the snapshot' unless snap - # puts snap.inspect + if !snap.nil? + snap = connection.snapshots.get(snap) + raise 'Could not GET the snapshot' unless snap + # puts snap.inspect + end end diff --git a/lib/fog/google/examples/launch_micro_instance.rb b/lib/fog/google/examples/launch_micro_instance.rb index 56f5fcad3..c59e7e797 100755 --- a/lib/fog/google/examples/launch_micro_instance.rb +++ b/lib/fog/google/examples/launch_micro_instance.rb @@ -5,7 +5,7 @@ def test :name => 'foggydisk', :size_gb => 10, :zone_name => 'us-central1-a', - :image_name => 'centos-6-v20130522', + :source_image => 'centos-6-v20130522', }) disk.wait_for { disk.ready? } diff --git a/lib/fog/google/examples/network.rb b/lib/fog/google/examples/network.rb index b7ad0c379..751795000 100644 --- a/lib/fog/google/examples/network.rb +++ b/lib/fog/google/examples/network.rb @@ -2,9 +2,9 @@ def test connection = Fog::Compute.new({ :provider => "Google" }) # we create a new private network - connection.insert_network('my-private-network','10.240.0.0/16') + connection.insert_network('my-private-network', '10.240.0.0/16') - server = connection.servers.bootstrap(defaults = { + server = connection.servers.create({ :name => "fog-smoke-test-#{Time.now.to_i}", :image_name => "debian-7-wheezy-v20130522", :machine_type => "n1-standard-1", @@ -15,4 +15,7 @@ def test :external_ip => false, :user => ENV['USER'], }) + + # The network won't have any firewall rules, so we won't be able to ssh in. + server.wait_for { ready? } end diff --git a/lib/fog/google/requests/compute/delete_disk.rb b/lib/fog/google/requests/compute/delete_disk.rb index e673ab4c1..e7903d5e7 100644 --- a/lib/fog/google/requests/compute/delete_disk.rb +++ b/lib/fog/google/requests/compute/delete_disk.rb @@ -13,6 +13,10 @@ module Fog class Real def delete_disk(disk_name, zone_name) + if zone_name.start_with? 'http' + zone_name = zone_name.split('/')[-1] + end + api_method = @compute.disks.delete parameters = { 'project' => @project, diff --git a/lib/fog/google/requests/compute/get_disk.rb b/lib/fog/google/requests/compute/get_disk.rb index 2349f561a..5914c3ffd 100644 --- a/lib/fog/google/requests/compute/get_disk.rb +++ b/lib/fog/google/requests/compute/get_disk.rb @@ -16,6 +16,7 @@ module Fog if zone_name.start_with? 'http' zone_name = zone_name.split('/')[-1] end + api_method = @compute.disks.get parameters = { 'project' => @project, diff --git a/lib/fog/google/requests/compute/get_snapshot.rb b/lib/fog/google/requests/compute/get_snapshot.rb index 1dc66282e..1b3a2ba9d 100644 --- a/lib/fog/google/requests/compute/get_snapshot.rb +++ b/lib/fog/google/requests/compute/get_snapshot.rb @@ -13,6 +13,10 @@ module Fog class Real def get_snapshot(snap_name, project=@project) + if snap_name.nil? + raise ArgumentError.new "snap_name must not be nil." + end + api_method = @compute.snapshots.get parameters = { 'snapshot' => snap_name, From b306b7cb34092cb6119b85f945dedf7be052f18a Mon Sep 17 00:00:00 2001 From: Nat Welch Date: Tue, 13 Aug 2013 14:51:17 -0700 Subject: [PATCH 2/2] Fix comments in Google snapshot example. --- lib/fog/google/examples/get_list_snapshots.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/google/examples/get_list_snapshots.rb b/lib/fog/google/examples/get_list_snapshots.rb index 231a85c6d..91f265186 100644 --- a/lib/fog/google/examples/get_list_snapshots.rb +++ b/lib/fog/google/examples/get_list_snapshots.rb @@ -2,15 +2,15 @@ def test connection = Fog::Compute.new({ :provider => "Google" }) - # puts 'Listing images in all projects...' + # puts 'Listing snapshots...' # puts '---------------------------------' snapshots = connection.snapshots.all raise 'Could not LIST the snapshots' unless snapshots # puts snapshots.inspect - snap = snapshots.first - # puts 'Fetching a single image from a global project...' + # puts 'Fetching a single snapshot...' # puts '------------------------------------------------' + snap = snapshots.first if !snap.nil? snap = connection.snapshots.get(snap) raise 'Could not GET the snapshot' unless snap