1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[AWS|ELB] Added support for InstanceProtocol to listeners

This commit is contained in:
James Stremick 2012-01-22 20:00:48 -05:00
parent bf0c720370
commit 0500be0532
4 changed files with 30 additions and 16 deletions

View file

@ -4,20 +4,21 @@ module Fog
class ELB
class Listener < Fog::Model
attribute :policy_names, :aliases => 'PolicyNames'
attribute :instance_port, :aliases => 'InstancePort'
attribute :lb_port, :aliases => 'LoadBalancerPort'
attribute :protocol, :aliases => 'Protocol'
attribute :ssl_id, :aliases => 'SSLCertificateId'
attribute :policy_names, :aliases => 'PolicyNames'
attribute :instance_port, :aliases => 'InstancePort'
attribute :instance_protocol, :aliases => 'InstanceProtocol'
attribute :lb_port, :aliases => 'LoadBalancerPort'
attribute :protocol, :aliases => 'Protocol'
attribute :ssl_id, :aliases => 'SSLCertificateId'
def initialize(attributes={})
# set defaults, which may be overridden in super
merge_attributes(:policy_names => [], :instance_port => 80, :lb_port => 80, :protocol => 'HTTP')
merge_attributes(:policy_names => [], :instance_port => 80, :instance_protocol => 'HTTP', :lb_port => 80, :protocol => 'HTTP')
super
end
def save
requires :load_balancer, :instance_port, :lb_port, :protocol
requires :load_balancer, :instance_port, :lb_port, :protocol, :instance_protocol
connection.create_load_balancer_listeners(load_balancer.id, [to_params])
reload
end
@ -44,6 +45,7 @@ module Fog
def to_params
{
'InstancePort' => instance_port,
'InstanceProtocol' => instance_protocol,
'LoadBalancerPort' => lb_port,
'Protocol' => protocol,
'SSLCertificateId' => ssl_id

View file

@ -11,9 +11,10 @@ module Fog
# * 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.
# * 'Protocol'<~String> - Protocol to use. Either HTTP, HTTPS, TCP or SSL.
# * '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
# * 'InstanceProtocol'<~String> - Protocol for sending traffic to an instance. Either HTTP, HTTPS, TCP or SSL.
# * 'SSLCertificateId'<~String> - ARN of the server certificate
# ==== Returns
# * response<~Excon::Response>:
@ -28,17 +29,20 @@ module Fog
listener_protocol = []
listener_lb_port = []
listener_instance_port = []
listener_instance_protocol = []
listener_ssl_certificate_id = []
listeners.each do |listener|
listener_protocol.push(listener['Protocol'])
listener_lb_port.push(listener['LoadBalancerPort'])
listener_instance_port.push(listener['InstancePort'])
listener_instance_protocol.push(listener['InstanceProtocol'])
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
end
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.LoadBalancerPort', listener_lb_port))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstancePort', listener_instance_port))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstanceProtocol', listener_instance_protocol))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.SSLCertificateId', listener_ssl_certificate_id))
request({

View file

@ -10,9 +10,10 @@ module Fog
# ==== Parameters
# * lb_name<~String> - Name for the new ELB -- must be unique
# * listeners<~Array> - Array of Hashes describing ELB listeners to add to the ELB
# * 'Protocol'<~String> - Protocol to use. Either HTTP or TCP.
# * 'Protocol'<~String> - Protocol to use. Either HTTP, HTTPS, TCP or SSL.
# * '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
# * 'InstanceProtocol'<~String> - Protocol for sending traffic to an instance. Either HTTP, HTTPS, TCP or SSL.
# * 'SSLCertificateId'<~String> - ARN of the server certificate
# ==== Returns
# * response<~Excon::Response>:
@ -25,17 +26,20 @@ module Fog
listener_protocol = []
listener_lb_port = []
listener_instance_port = []
listener_instance_protocol = []
listener_ssl_certificate_id = []
listeners.each do |listener|
listener_protocol.push(listener['Protocol'])
listener_lb_port.push(listener['LoadBalancerPort'])
listener_instance_port.push(listener['InstancePort'])
listener_instance_protocol.push(listener['InstanceProtocol'])
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
end
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.LoadBalancerPort', listener_lb_port))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstancePort', listener_instance_port))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstanceProtocol', listener_instance_protocol))
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.SSLCertificateId', listener_ssl_certificate_id))
request({

View file

@ -1,4 +1,5 @@
Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
require 'fog'
@availability_zones = Fog::Compute[:aws].describe_availability_zones('state' => 'available').body['availabilityZoneInfo'].collect{ |az| az['zoneName'] }
@key_name = 'fog-test-model'
@ -13,15 +14,17 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
tests("default attributes") do
listener = Fog::AWS[:elb].listeners.new
tests('instance_port is 80').returns(80) { listener.instance_port }
tests('instance_protocol is HTTP').returns(80) { listener.instance_protocol }
tests('lb_port is 80').returns(80) { listener.lb_port }
tests('protocol is HTTP').returns('HTTP') { listener.protocol }
tests('policy_names is empty').returns([]) { listener.policy_names }
end
tests("specifying attributes") do
attributes = {:instance_port => 2000, :lb_port => 2001, :protocol => 'SSL', :policy_names => ['fake'] }
attributes = {:instance_port => 2000, :instance_protocol => 'SSL', :lb_port => 2001, :protocol => 'SSL', :policy_names => ['fake'] }
listener = Fog::AWS[:elb].listeners.new(attributes)
tests('instance_port is 2000').returns(2000) { listener.instance_port }
tests('instance_protocol is SSL').returns('SSL') { listener.instance_protocol }
tests('lb_port is 2001').returns(2001) { listener.lb_port }
tests('protocol is SSL').returns('SSL') { listener.protocol }
tests('policy_names is [ fake ]').returns(['fake']) { listener.policy_names }
@ -62,7 +65,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
'PolicyNames' => []
}, {
'Listener' => {
'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS',
'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS',
'SSLCertificateId' => @certificate['Arn']
},
'PolicyNames' => []
@ -73,13 +76,14 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
tests('lb_port is 2030').returns(2030) { elb3.listeners.first.lb_port }
tests('protocol is HTTP').returns('HTTP') { elb3.listeners.first.protocol }
tests('protocol is HTTPS').returns('HTTPS') { elb3.listeners.last.protocol }
tests('instance_protocol is HTTPS').returns('HTTPS') { elb3.listeners.last.instance_protocol }
elb3.destroy
end
tests('with invalid Server Cert ARN').raises(Fog::AWS::IAM::NotFound) do
listeners = [{
'Listener' => {
'LoadBalancerPort' => 443, 'InstancePort' => 80, 'Protocol' => 'HTTPS', "SSLCertificateId" => "fakecert"}
'LoadBalancerPort' => 443, 'InstancePort' => 80, 'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS', "SSLCertificateId" => "fakecert"}
}]
Fog::AWS[:elb].load_balancers.create(:id => "#{elb_id}-4", "ListenerDescriptions" => listeners, :availability_zones => @availability_zones)
end
@ -178,7 +182,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
returns(1) { elb.listeners.size }
listener = elb.listeners.first
returns([80,80,'HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.policy_names] }
returns([80,80,'HTTP','HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.instance_protocol, listener.policy_names] }
end
tests('#get') do
@ -186,8 +190,8 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
end
tests('create') do
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP')
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP', 'InstanceProtocol' => 'TCP'}
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP', :instance_protocol => 'TCP')
returns(2) { elb.listeners.size }
returns(443) { elb.listeners.get(443).lb_port }
end
@ -245,7 +249,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
end
tests('setting a new ssl certificate id') do
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'HTTPS', :ssl_id => @certificate['Arn'])
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'HTTPS', :instance_protocol => 'HTTPS', :ssl_id => @certificate['Arn'])
elb.set_listener_ssl_certificate(443, @certificate['Arn'])
end