Class: Fog::AWS::ELB::Real

Inherits:
Object
  • Object
show all
Includes:
Collections
Defined in:
lib/fog/aws/elb.rb,
lib/fog/aws/requests/elb/create_load_balancer.rb,
lib/fog/aws/requests/elb/delete_load_balancer.rb,
lib/fog/aws/requests/elb/describe_load_balancers.rb,
lib/fog/aws/requests/elb/describe_instance_health.rb,
lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb,
lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb,
lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb,
lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Initialize connection to ELB

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

elb = ELB.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

    • region<~String> - optional region to use, in [‘eu-west-1’, ‘us-east-1’, ‘us-west-1’i, ‘ap-southeast-1’]

Returns

  • ELB object with connection to AWS.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/aws/elb.rb', line 48

def initialize(options={})
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
  @host = options[:host] || case options[:region]
  when 'ap-southeast-1'
    'elasticloadbalancing.ap-southeast-1.amazonaws.com'
  when 'eu-west-1'
    'elasticloadbalancing.eu-west-1.amazonaws.com'
  when 'us-east-1'
    'elasticloadbalancing.us-east-1.amazonaws.com'
  when 'us-west-1'
    'elasticloadbalancing.us-west-1.amazonaws.com'
  else
    'elasticloadbalancing.amazonaws.com'
  end
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

Instance Method Details

#create_load_balancer(availability_zones, lb_name, listeners) ⇒ Object

Create a new Elastic Load Balancer

Parameters

  • availability_zones<~Array> - List of availability zones for the ELB

  • lb_name<~String> - Name for the new ELB – must be unique

  • listeners<~Array> - Array of Hashes describing ELB listeners to assign to the ELB

    • ‘Protocol’<~String> - Protocol to use. Either HTTP or TCP.

    • ‘LoadBalancerPort’<~Integer> - The port that the ELB will listen to for outside traffic

    • ‘InstancePort’<~Integer> - The port on the instance that the ELB will forward traffic to

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘CreateLoadBalancerResult’<~Hash>:

        • ‘DNSName’<~String> - DNS name for the newly created ELB



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/aws/requests/elb/create_load_balancer.rb', line 24

def create_load_balancer(availability_zones, lb_name, listeners)
  params = ELB.indexed_param('AvailabilityZones.member', [*availability_zones], 1)

  listener_protocol = []
  listener_lb_port = []
  listener_instance_port = []
  listeners.each do |listener|
    listener_protocol.push(listener['Protocol'])
    listener_lb_port.push(listener['LoadBalancerPort'])
    listener_instance_port.push(listener['InstancePort'])
  end

  params.merge!(AWS.indexed_param('Listeners.member.%.Protocol', listener_protocol, 1))
  params.merge!(AWS.indexed_param('Listeners.member.%.LoadBalancerPort', listener_lb_port, 1))
  params.merge!(AWS.indexed_param('Listeners.member.%.InstancePort', listener_instance_port, 1))

  request({
    'Action'           => 'CreateLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new
  }.merge!(params))
end

#delete_load_balancer(lb_name) ⇒ Object

Delete an existing Elastic Load Balancer

Note that this API call, as defined by Amazon, is idempotent. That is, it will not return an error if you try to delete an ELB that does not exist.

Parameters

  • lb_name<~String> - Name of the ELB to be deleted

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘DeleteLoadBalancerResponse’<~nil>

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request



22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/elb/delete_load_balancer.rb', line 22

def delete_load_balancer(lb_name)
  request({
    'Action'           => 'DeleteLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::DeleteLoadBalancer.new
  })
end

#deregister_instances_from_load_balancer(instance_ids, lb_name) ⇒ Object Also known as: deregister_instances

Deregister an instance from an existing ELB

Parameters

  • instance_ids<~Array> - List of instance IDs to remove from ELB

  • lb_name<~String> - Load balancer to remove instances from

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DeregisterInstancesFromLoadBalancerResult’<~Hash>:

        • ‘Instances’<~Array> - array of hashes describing instances currently enabled

          • ‘InstanceId’<~String>



22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb', line 22

def deregister_instances_from_load_balancer(instance_ids, lb_name)
  params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
  request({
    'Action'           => 'DeregisterInstancesFromLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::DeregisterInstancesFromLoadBalancer.new
  }.merge!(params))
end

#describe_instance_health(lb_name, instance_ids = []) ⇒ Object

Get health status for one or more instances on an existing ELB

Parameters

  • lb_name<~String> - Load balancer to check instances health on

  • instance_ids<~Array> - Optional list of instance IDs to check

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DescribeInstanceHealthResult’<~Hash>:

        • ‘InstanceStates’<~Array> - array of hashes describing instance health

          • ‘Description’<~String>

          • ‘State’<~String>

          • ‘InstanceId’<~String>

          • ‘ReasonCode’<~String>



25
26
27
28
29
30
31
32
# File 'lib/fog/aws/requests/elb/describe_instance_health.rb', line 25

def describe_instance_health(lb_name, instance_ids = [])
  params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
  request({
    'Action'           => 'DescribeInstanceHealth',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::DescribeInstanceHealth.new
  }.merge!(params))
end

#describe_load_balancers(lb_name = []) ⇒ Object

Describe all or specified load balancers

Parameters

  • lb_name<~Array> - List of load balancer names to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DescribeLoadBalancersResult’<~Hash>:

        • ‘LoadBalancerDescriptions’<~Array>

          • ‘LoadBalancerName’<~String> - name of load balancer

          • ‘DNSName’<~String> - external DNS name of load balancer

          • ‘CreatedTime’<~Time> - time load balancer was created

          • ‘ListenerDescriptions’<~Array>

            • ‘PolicyNames’<~Array> - list of policies enabled

            • ‘Listener’<~Hash>:

              • ‘InstancePort’<~Integer> - port on instance that requests are sent to

              • ‘Protocol’<~String> - transport protocol used for routing in [TCP, HTTP]

              • ‘LoadBalancerPort’<~Integer> - port that load balancer listens on for requests

          • ‘HealthCheck’<~Hash>:

            • ‘HealthyThreshold’<~Integer> - number of consecutive health probe successes required before moving the instance to the Healthy state

            • ‘Timeout’<~Integer> - number of seconds after which no response means a failed health probe

            • ‘Interval’<~Integer> - interval (in seconds) between health checks of an individual instance

            • ‘UnhealthyThreshold’<~Integer> - number of consecutive health probe failures that move the instance to the unhealthy state

            • ‘Target’<~String> - string describing protocol type, port and URL to check

          • ‘Policies’<~Hash>:

            • ‘LBCookieStickinessPolicies’<~Array> - list of Load Balancer Generated Cookie Stickiness policies for the LoadBalancer

            • ‘AppCookieStickinessPolicies’<~Array> - list of Application Generated Cookie Stickiness policies for the LoadBalancer

          • ‘AvailabilityZones’<~Array> - list of availability zones covered by this load balancer

          • ‘Instances’<~Array> - list of instances that the load balancer balances between



40
41
42
43
44
45
46
# File 'lib/fog/aws/requests/elb/describe_load_balancers.rb', line 40

def describe_load_balancers(lb_name = [])
  params = AWS.indexed_param('LoadBalancerNames.member', [*lb_name], 1)
  request({
    'Action'  => 'DescribeLoadBalancers',
    :parser   => Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new
  }.merge!(params))
end

#disable_availability_zones_for_load_balancer(availability_zones, lb_name) ⇒ Object Also known as: disable_zones

Disable an availability zone for an existing ELB

Parameters

  • availability_zones<~Array> - List of availability zones to disable on ELB

  • lb_name<~String> - Load balancer to disable availability zones on

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DisableAvailabilityZonesForLoadBalancerResult’<~Hash>:

        • ‘AvailabilityZones’<~Array> - array of strings describing instances currently enabled



21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb', line 21

def disable_availability_zones_for_load_balancer(availability_zones, lb_name)
  params = AWS.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
  request({
    'Action'           => 'DisableAvailabilityZonesForLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::DisableAvailabilityZonesForLoadBalancer.new
  }.merge!(params))
end

#enable_availability_zones_for_load_balancer(availability_zones, lb_name) ⇒ Object Also known as: enable_zones

Enable an availability zone for an existing ELB

Parameters

  • availability_zones<~Array> - List of availability zones to enable on ELB

  • lb_name<~String> - Load balancer to enable availability zones on

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘EnableAvailabilityZonesForLoadBalancerResult’<~Hash>:

        • ‘AvailabilityZones’<~Array> - array of strings describing instances currently enabled



21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb', line 21

def enable_availability_zones_for_load_balancer(availability_zones, lb_name)
  params = AWS.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
  request({
    'Action'           => 'EnableAvailabilityZonesForLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::EnableAvailabilityZonesForLoadBalancer.new
  }.merge!(params))
end

#register_instances_with_load_balancer(instance_ids, lb_name) ⇒ Object Also known as: register_instances

Register an instance with an existing ELB

Parameters

  • instance_ids<~Array> - List of instance IDs to associate with ELB

  • lb_name<~String> - Load balancer to assign instances to

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘RegisterInstancesWithLoadBalancerResult’<~Hash>:

        • ‘Instances’<~Array> - array of hashes describing instances currently enabled

          • ‘InstanceId’<~String>



22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb', line 22

def register_instances_with_load_balancer(instance_ids, lb_name)
  params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
  request({
    'Action'           => 'RegisterInstancesWithLoadBalancer',
    'LoadBalancerName' => lb_name,
    :parser            => Fog::Parsers::AWS::ELB::RegisterInstancesWithLoadBalancer.new
  }.merge!(params))
end

#reloadObject



69
70
71
# File 'lib/fog/aws/elb.rb', line 69

def reload
  @connection.reset
end