File: forwarding_rule.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 (79 lines) | stat: -rw-r--r-- 2,489 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
module Fog
  module Compute
    class Google
      class ForwardingRule < Fog::Model
        identity :name

        attribute :ip_address, :aliases => "IPAddress"
        attribute :ip_protocol, :aliases => "IPProtocol"
        attribute :backend_service, :aliases => "backendService"
        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :description
        attribute :id
        attribute :ip_version, :aliases => "ipVersion"
        attribute :kind
        attribute :load_balancing_scheme, :aliases => "loadBalancingScheme"
        attribute :network
        attribute :port_range, :aliases => "portRange"
        attribute :ports
        attribute :region
        attribute :self_link, :aliases => "selfLink"
        attribute :subnetwork
        attribute :target

        def save
          requires :identity, :region

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

        def set_target(new_target)
          requires :identity, :region

          new_target = new_target.self_link unless new_target.class == String
          self.target = new_target
          service.set_forwarding_rule_target(
            identity, region, :target => new_target
          )
          reload
        end

        def destroy(async = true)
          requires :identity, :region
          data = service.delete_forwarding_rule(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 ready?
          requires :identity
          service.get_forwarding_rule(identity, region)
          true
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          false
        end

        def reload
          requires :name, :region

          return unless data = begin
            collection.get(name, region)
          rescue Excon::Errors::SocketError
            nil
          end

          new_attributes = data.attributes
          merge_attributes(new_attributes)
          self
        end
      end
    end
  end
end