class AWS::ELB::Listener

Attributes

load_balancer[R]

@return [LoadBalancer]

port[R]

@return [Integer]

Public Class Methods

new(load_balancer, port, options = {}) click to toggle source

@param [LoadBalancer] #load_balancer The load balancer this listener

belongs to.

@param [Integer] port The external load balancer port number.

@param [Hash] options

@option (see AWS::ELB::ListenerCollection#create)

# File lib/aws/elb/listener.rb, line 30
def initialize load_balancer, port, options = {}

  @load_balancer = load_balancer
  @port = port.to_i
  @protocol = options[:protocol]
  @instance_port = options[:instance_port]
  @instance_protocol = options[:instance_protocol]

  super

end

Public Instance Methods

==(other) click to toggle source
Alias for: eql?
delete() click to toggle source

Deletes the listener from its load balancer. @return [nil]

# File lib/aws/elb/listener.rb, line 157
def delete

  client.delete_load_balancer_listeners(
    :load_balancer_name => load_balancer.name,
    :load_balancer_ports => [port])

  nil

end
eql?(other) click to toggle source

@private

# File lib/aws/elb/listener.rb, line 173
def eql? other
  other.is_a?(Listener) and 
  other.load_balancer == load_balancer and
  other.port == port
end
Also aliased as: ==
exists?() click to toggle source

Returns true if this listener exists.

load_balancer = ELB.new.load_balancers['my-load-balancer']
listener = load_balancer.listeners[80] # port 80
listener.exists?

@return [Boolean] Returns true if the load balancer has a listener

on this port.
# File lib/aws/elb/listener.rb, line 149
def exists?
  !_description.nil?
rescue AWS::Core::Resource::NotFound
  false
end
inspect() click to toggle source

@private

# File lib/aws/elb/listener.rb, line 168
def inspect
  "#{self.class.name} port:#{port}>"
end
instance_port() click to toggle source

@return [Integer]

# File lib/aws/elb/listener.rb, line 55
def instance_port
  @instance_port || _description.listener.instance_port
end
instance_protocol() click to toggle source

@return [Symbol]

# File lib/aws/elb/listener.rb, line 60
def instance_protocol
  proto = @instance_protocol || _description.listener.instance_protocol
  proto.to_s.downcase.to_sym
end
policy() click to toggle source

@return [LoadBalancerPolicy,nil] Returns the current policy for this

listener.  Returns nil if no load balancer policy has been 
associated with it.
# File lib/aws/elb/listener.rb, line 106
def policy
  policy_name = _description.policy_names.first
  policy_name ? load_balancer.policies[policy_name] : nil
end
policy=(policy_or_policy_name) click to toggle source

@param [String,LoadBalancerPolicy] policy_or_policy_name Sets

the policy for this listener.

@return [LoadBalancerPolicy]

# File lib/aws/elb/listener.rb, line 114
def policy= policy_or_policy_name

  policy_name = policy_or_policy_name.is_a?(LoadBalancerPolicy) ?
    policy_or_policy_name.name : policy_or_policy_name.to_s

  client.set_load_balancer_policies_of_listener(
    :load_balancer_name => load_balancer.name,
    :load_balancer_port => port,
    :policy_names => [policy_name])

  LoadBalancerPolicy.new(load_balancer, policy_name, :config => config)

end
protocol() click to toggle source

@return [Symbol] Returns the protocl for this listener.

# File lib/aws/elb/listener.rb, line 49
def protocol
  proto = @protocol || _description.listener.protocol
  proto.to_s.downcase.to_sym
end
remove_policy() click to toggle source

Removes the current policy from this listener. @return [nil]

# File lib/aws/elb/listener.rb, line 130
def remove_policy

  client.set_load_balancer_policies_of_listener(
    :load_balancer_name => load_balancer.name,
    :load_balancer_port => port,
    :policy_names => [])

  nil

end
server_certificate() click to toggle source

@return [IAM::ServerCertificate,nil] Returns the IAM::ServerCertificate

associated with this listener, or nil if there is none.
# File lib/aws/elb/listener.rb, line 90
def server_certificate
  desc = _description
  if desc.listener.respond_to?(:ssl_certificate_id)
    AWS.memoize do
      arn = desc.listener.ssl_certificate_id
      iam = IAM.new(:config => config)
      iam.server_certificates.find{|cert| cert.arn == arn }
    end
  else
    nil
  end
end
server_certificate=(server_certificate) click to toggle source

Sets the certificate that terminates the specified listener’s SSL connections. The specified certificate replaces any prior certificate for this listener.

@param [String,IAM::ServerCertificate] #server_certificate The ARN

of an IAM::ServerCertificate or an IAM::ServerCertificate object.

@return [nil]

# File lib/aws/elb/listener.rb, line 74
def server_certificate= server_certificate

  arn = server_certificate.is_a?(IAM::ServerCertificate) ?
    server_certificate.arn : server_certificate

  client.set_load_balancer_listener_ssl_certificate(
    :load_balancer_name => load_balancer.name,
    :load_balancer_port => port,
    :ssl_certificate_id => arn)

  nil

end

Protected Instance Methods

_description() click to toggle source
# File lib/aws/elb/listener.rb, line 181
def _description
  load_balancer.listener_descriptions.find do |desc| 
    desc.listener.load_balancer_port == port
  end
end