Class: Fog::Compute::Google::HttpHealthCheck

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/google/models/http_health_check.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#create(opts) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/fog/compute/google/models/http_health_check.rb', line 50

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

#destroy(async = true) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/fog/compute/google/models/http_health_check.rb', line 69

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

#ready?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/fog/compute/google/models/http_health_check.rb', line 78

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

#reloadObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/compute/google/models/http_health_check.rb', line 86

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

#saveObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/compute/google/models/http_health_check.rb', line 33

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

#update(opts) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/fog/compute/google/models/http_health_check.rb', line 60

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