Class: Fog::Compute::Google::TargetPool

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

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#add_health_check(health_check) ⇒ Object



64
65
66
67
68
# File 'lib/fog/compute/google/models/target_pool.rb', line 64

def add_health_check(health_check)
  health_check = health_check.self_link unless health_check.class == String
  service.add_target_pool_health_checks(self, [health_check])
  reload
end

#add_instance(instance) ⇒ Object



52
53
54
55
56
# File 'lib/fog/compute/google/models/target_pool.rb', line 52

def add_instance(instance)
  instance = instance.self_link unless instance.class == String
  service.add_target_pool_instances(self, [instance])
  reload
end

#destroy(async = true) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/compute/google/models/target_pool.rb', line 38

def destroy(async = true)
  requires :name, :region
  operation = service.delete_target_pool(name, region)
  unless async
    # wait until "DONE" to ensure the operation doesn't fail, raises
    # exception on error
    Fog.wait_for do
      operation = service.get_region_operation(region, operation.body["name"])
      operation.body["status"] == "DONE"
    end
  end
  operation
end

#get_healthObject



76
77
78
# File 'lib/fog/compute/google/models/target_pool.rb', line 76

def get_health
  service.get_target_pool_health self
end

#ready?Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
# File 'lib/fog/compute/google/models/target_pool.rb', line 80

def ready?
  service.get_target_pool(name, region)
  true
rescue Fog::Errors::NotFound
  false
end

#region_nameObject



87
88
89
# File 'lib/fog/compute/google/models/target_pool.rb', line 87

def region_name
  region.nil? ? nil : region.split("/")[-1]
end

#reloadObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fog/compute/google/models/target_pool.rb', line 91

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

#remove_health_check(health_check) ⇒ Object



70
71
72
73
74
# File 'lib/fog/compute/google/models/target_pool.rb', line 70

def remove_health_check(health_check)
  health_check = health_check.self_link unless health_check.class == String
  service.remove_target_pool_health_checks(self, [health_check])
  reload
end

#remove_instance(instance) ⇒ Object



58
59
60
61
62
# File 'lib/fog/compute/google/models/target_pool.rb', line 58

def remove_instance(instance)
  instance = instance.self_link unless instance.class == String
  service.remove_target_pool_instances(self, [instance])
  reload
end

#saveObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/compute/google/models/target_pool.rb', line 19

def save
  requires :name, :region

  options = {
    "description" => description,
    "region" => region,
    "healthChecks" => health_checks,
    "instances" => instances,
    "sessionAffinity" => session_affinity,
    "failoverRatio" => failover_ratio,
    "backupPool" => backup_pool
  }

  data = service.insert_target_pool(name, region, options).body
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data["name"], nil, data["region"])
  operation.wait_for { !pending? }
  reload
end