Class: AWS::ELB::AvailabilityZoneCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Collection::Simple
Defined in:
lib/aws/elb/availability_zone_collection.rb

Overview

A collection that help maanage the availability zones for a load balancer.

load_balancer = AWS::ELB.new.load_balancers['my-load-balancer']

zones = load_balancer.availability_zones

# adding zones
zones.enable('us-east-1b', 'us-east-1c')

# removing zones
zones.disable('us-east-1b')

# enumerating enabled zones
zones.each do |zone|
  puts zone.name
end

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Collection::Simple

#each_batch

Methods included from Core::Collection

#each, #each_batch, #enum, #first, #in_groups_of, #page

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(load_balancer, options = {}) ⇒ AvailabilityZoneCollection

Returns a new instance of AvailabilityZoneCollection.

Parameters:

  • load_balancer (LoadBalancer)

    The load balancer this list of availability zones belongs to.



41
42
43
44
# File 'lib/aws/elb/availability_zone_collection.rb', line 41

def initialize load_balancer, options = {}
  @load_balancer = load_balancer
  super
end

Instance Attribute Details

#load_balancerLoadBalancer (readonly)

Returns the load balancer this list describes.

Returns:

  • (LoadBalancer)

    Returns the load balancer this list describes.



47
48
49
# File 'lib/aws/elb/availability_zone_collection.rb', line 47

def load_balancer
  @load_balancer
end

Instance Method Details

#disable(*availability_zones) ⇒ nil

Removes the specified EC2 availability zones from the set of configured availability zones for the load balancer.

load_balancer.availability_zones.disable("us-east-1a", "us-east-1b")

You can also pass AWS::EC2::AvailabilityZone objects:

# disable all availabilty zones
zones = AWS::EC2.new.availability_zones.to_a
load_balancer.availability_zones.disable(zones)

There must be at least one availability zone registered with a load balancer at all times. A client cannot remove all the availability zones from a load balancer. Once an availability zone is removed, all the instances registered with the load balancer that are in the removed availability zone go into the out of service state.

Upon availability zone removal, the load balancer attempts to equally balance the traffic among its remaining usable availability zones. Trying to remove an availability zone that was not associated with the load balancer does nothing.

Parameters:

Returns:

  • (nil)


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/aws/elb/availability_zone_collection.rb', line 110

def disable *availability_zones

  names = availability_zones.flatten.collect do |av|
    av.is_a?(EC2::AvailabilityZone) ? av.name : av.to_s
  end

  client.disable_availability_zones_for_load_balancer(
    :load_balancer_name => load_balancer.name,
    :availability_zones => names)

  nil

end

#enable(*availability_zones) ⇒ nil

Adds one or more EC2 Availability Zones to the load balancer.

load_balancer.availability_zones.enable("us-east-1a", "us-east-1b")

You can also pass AWS::EC2::AvailabilityZone objects:

# enable all availabilty zones for this region
zones = AWS::EC2.new.availability_zones.to_a
load_balancer.availability_zones.enable(zones)

The load balancer evenly distributes requests across all its registered availability zones that contain instances. As a result, the client must ensure that its load balancer is appropriately scaled for each registered Availability Zone.

Parameters:

Returns:

  • (nil)


69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/aws/elb/availability_zone_collection.rb', line 69

def enable *availability_zones

  names = availability_zones.flatten.collect do |av|
    av.is_a?(EC2::AvailabilityZone) ? av.name : av.to_s
  end

  client.enable_availability_zones_for_load_balancer(
    :load_balancer_name => load_balancer.name,
    :availability_zones => names)

  nil

end