class Fog::Compute::Google::Images

Constants

GLOBAL_PROJECTS

Public Instance Methods

all() click to toggle source
# File lib/fog/google/models/compute/images.rb, line 17
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
get(identity) click to toggle source
# File lib/fog/google/models/compute/images.rb, line 32
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