class Fog::Compute::Google::TargetPool

Constants

RUNNING_STATE

Public Instance Methods

add_health_check(health_check, async = true) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 68
def add_health_check(health_check, async = true)
  requires :identity, :region

  health_check = health_check.self_link unless health_check.class == String
  data = service.add_target_pool_health_checks(identity, region, [health_check])
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? } unless async

  reload
end
add_instance(instance, async = true) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 42
def add_instance(instance, async = true)
  requires :identity
  instance = instance.self_link unless instance.class == String
  data = service.add_target_pool_instances(identity, region, [instance])
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? } unless async

  reload
end
destroy(async = true) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 32
def destroy(async = true)
  requires :identity, :region
  data = service.delete_target_pool(identity, region)
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? } unless async
  operation
end
get_health(instance_name = nil) click to toggle source

Get most recent health checks for each IP for instances.

@param [String] instance_name a specific instance to look up. Default

behavior returns health checks for all instances associated with
this check.

@returns [Hash<String, Array<Hash>>] a map of instance URL to health checks

Example Hash: {

"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/myinstance"=>

[{:health_state=>“UNHEALTHY”,

:instance=>"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/myinstance"

}] }

# File lib/fog/compute/google/models/target_pool.rb, line 109
def get_health(instance_name = nil)
  requires :identity, :region

  if instance_name
    instance = service.servers.get(instance_name)
    data = service.get_target_pool_health(identity, region, instance.self_link)
                  .to_h[:health_status] || []
    results = [[instance.self_link, data]]
  else
    results = instances.map do |self_link|
      # TODO: Improve the returned object, current is hard to navigate
      # [{instance => @instance, health_state => "HEALTHY"}, ...]
      data = service.get_target_pool_health(identity, region, self_link)
                    .to_h[:health_status] || []
      [self_link, data]
    end
  end
  Hash[results]
end
ready?() click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 141
def ready?
  service.get_target_pool(name, region)
  true
rescue ::Google::Apis::ClientError => e
  raise e unless e.status_code == 404
  false
end
region_name() click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 149
def region_name
  region.nil? ? nil : region.split("/")[-1]
end
reload() click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 153
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, async = true) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 81
def remove_health_check(health_check, async = true)
  requires :identity, :region

  health_check = health_check.self_link unless health_check.class == String
  data = service.remove_target_pool_health_checks(identity, region, [health_check])
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? } unless async
  reload
end
remove_instance(instance, async = true) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 54
def remove_instance(instance, async = true)
  requires :identity

  instance = instance.self_link unless instance.class == String
  data = service.remove_target_pool_instances(identity, region, [instance])
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)

  operation.wait_for { ready? } unless async

  reload
end
save() click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 19
def save
  requires :name, :region

  data = service.insert_target_pool(
    name, region, attributes.reject { |_k, v| v.nil? }
  )
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? }
  reload
end
set_backup(backup = nil) click to toggle source
# File lib/fog/compute/google/models/target_pool.rb, line 129
def set_backup(backup = nil)
  requires :identity, :region

  backup ||= backup_pool

  service.set_target_pool_backup(
    identity, region, backup,
    :failover_ratio => failover_ratio
  )
  reload
end