From 5f7886e08d0ecd7d84264fb9c8e1cc05ef085427 Mon Sep 17 00:00:00 2001 From: Nat Welch Date: Mon, 17 Mar 2014 07:46:25 -0700 Subject: [PATCH] [google|compute] Change projects we search for images in. This removes Google (which has no valid v1 images) and adds rhel-cloud and suse-cloud. It also wraps the lookups in a catch block for not-found exceptions because not everyone has access to everything. --- lib/fog/google/examples/image_all.rb | 6 +++++ lib/fog/google/models/compute/images.rb | 29 ++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 lib/fog/google/examples/image_all.rb diff --git a/lib/fog/google/examples/image_all.rb b/lib/fog/google/examples/image_all.rb new file mode 100644 index 000000000..bbac2b954 --- /dev/null +++ b/lib/fog/google/examples/image_all.rb @@ -0,0 +1,6 @@ +def test + connection = Fog::Compute.new({ :provider => "Google" }) + + # If this doesn't raise an exception, everything is good. + connection.images.all +end diff --git a/lib/fog/google/models/compute/images.rb b/lib/fog/google/models/compute/images.rb index df9aef305..6d7ea2c8c 100644 --- a/lib/fog/google/models/compute/images.rb +++ b/lib/fog/google/models/compute/images.rb @@ -9,23 +9,32 @@ module Fog model Fog::Compute::Google::Image - GLOBAL_PROJECTS = [ 'google', - 'debian-cloud', - 'centos-cloud', - # RHEL removed from this list because not everyone has access to it. - # 'rhel-cloud', - ] + # NOTE: Not everyone has access to these projects because of the + # licenses needed to use some of them. + # https://developers.google.com/compute/docs/premium-operating-systems + GLOBAL_PROJECTS = [ + 'debian-cloud', + 'centos-cloud', + 'rhel-cloud', + 'suse-cloud' + ] def all data = [] all_projects = GLOBAL_PROJECTS + [ self.service.project ] all_projects.each do |project| - images = service.list_images(project).body["items"] || [] + begin + images = service.list_images(project).body["items"] || [] - # Keep track of the project in which we found the image(s) - images.each { |img| img[:project] = project } - data += images + # Keep track of the project in which we found the image(s) + images.each { |img| img[:project] = project } + data += images + rescue Fog::Errors::NotFound + # Not everyone has access to every Global Project. Requests + # return 404 if you don't have access. + next + end end load(data)