Class: AWS::ELB::Listener

Inherits:
Object
  • Object
show all
Includes:
Core::Model
Defined in:
lib/aws/elb/listener.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix

Constructor Details

#initialize(load_balancer, port, options = {}) ⇒ Listener

Returns a new instance of Listener.

Parameters:

  • load_balancer (LoadBalancer)

    The load balancer this listener belongs to.

  • port (Integer)

    The external load balancer port number.

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

Options Hash (options):

  • :port (Integer)

    Specifies the external load balancer port number. This property cannot be modified for the life of the LoadBalancer.

  • :protocol (String, Symbol)

    Specifies the load balancer transport protocol to use for routing. Valid values include:

  • :instance_port (Integer)

    Specifies the TCP port on which the instance server is listening. This property cannot be modified for the life of the load balancer.

  • :instance_protocol (String, Symbol)

    Specifies the protocol to use for routing traffic to back-end instances. Valid values include:

    • :http, ‘HTTP’

    • :https, ‘HTTPS’

    • :tcp, ‘TCP’

    • :ssl, ‘SSL’

    This property cannot be modified for the life of the load balacner.

    NOTE: If the front-end protocol is HTTP or HTTPS, :instance_protocol has to be at the same protocol layer, i.e., HTTP or HTTPS. Likewise, if the front-end protocol is TCP or SSL, :instance_protocol has to be TCP or SSL.

    NOTE: If there is another listener with the same :instance_port whose :instance_protocol is secure, i.e., HTTPS or SSL, the listener’s :instance_protocol has to be secure, i.e., HTTPS or SSL. If there is another listener with the same :instance_port whose :instance_protocol is HTTP or TCP, the listener’s :instance_protocol must be either HTTP or TCP.

    • :tcp, ‘TCP’

    • :http, ‘HTTP’

    This property cannot be modified for the life of the load balancer.

  • :server_certificate (String, IAM::ServerCertificate)

    The ARN string of an IAM::ServerCertifcate or an IAM::ServerCertificate object. Reqruied for HTTPs listeners.



30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#load_balancerLoadBalancer (readonly)

Returns:



43
44
45
# File 'lib/aws/elb/listener.rb', line 43

def load_balancer
  @load_balancer
end

#portInteger (readonly)

Returns:

  • (Integer)


46
47
48
# File 'lib/aws/elb/listener.rb', line 46

def port
  @port
end

Instance Method Details

#deletenil

Deletes the listener from its load balancer.

Returns:

  • (nil)


157
158
159
160
161
162
163
164
165
# 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) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


173
174
175
176
177
# 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

#exists?Boolean

Returns true if this listener exists.

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

Returns:

  • (Boolean)

    Returns true if the load balancer has a listener on this port.



149
150
151
152
153
# File 'lib/aws/elb/listener.rb', line 149

def exists?
  !_description.nil?
rescue AWS::Core::Resource::NotFound
  false
end

#inspectObject



168
169
170
# File 'lib/aws/elb/listener.rb', line 168

def inspect
  "#{self.class.name} port:#{port}>"
end

#instance_portInteger

Returns:

  • (Integer)


55
56
57
# File 'lib/aws/elb/listener.rb', line 55

def instance_port
  @instance_port || _description.listener.instance_port
end

#instance_protocolSymbol

Returns:

  • (Symbol)


60
61
62
63
# 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

#policyLoadBalancerPolicy?

Returns the current policy for this listener. Returns nil if no load balancer policy has been associated with it.

Returns:

  • (LoadBalancerPolicy, nil)

    Returns the current policy for this listener. Returns nil if no load balancer policy has been associated with it.



106
107
108
109
# 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) ⇒ LoadBalancerPolicy

Parameters:

  • policy_or_policy_name (String, LoadBalancerPolicy)

    Sets the policy for this listener.

Returns:



114
115
116
117
118
119
120
121
122
123
124
125
126
# 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

#protocolSymbol

Returns the protocl for this listener.

Returns:

  • (Symbol)

    Returns the protocl for this listener.



49
50
51
52
# File 'lib/aws/elb/listener.rb', line 49

def protocol
  proto = @protocol || _description.listener.protocol
  proto.to_s.downcase.to_sym
end

#remove_policynil

Removes the current policy from this listener.

Returns:

  • (nil)


130
131
132
133
134
135
136
137
138
139
# 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_certificateIAM::ServerCertificate?

Returns the IAM::ServerCertificate associated with this listener, or nil if there is none.

Returns:

  • (IAM::ServerCertificate, nil)

    Returns the IAM::ServerCertificate associated with this listener, or nil if there is none.



90
91
92
93
94
95
96
97
98
99
100
101
# 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) ⇒ nil

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

Parameters:

  • server_certificate (String, IAM::ServerCertificate)

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

Returns:

  • (nil)


74
75
76
77
78
79
80
81
82
83
84
85
86
# 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