Class: AWS::ELB::AvailabilityZoneCollection
- Inherits:
-
Object
- Object
- AWS::ELB::AvailabilityZoneCollection
- 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
-
#load_balancer ⇒ LoadBalancer
readonly
Returns the load balancer this list describes.
Attributes included from Core::Model
Instance Method Summary collapse
-
#disable(*availability_zones) ⇒ nil
Removes the specified EC2 availability zones from the set of configured availability zones for the load balancer.
-
#enable(*availability_zones) ⇒ nil
Adds one or more EC2 Availability Zones to the load balancer.
-
#initialize(load_balancer, options = {}) ⇒ AvailabilityZoneCollection
constructor
A new instance of AvailabilityZoneCollection.
Methods included from Core::Collection::Simple
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.
41 42 43 44 |
# File 'lib/aws/elb/availability_zone_collection.rb', line 41 def initialize load_balancer, = {} @load_balancer = load_balancer super end |
Instance Attribute Details
#load_balancer ⇒ LoadBalancer (readonly)
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.
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.
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 |