Sha256: 821ffeb3918c1aa15b01360b9df661a73671d81192c309009ef57d08c242ed46

Contents?: true

Size: 1.57 KB

Versions: 38

Compression:

Stored size: 1.57 KB

Contents

require 'fog/core/collection'
require 'fog/google/models/compute/image'

module Fog
  module Compute
    class Google

      class Images < Fog::Collection

        model Fog::Compute::Google::Image

        GLOBAL_PROJECTS = [ 'google',
                            'debian-cloud',
                            'centos-cloud',
                          ]

        def all
          data = []
          all_projects = GLOBAL_PROJECTS + [ self.service.project ]

          all_projects.each do |project|
            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
          end

          load(data)
        end

        def get(identity)
          # Search own project before global projects
          all_projects = [ self.service.project ] + GLOBAL_PROJECTS

          data = nil
          all_projects.each do |project|
            begin
              data = service.get_image(identity, project).body
              data[:project] = project
            rescue Fog::Errors::Error
              next
            else
              break
            end
          end

          # If it wasn't found in any project, raise
          if data.nil?
            raise Fog::Errors::Error.new('Unable to find the specified image '\
                                         'in the following projects: '\
                                         "#{all_projects.join(', ')}")
          end

          new(data)
        end

      end
    end
  end
end

Version data entries

38 entries across 38 versions & 3 rubygems

Version Path
fog-maestrodev-1.19.0.20140212012611 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/google/models/compute/images.rb
fog-1.19.0 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131209090811 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131205181604 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131127194823 lib/fog/google/models/compute/images.rb
fog-maestrodev-1.18.0.20131126183714 lib/fog/google/models/compute/images.rb