File: http_health_check.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 (104 lines) | stat: -rw-r--r-- 3,107 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module Fog
  module Compute
    class Google
      class HttpHealthCheck < Fog::Model
        identity :name

        attribute :check_interval_sec, :aliases => "checkIntervalSec"
        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :description
        attribute :healthy_threshold, :aliases => "healthyThreshold"
        attribute :host
        attribute :id
        attribute :kind
        attribute :port
        attribute :request_path, :aliases => "requestPath"
        attribute :self_link, :aliases => "selfLink"
        attribute :timeout_sec, :aliases => "timeoutSec"
        attribute :unhealthy_threshold, :aliases => "unhealthyThreshold"

        MODIFIABLE_FIELDS = %i(
          name
          check_interval_sec
          creation_timestamp
          description
          healthy_threshold
          host
          port
          request_path
          timeout_sec
          unhealthy_threshold
        ).freeze

        def save
          opts = {
            :name => name,
            :check_interval_sec => check_interval_sec,
            :creation_timestamp => creation_timestamp,
            :description => description,
            :healthy_threshold => healthy_threshold,
            :host => host,
            :port => port,
            :request_path => request_path,
            :timeout_sec => timeout_sec,
            :unhealthy_threshold => unhealthy_threshold
          }

          id.nil? ? create(opts) : update(opts)
        end

        def create(opts)
          requires :name

          data = service.insert_http_health_check(name, opts)
          operation = Fog::Compute::Google::Operations.new(service: service)
                                                      .get(data.name, data.zone)
          operation.wait_for { ready? }
          reload
        end

        def update(opts)
          requires :name
          data = service.update_http_health_check(name, opts)
          operation = Fog::Compute::Google::Operations.new(service: service)
                                                      .get(data.name, data.zone)
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :name
          data = service.delete_http_health_check(name)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? } unless async
          operation
        end

        def ready?
          service.get_http_health_check(name)
          true
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          false
        end

        def reload
          requires :name

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

          new_attributes = data.attributes
          merge_attributes(new_attributes)
          self
        end

        RUNNING_STATE = "READY".freeze
      end
    end
  end
end