File: set_server_metadata.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 (39 lines) | stat: -rw-r--r-- 1,391 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
module Fog
  module Compute
    class Google
      class Mock
        def set_server_metadata(_instance, _zone, _fingerprint, _metadata_items = {})
          # :no-coverage:
          Fog::Mock.not_implemented
          # :no-coverage:
        end
      end

      class Real
        # Set an instance metadata
        #
        # @param [String] instance Instance name (identity)
        # @param [String] zone Name of zone
        # @param [String] fingerprint The fingerprint of the last metadata.
        #   Can be retrieved by reloading the compute object, and checking the
        #   metadata fingerprint field.
        #     instance.reload
        #     fingerprint = instance.metadata['fingerprint']
        # @param [Hash] metadata A new metadata object
        #   Should have the following structure:
        #   {'foo' => 'bar', 'baz'=>'foo'}
        #
        # @returns [::Google::Apis::ComputeV1::Operation] set operation
        def set_server_metadata(instance, zone, fingerprint, metadata_items = [])
          items = metadata_items.map { |item| ::Google::Apis::ComputeV1::Metadata::Item.new(**item) }
          @compute.set_instance_metadata(
            @project, zone.split("/")[-1], instance,
            ::Google::Apis::ComputeV1::Metadata.new(
              fingerprint: fingerprint, items: items
            )
          )
        end
      end
    end
  end
end