Class: AWS::ELB::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/AWS/ELB.rb,
lib/AWS/ELB/load_balancers.rb

Instance Attribute Summary

Attributes inherited from Base

#port, #proxy_server, #server, #use_ssl

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from AWS::Base

Instance Method Details

#api_versionObject



22
23
24
# File 'lib/AWS/ELB.rb', line 22

def api_version
  API_VERSION
end

#aws_error?(response) ⇒ Boolean

Raises the appropriate error if the specified Net::HTTPResponse object contains an Amazon EC2 error; returns false otherwise.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/AWS/ELB.rb', line 32

def aws_error?(response)

  # return false if we got a HTTP 200 code,
  # otherwise there is some type of error (40x,50x) and
  # we should try to raise an appropriate exception
  # from one of our exception classes defined in
  # exceptions.rb
  return false if response.is_a?(Net::HTTPSuccess)

  # parse the XML document so we can walk through it
  doc = REXML::Document.new(response.body)

  # Check that the Error element is in the place we would expect.
  # and if not raise a generic error exception
  unless doc.root.elements[1].name == "Error"
    raise Error, "Unexpected error format. response.body is: #{response.body}"
  end

  # An valid error response looks like this:
  # <?xml version="1.0"?><Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>Unknown parameter: foo</Message></Error></Errors><RequestID>291cef62-3e86-414b-900e-17246eccfae8</RequestID></Response>
  # AWS EC2 throws some exception codes that look like Error.SubError.  Since we can't name classes this way
  # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
  # non '.' name as well.
  error_code    = doc.root.elements['//ErrorResponse/Error/Code'].text.gsub('.', '')
  error_message = doc.root.elements['//ErrorResponse/Error/Message'].text

  # Raise one of our specific error classes if it exists.
  # otherwise, throw a generic EC2 Error with a few details.
  if AWS.const_defined?(error_code)
    raise AWS.const_get(error_code), error_message
  else
    raise AWS::Error, error_message
  end

end

#configure_health_check(options = {}) ⇒ Object

This API enables you to define an application healthcheck for the instances.

Note: Completion of this API does not guarantee that operation has completed. Rather, it means that the request has been registered and the changes will happen shortly.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :health_check (Hash)

    A Hash with the keys (:timeout, :interval, :unhealthy_threshold, :healthy_threshold)

  • :load_balancer_name (String)

    The name of the load balancer.

Raises:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/AWS/ELB/load_balancers.rb', line 131

def configure_health_check( options = {} )
  raise ArgumentError, "No :health_check provided" if options[:health_check].nil? || options[:health_check].empty?
  raise ArgumentError, "No :health_check => :target provided" if options[:health_check][:target].nil? || options[:health_check][:target].empty?
  raise ArgumentError, "No :health_check => :timeout provided" if options[:health_check][:timeout].nil? || options[:health_check][:timeout].empty?
  raise ArgumentError, "No :health_check => :interval provided" if options[:health_check][:interval].nil? || options[:health_check][:interval].empty?
  raise ArgumentError, "No :health_check => :unhealthy_threshold provided" if options[:health_check][:unhealthy_threshold].nil? || options[:health_check][:unhealthy_threshold].empty?
  raise ArgumentError, "No :health_check => :healthy_threshold provided" if options[:health_check][:healthy_threshold].nil? || options[:health_check][:healthy_threshold].empty?
  raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?

  params = {}

  params['LoadBalancerName'] = options[:load_balancer_name]
  params['HealthCheck.Target'] = options[:health_check][:target]
  params['HealthCheck.Timeout'] = options[:health_check][:timeout]
  params['HealthCheck.Interval'] = options[:health_check][:interval]
  params['HealthCheck.UnhealthyThreshold'] = options[:health_check][:unhealthy_threshold]
  params['HealthCheck.HealthyThreshold'] = options[:health_check][:healthy_threshold]

  return response_generator(:action => "ConfigureHealthCheck", :params => params)
end

#create_load_balancer(options = {}) ⇒ Object

This API creates a new LoadBalancer. Once the call has completed successfully, a new LoadBalancer will be created, but it will not be usable until at least one instance has been registered. When the LoadBalancer creation is completed, you can check whether it is usable by using the DescribeInstanceHealth API. The LoadBalancer is usable as soon as any registered instance is InService.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :load_balancer_name (String) — default: nil

    the name of the load balancer

  • :availability_zones (Array) — default: nil
  • :listeners (Array) — default: nil

    An Array of Hashes (:protocol, :load_balancer_port, :instance_port)

  • :availability_zones (Array) — default: nil

    An Array of Strings

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/AWS/ELB/load_balancers.rb', line 17

def create_load_balancer( options = {} )
  raise ArgumentError, "No :availability_zones provided" if options[:availability_zones].nil? || options[:availability_zones].empty?
  raise ArgumentError, "No :listeners provided" if options[:listeners].nil? || options[:listeners].empty?
  raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?

  params = {}

  params.merge!(pathlist('AvailabilityZones.member', [options[:availability_zones]].flatten))
  params.merge!(pathhashlist('Listeners.member', [options[:listeners]].flatten, {
    :protocol => 'Protocol',
    :load_balancer_port => 'LoadBalancerPort',
    :instance_port => 'InstancePort'
  }))
  params['LoadBalancerName'] = options[:load_balancer_name]

  return response_generator(:action => "CreateLoadBalancer", :params => params)
end

#default_hostObject



26
27
28
# File 'lib/AWS/ELB.rb', line 26

def default_host
  DEFAULT_HOST
end

#delete_load_balancer(options = {}) ⇒ Object

This API deletes the specified LoadBalancer. On deletion, all of the configured properties of the LoadBalancer will be deleted. If you attempt to recreate the LoadBalancer, you need to reconfigure all the settings. The DNS name associated with a deleted LoadBalancer is no longer be usable. Once deleted, the name and associated DNS record of the LoadBalancer no longer exist and traffic sent to any of its IP addresses will no longer be delivered to your instances. You will not get the same DNS name even if you create a new LoadBalancer with same LoadBalancerName.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :load_balancer_name (String)

    the name of the load balancer

Raises:



47
48
49
50
51
# File 'lib/AWS/ELB/load_balancers.rb', line 47

def delete_load_balancer( options = {} )
  raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
  params = { 'LoadBalancerName' => options[:load_balancer_name] }
  return response_generator(:action => "DeleteLoadBalancer", :params => params)
end

#deregister_instances_from_load_balancer(options = {}) ⇒ Object

This API deregisters instances from the LoadBalancer. Trying to deregister an instance that is not registered with the LoadBalancer does nothing.

In order to successfully call this API, you must provide the same account credentials as those that were used to create the LoadBalancer.

Once the instance is deregistered, it will stop receiving traffic from the LoadBalancer.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :instances (Array<String>)

    An Array of instance names to remove from the load balancer.

  • :load_balancer_name (String)

    The name of the load balancer.

Raises:



114
115
116
117
118
119
120
121
# File 'lib/AWS/ELB/load_balancers.rb', line 114

def deregister_instances_from_load_balancer( options = {} )
  raise ArgumentError, "No :instances provided" if options[:instances].nil? || options[:instances].empty?
  raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
  params = {}
  params.merge!(pathlist('Instances.member', [options[:instances]].flatten))
  params['LoadBalancerName'] = options[:load_balancer_name]
  return response_generator(:action => "DeregisterInstancesFromLoadBalancer", :params => params)
end

#describe_instance_health(options = {}) ⇒ Object

TODO:

Implement this method

Not yet implemented



156
157
158
# File 'lib/AWS/ELB/load_balancers.rb', line 156

def describe_instance_health( options = {} )
  raise "Not yet implemented"
end

#describe_load_balancers(options = {}) ⇒ Object

This API returns detailed configuration information for the specified LoadBalancers, or if no LoadBalancers are specified, then the API returns configuration information for all LoadBalancers created by the caller. For more information, please see LoadBalancer.

You must have created the specified input LoadBalancers in order to retrieve this information. In other words, in order to successfully call this API, you must provide the same account credentials as those that were used to create the LoadBalancer.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :load_balancer_names (Array<String>) — default: []

    An Array of names of load balancers to describe.



65
66
67
68
69
# File 'lib/AWS/ELB/load_balancers.rb', line 65

def describe_load_balancers( options = {} )
  options = { :load_balancer_names => [] }.merge(options)
  params = pathlist("LoadBalancerName.member", options[:load_balancer_names])
  return response_generator(:action => "DescribeLoadBalancers", :params => params)
end

#disable_availability_zones_for_load_balancer(options = {}) ⇒ Object

TODO:

Implement this method

Not yet implemented



164
165
166
# File 'lib/AWS/ELB/load_balancers.rb', line 164

def disable_availability_zones_for_load_balancer( options = {} )
  raise "Not yet implemented"
end

#enable_availability_zones_for_load_balancer(options = {}) ⇒ Object

TODO:

Implement this method

Not yet implemented



172
173
174
# File 'lib/AWS/ELB/load_balancers.rb', line 172

def enable_availability_zones_for_load_balancer( options = {} )
  raise "Not yet implemented"
end

#register_instances_with_load_balancer(options = {}) ⇒ Object

This API adds new instances to the LoadBalancer.

Once the instance is registered, it starts receiving traffic and requests from the LoadBalancer. Any instance that is not in any of the Availability Zones registered for the LoadBalancer will be moved to the OutOfService state. It will move to the InService state when the Availability Zone is added to the LoadBalancer.

You must have been the one who created the LoadBalancer. In other words, in order to successfully call this API, you must provide the same account credentials as those that were used to create the LoadBalancer.

NOTE: Completion of this API does not guarantee that operation has completed. Rather, it means that the request has been registered and the changes will happen shortly.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :instances (Array<String>)

    An Array of instance names to add to the load balancer.

  • :load_balancer_name (String)

    The name of the load balancer.

Raises:



91
92
93
94
95
96
97
98
# File 'lib/AWS/ELB/load_balancers.rb', line 91

def register_instances_with_load_balancer( options = {} )
  raise ArgumentError, "No :instances provided" if options[:instances].nil? || options[:instances].empty?
  raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
  params = {}
  params.merge!(pathhashlist('Instances.member', options[:instances].flatten.collect{|e| {:instance_id => e}}, {:instance_id => 'InstanceId'}))
  params['LoadBalancerName'] = options[:load_balancer_name]
  return response_generator(:action => "RegisterInstancesWithLoadBalancer", :params => params)
end