File: insert_disk.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 (48 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download | duplicates (2)
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
module Fog
  module Compute
    class Google
      class Mock
        def insert_disk(_disk_name, _zone, _image_name = nil, _options = {})
          # :no-coverage:
          Fog::Mock.not_implemented
          # :no-coverage:
        end
      end

      class Real
        # Create a disk resource in a specific zone
        # https://cloud.google.com/compute/docs/reference/latest/disks/insert
        #
        # @param disk_name [String] Name of the disk to create
        # @param zone_name [String] Zone the disk reside in
        # @param source_image [String] Optional self_link or family formatted url of the image to
        # create the disk from, see https://cloud.google.com/compute/docs/reference/latest/disks/insert
        # @param opts [Hash] Optional hash of options
        # @option options [String] size_gb Number of GB to allocate to an empty disk
        # @option options [String] source_snapshot Snapshot to create the disk from
        # @option options [String] description Human friendly description of the disk
        # @option options [String] type URL of the disk type resource describing which disk type to use
        # TODO(2.0): change source_image to keyword argument in 2.0 and gracefully deprecate
        def insert_disk(disk_name, zone, source_image = nil,
                        description: nil, type: nil, size_gb: nil,
                        source_snapshot: nil, labels: nil, **_opts)

          if source_image && !source_image.include?("projects/")
            raise ArgumentError.new("source_image needs to be self-link formatted or specify a family")
          end
          disk_opts = {
            :name => disk_name,
            :description => description,
            :type => type,
            :size_gb => size_gb,
            :source_snapshot => source_snapshot,
            :source_image => source_image
          }
          disk_opts[:labels] = labels if labels
          disk = ::Google::Apis::ComputeV1::Disk.new(**disk_opts)
          @compute.insert_disk(@project, zone.split("/")[-1], disk)
        end
      end
    end
  end
end