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



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

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



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

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



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

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



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

def get_health
  service.get_target_pool_health self
end

#ready?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
# File 'lib/fog/google/models/compute/target_pool.rb', line 82

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

#region_nameObject



91
92
93
# File 'lib/fog/google/models/compute/target_pool.rb', line 91

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

#reloadObject



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

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



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

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



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

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

#saveObject



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

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