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

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

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#add_health_check(health_check) ⇒ Object



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

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



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

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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/google/models/compute/target_pool.rb', line 43

def destroy(async=true)
  requires :name, :region
  operation = service.delete_target_pool(name, region)
  if not 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



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

def get_health
  service.get_target_pool_health self
end

#ready?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
# File 'lib/fog/google/models/compute/target_pool.rb', line 85

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

#reloadObject



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

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



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

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



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

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

#saveObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/google/models/compute/target_pool.rb', line 24

def save
  requires :name, :region

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

  service.insert_target_pool(name, region, options).body
  data = service.backoff_if_unfound {service.get_target_pool(name, region).body}
  merge_attributes(data)
  self
end