File: subnetwork.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 (83 lines) | stat: -rw-r--r-- 2,898 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
82
83
module Fog
  module Compute
    class Google
      ##
      # Represents a Subnetwork resource
      #
      # @see https://developers.google.com/compute/docs/reference/latest/subnetworks
      class Subnetwork < Fog::Model
        identity :name

        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :description
        attribute :gateway_address, :aliases => "gatewayAddress"
        attribute :id
        attribute :ip_cidr_range, :aliases => "ipCidrRange"
        attribute :kind
        attribute :network
        attribute :private_ip_google_access, :aliases => "privateIpGoogleAccess"
        attribute :region
        attribute :secondary_ip_ranges, :aliases => "secondaryIpRanges"
        attribute :self_link, :aliases => "selfLink"

        def save
          requires :identity, :network, :region, :ip_cidr_range

          data = service.insert_subnetwork(identity, region, network, ip_cidr_range, attributes)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name, nil, data.region)
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :identity, :region

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

        def update_interface_config(network_interface)
          network_interface["subnetwork"] = self_link if network_interface
          network_interface
        end

        def expand_ip_cidr_range(range, async = true)
          requires :identity, :region

          data = service.expand_subnetwork_ip_cidr_range(
            identity, region, range
          )
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name, nil, data.region)
          operation.wait_for { ready? } unless async
          reload
        end

        def set_private_ip_google_access(access, async = true)
          requires :identity, :region

          data = service.set_subnetwork_private_ip_google_access(
            identity, region, access
          )
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name, nil, data.region)

          operation.wait_for { ready? } unless async
          reload
        end

        def reload
          requires :identity, :region

          data = collection.get(identity, region.split("/")[-1])
          merge_attributes(data.attributes)
          self
        end
      end
    end
  end
end