File: image.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (81 lines) | stat: -rw-r--r-- 2,755 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module Fog
  module Compute
    class Google
      class Image < Fog::Model
        identity :name

        attribute :archive_size_bytes, :aliases => "archiveSizeBytes"
        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :deprecated
        attribute :description
        attribute :disk_size_gb, :aliases => "diskSizeGb"
        attribute :family
        attribute :guest_os_features, :aliases => "guestOsFeatures"
        attribute :id
        attribute :image_encryption_key, :aliases => "imageEncryptionKey"
        attribute :kind
        attribute :licenses

        # A RawDisk, e.g. -
        # {
        #   :source         => url_to_gcs_file,
        #   :container_type => 'TAR',
        #   :sha1Checksum   => ,
        # }
        attribute :raw_disk, :aliases => "rawDisk"

        attribute :self_link, :aliases => "selfLink"
        attribute :source_disk, :aliases => "sourceDisk"
        attribute :source_disk_encryption_key, :aliases => "sourceDiskEncryptionKey"
        attribute :source_disk_id, :aliases => "sourceDiskId"
        attribute :source_image, :aliases => "sourceImage"
        attribute :source_image_encryption_key, :aliases => "sourceImageEncryptionKey"
        attribute :source_image_id, :aliases => "sourceImageId"
        attribute :source_type, :aliases => "sourceType"
        attribute :status

        # This attribute is not available in the representation of an
        # 'image' returned by the GCE server (see GCE API). However,
        # images are a global resource and a user can query for images
        # across projects. Therefore we try to remember which project
        # the image belongs to by tracking it in this attribute.
        attribute :project

        READY_STATE = "READY".freeze

        def ready?
          status == READY_STATE
        end

        def destroy(async = true)
          data = service.delete_image(name)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? } unless async
          operation
        end

        def reload
          requires :name
          data = service.get_image(name, project)
          merge_attributes(data.to_h)
          self
        end

        def save
          requires :name

          data = service.insert_image(name, attributes)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? }
          reload
        end

        def resource_url
          "#{project}/global/images/#{name}"
        end
      end
    end
  end
end