mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #712 from jstremick/master
[aws|elb] Updated Load Balancers and Listeners to support the InstanceProtocol attribute
This commit is contained in:
commit
e4873182e5
5 changed files with 31 additions and 20 deletions
|
@ -4,20 +4,21 @@ module Fog
|
||||||
class ELB
|
class ELB
|
||||||
class Listener < Fog::Model
|
class Listener < Fog::Model
|
||||||
|
|
||||||
attribute :policy_names, :aliases => 'PolicyNames'
|
attribute :policy_names, :aliases => 'PolicyNames'
|
||||||
attribute :instance_port, :aliases => 'InstancePort'
|
attribute :instance_port, :aliases => 'InstancePort'
|
||||||
attribute :lb_port, :aliases => 'LoadBalancerPort'
|
attribute :instance_protocol, :aliases => 'InstanceProtocol'
|
||||||
attribute :protocol, :aliases => 'Protocol'
|
attribute :lb_port, :aliases => 'LoadBalancerPort'
|
||||||
attribute :ssl_id, :aliases => 'SSLCertificateId'
|
attribute :protocol, :aliases => 'Protocol'
|
||||||
|
attribute :ssl_id, :aliases => 'SSLCertificateId'
|
||||||
|
|
||||||
def initialize(attributes={})
|
def initialize(attributes={})
|
||||||
# set defaults, which may be overridden in super
|
# 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
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
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])
|
connection.create_load_balancer_listeners(load_balancer.id, [to_params])
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
|
@ -44,6 +45,7 @@ module Fog
|
||||||
def to_params
|
def to_params
|
||||||
{
|
{
|
||||||
'InstancePort' => instance_port,
|
'InstancePort' => instance_port,
|
||||||
|
'InstanceProtocol' => instance_protocol,
|
||||||
'LoadBalancerPort' => lb_port,
|
'LoadBalancerPort' => lb_port,
|
||||||
'Protocol' => protocol,
|
'Protocol' => protocol,
|
||||||
'SSLCertificateId' => ssl_id
|
'SSLCertificateId' => ssl_id
|
||||||
|
|
|
@ -11,9 +11,10 @@ module Fog
|
||||||
# * availability_zones<~Array> - List of availability zones for the ELB
|
# * availability_zones<~Array> - List of availability zones for the ELB
|
||||||
# * lb_name<~String> - Name for the new ELB -- must be unique
|
# * lb_name<~String> - Name for the new ELB -- must be unique
|
||||||
# * listeners<~Array> - Array of Hashes describing ELB listeners to assign to the ELB
|
# * 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
|
# * '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
|
# * '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
|
# * 'SSLCertificateId'<~String> - ARN of the server certificate
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
|
@ -28,17 +29,20 @@ module Fog
|
||||||
listener_protocol = []
|
listener_protocol = []
|
||||||
listener_lb_port = []
|
listener_lb_port = []
|
||||||
listener_instance_port = []
|
listener_instance_port = []
|
||||||
|
listener_instance_protocol = []
|
||||||
listener_ssl_certificate_id = []
|
listener_ssl_certificate_id = []
|
||||||
listeners.each do |listener|
|
listeners.each do |listener|
|
||||||
listener_protocol.push(listener['Protocol'])
|
listener_protocol.push(listener['Protocol'])
|
||||||
listener_lb_port.push(listener['LoadBalancerPort'])
|
listener_lb_port.push(listener['LoadBalancerPort'])
|
||||||
listener_instance_port.push(listener['InstancePort'])
|
listener_instance_port.push(listener['InstancePort'])
|
||||||
|
listener_instance_protocol.push(listener['InstanceProtocol'])
|
||||||
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
|
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
|
||||||
end
|
end
|
||||||
|
|
||||||
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol))
|
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.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.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))
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.SSLCertificateId', listener_ssl_certificate_id))
|
||||||
|
|
||||||
request({
|
request({
|
||||||
|
|
|
@ -10,9 +10,10 @@ module Fog
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * lb_name<~String> - Name for the new ELB -- must be unique
|
# * lb_name<~String> - Name for the new ELB -- must be unique
|
||||||
# * listeners<~Array> - Array of Hashes describing ELB listeners to add to the ELB
|
# * 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
|
# * '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
|
# * '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
|
# * 'SSLCertificateId'<~String> - ARN of the server certificate
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
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'] }
|
@availability_zones = Fog::Compute[:aws].describe_availability_zones('state' => 'available').body['availabilityZoneInfo'].collect{ |az| az['zoneName'] }
|
||||||
@key_name = 'fog-test-model'
|
@key_name = 'fog-test-model'
|
||||||
|
|
||||||
|
@ -13,15 +14,17 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
tests("default attributes") do
|
tests("default attributes") do
|
||||||
listener = Fog::AWS[:elb].listeners.new
|
listener = Fog::AWS[:elb].listeners.new
|
||||||
tests('instance_port is 80').returns(80) { listener.instance_port }
|
tests('instance_port is 80').returns(80) { listener.instance_port }
|
||||||
|
tests('instance_protocol is HTTP').returns('HTTP') { listener.instance_protocol }
|
||||||
tests('lb_port is 80').returns(80) { listener.lb_port }
|
tests('lb_port is 80').returns(80) { listener.lb_port }
|
||||||
tests('protocol is HTTP').returns('HTTP') { listener.protocol }
|
tests('protocol is HTTP').returns('HTTP') { listener.protocol }
|
||||||
tests('policy_names is empty').returns([]) { listener.policy_names }
|
tests('policy_names is empty').returns([]) { listener.policy_names }
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("specifying attributes") do
|
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)
|
listener = Fog::AWS[:elb].listeners.new(attributes)
|
||||||
tests('instance_port is 2000').returns(2000) { listener.instance_port }
|
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('lb_port is 2001').returns(2001) { listener.lb_port }
|
||||||
tests('protocol is SSL').returns('SSL') { listener.protocol }
|
tests('protocol is SSL').returns('SSL') { listener.protocol }
|
||||||
tests('policy_names is [ fake ]').returns(['fake']) { listener.policy_names }
|
tests('policy_names is [ fake ]').returns(['fake']) { listener.policy_names }
|
||||||
|
@ -62,7 +65,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
'PolicyNames' => []
|
'PolicyNames' => []
|
||||||
}, {
|
}, {
|
||||||
'Listener' => {
|
'Listener' => {
|
||||||
'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS',
|
'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS',
|
||||||
'SSLCertificateId' => @certificate['Arn']
|
'SSLCertificateId' => @certificate['Arn']
|
||||||
},
|
},
|
||||||
'PolicyNames' => []
|
'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('lb_port is 2030').returns(2030) { elb3.listeners.first.lb_port }
|
||||||
tests('protocol is HTTP').returns('HTTP') { elb3.listeners.first.protocol }
|
tests('protocol is HTTP').returns('HTTP') { elb3.listeners.first.protocol }
|
||||||
tests('protocol is HTTPS').returns('HTTPS') { elb3.listeners.last.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
|
elb3.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('with invalid Server Cert ARN').raises(Fog::AWS::IAM::NotFound) do
|
tests('with invalid Server Cert ARN').raises(Fog::AWS::IAM::NotFound) do
|
||||||
listeners = [{
|
listeners = [{
|
||||||
'Listener' => {
|
'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)
|
Fog::AWS[:elb].load_balancers.create(:id => "#{elb_id}-4", "ListenerDescriptions" => listeners, :availability_zones => @availability_zones)
|
||||||
end
|
end
|
||||||
|
@ -178,7 +182,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
returns(1) { elb.listeners.size }
|
returns(1) { elb.listeners.size }
|
||||||
|
|
||||||
listener = elb.listeners.first
|
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
|
end
|
||||||
|
|
||||||
tests('#get') do
|
tests('#get') do
|
||||||
|
@ -186,8 +190,8 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('create') do
|
tests('create') do
|
||||||
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
|
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP', 'InstanceProtocol' => 'TCP'}
|
||||||
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP')
|
elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP', :instance_protocol => 'TCP')
|
||||||
returns(2) { elb.listeners.size }
|
returns(2) { elb.listeners.size }
|
||||||
returns(443) { elb.listeners.get(443).lb_port }
|
returns(443) { elb.listeners.get(443).lb_port }
|
||||||
end
|
end
|
||||||
|
@ -245,7 +249,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('setting a new ssl certificate id') do
|
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'])
|
elb.set_listener_ssl_certificate(443, @certificate['Arn'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do
|
||||||
|
|
||||||
tests("#create_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do
|
tests("#create_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do
|
||||||
listeners = [
|
listeners = [
|
||||||
{'Protocol' => 'TCP', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']},
|
{'Protocol' => 'TCP','InstanceProtocol' => 'TCP', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']},
|
||||||
{'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80}
|
{'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80}
|
||||||
]
|
]
|
||||||
response = Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
response = Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
||||||
|
@ -22,7 +22,7 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do
|
||||||
|
|
||||||
tests("#create_load_balancer_listeners with non-existant SSL certificate") do
|
tests("#create_load_balancer_listeners with non-existant SSL certificate") do
|
||||||
listeners = [
|
listeners = [
|
||||||
{'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => 'non-existant'},
|
{'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => 'non-existant'},
|
||||||
]
|
]
|
||||||
raises(Fog::AWS::IAM::NotFound) { Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners) }
|
raises(Fog::AWS::IAM::NotFound) { Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners) }
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do
|
||||||
tests("#create_load_balancer_listeners with invalid SSL certificate").raises(Fog::AWS::IAM::NotFound) do
|
tests("#create_load_balancer_listeners with invalid SSL certificate").raises(Fog::AWS::IAM::NotFound) do
|
||||||
sleep 8 unless Fog.mocking?
|
sleep 8 unless Fog.mocking?
|
||||||
listeners = [
|
listeners = [
|
||||||
{'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => "#{@certificate['Arn']}fake"},
|
{'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => "#{@certificate['Arn']}fake"},
|
||||||
]
|
]
|
||||||
Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do
|
||||||
tests("#create_load_balancer_listeners with SSL certificate").formats(AWS::ELB::Formats::BASIC) do
|
tests("#create_load_balancer_listeners with SSL certificate").formats(AWS::ELB::Formats::BASIC) do
|
||||||
sleep 8 unless Fog.mocking?
|
sleep 8 unless Fog.mocking?
|
||||||
listeners = [
|
listeners = [
|
||||||
{'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']},
|
{'Protocol' => 'HTTPS', 'InstanceProtocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']},
|
||||||
]
|
]
|
||||||
Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
Fog::AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue