File: network.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 (60 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download
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
module Fog
  module Compute
    class Google
      ##
      # Represents a Network resource
      #
      # @see https://developers.google.com/compute/docs/reference/latest/networks
      class Network < Fog::Model
        identity :name

        attribute :auto_create_subnetworks, aliases => "autoCreateSubnetworks"
        attribute :creation_timestamp, aliases => "creationTimestamp"
        attribute :description
        # TODO: Naming issue in the client lib, rename after this is resolved:
        # https://github.com/google/google-api-ruby-client/issues/666
        attribute :gateway_i_pv4, aliases => %w(gateway_ipv4 gatewayIPv4)
        attribute :i_pv4_range, aliases => %w(ipv4_range IPv4Range)
        attribute :id
        attribute :kind
        attribute :peerings
        attribute :routing_config, aliases => "routingConfig"
        attribute :self_link, aliases => "selfLink"
        attribute :subnetworks

        # TODO: Naming issue in the client lib, rename after this is resolved:
        # https://github.com/google/google-api-ruby-client/issues/666
        alias_method :ipv4_range, :i_pv4_range

        def save
          requires :identity

          data = service.insert_network(identity, attributes)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          # Since network has no "state" we can query, we have to wait for the operation to finish
          # TODO: change back to async when there's a proper state API
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :identity

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

        # Returns a ready API structure for insert_instance, used in insert_server request.
        def get_as_interface_config(access_config = nil)
          network_interface = { :network => self_link }
          network_interface[:access_configs] = [access_config] if access_config
          network_interface
        end
      end
    end
  end
end