Class: Fog::Compute::Google::Images

Inherits:
Fog::Collection show all
Defined in:
lib/fog/google/models/compute/images.rb

Constant Summary collapse

GLOBAL_PROJECTS =
[ 'google',
  'debian-cloud',
  'centos-cloud',
# RHEL removed from this list because not everyone has access to it.
#  'rhel-cloud', 
]

Instance Attribute Summary

Attributes inherited from Fog::Collection

#service

Instance Method Summary collapse

Methods inherited from Fog::Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#allObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/google/models/compute/images.rb', line 19

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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/google/models/compute/images.rb', line 34

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