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

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

Constant Summary collapse

GLOBAL_PROJECTS =

NOTE: some of these operating systems are premium and users will be charged a license fee beyond the base Google Compute Engine VM charges. See cloud.google.com/compute/docs/operating-systems/ for more info.

%w(
  centos-cloud
  cos-cloud
  coreos-cloud
  debian-cloud
  rhel-cloud
  suse-cloud
  suse-sap-cloud
  ubuntu-os-cloud
  windows-cloud
  windows-sql-cloud
  google-containers
  opensuse-cloud
).freeze

Instance Method Summary collapse

Instance Method Details

#allObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/compute/google/models/images.rb', line 26

def all
  data = all_projects.map do |project|
    begin
      images = service.list_images(project).items || []
      # Keep track of the project in which we found the image(s)
      images.map { |img| img.to_h.merge(:project => project) }
    rescue ::Google::Apis::ClientError => e
      raise e unless e.status_code == 404
      # Not everyone has access to every Global Project. Requests
      # return 404 if you don't have access.
      next
    end
  end
  data = data.flatten

  load(data)
end

#currentObject

Only return the non-deprecated list of images


45
46
47
# File 'lib/fog/compute/google/models/images.rb', line 45

def current
  all.reject(&:deprecated)
end

#get(identity, project = nil) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/compute/google/models/images.rb', line 49

def get(identity, project = nil)
  project.nil? ? projects = all_projects : projects = [project]
  data = nil
  projects.each do |proj|
    begin
      data = service.get_image(identity, proj).to_h
      data[:project] = proj
    rescue ::Google::Apis::ClientError => e
      next if e.status_code == 404
      break
    else
      break
    end
  end

  return nil if data.nil?
  new(data)
end

#get_from_family(family, project = nil) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/compute/google/models/images.rb', line 68

def get_from_family(family, project = nil)
  project.nil? ? projects = all_projects : projects = [project]
  data = nil

  projects.each do |proj|
    begin
      data = service.get_image_from_family(family, proj).to_h
      data[:project] = proj
    rescue ::Google::Apis::ClientError => e
      next if e.status_code == 404
      break
    end
  end
  return nil if data.nil?
  new(data)
end