File: backend_service.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 (86 lines) | stat: -rw-r--r-- 2,473 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
module Fog
  module Compute
    class Google
      class BackendService < Fog::Model
        identity :name

        attribute :backends
        attribute :creation_timestamp
        attribute :description
        attribute :fingerprint
        attribute :health_checks, :aliases => "healthChecks"
        attribute :id
        attribute :kind
        attribute :port
        attribute :protocol
        attribute :self_link, :aliases => "selfLink"
        attribute :timeout_sec, :aliases => "timeoutSec"

        def save
          requires :name, :health_checks

          options = {
            :description => description,
            :backends => backends,
            :fingerprint => fingerprint,
            :health_checks => health_checks,
            :port => port,
            :protocol => protocol,
            :timeout_sec => timeout_sec
          }

          data = service.insert_backend_service(name, **options)
          operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name)
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :name

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

        def get_health
          service.get_backend_service_health(self)
        end

        def add_backend(backend)
          # ensure backend is an array of hashes
          backend = [backend] unless backend.class == Array
          backend.map! { |resource| resource.class == String ? { "group" => resource } : resource }
          service.add_backend_service_backends(self, backend)
          reload
        end

        def ready?
          service.get_backend_service(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