mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #534 from KevinLoiseau/enhance/add_service_elbv2_to_handle_specificities
Create service ELBV2 to handle specificities of 2015-12-01 API version
This commit is contained in:
commit
401e86ef22
10 changed files with 372 additions and 1 deletions
|
@ -26,6 +26,7 @@ module Fog
|
||||||
autoload :ECS, File.expand_path('../aws/ecs', __FILE__)
|
autoload :ECS, File.expand_path('../aws/ecs', __FILE__)
|
||||||
autoload :EFS, File.expand_path('../aws/efs', __FILE__)
|
autoload :EFS, File.expand_path('../aws/efs', __FILE__)
|
||||||
autoload :ELB, File.expand_path('../aws/elb', __FILE__)
|
autoload :ELB, File.expand_path('../aws/elb', __FILE__)
|
||||||
|
autoload :ELBV2, File.expand_path('../aws/elbv2', __FILE__)
|
||||||
autoload :EMR, File.expand_path('../aws/emr', __FILE__)
|
autoload :EMR, File.expand_path('../aws/emr', __FILE__)
|
||||||
autoload :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
|
autoload :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
|
||||||
autoload :Elasticache, File.expand_path('../aws/elasticache', __FILE__)
|
autoload :Elasticache, File.expand_path('../aws/elasticache', __FILE__)
|
||||||
|
@ -58,6 +59,7 @@ module Fog
|
||||||
service(:ecs, 'ECS')
|
service(:ecs, 'ECS')
|
||||||
service(:efs, 'EFS')
|
service(:efs, 'EFS')
|
||||||
service(:elb, 'ELB')
|
service(:elb, 'ELB')
|
||||||
|
service(:elbv2, 'ELBV2')
|
||||||
service(:emr, 'EMR')
|
service(:emr, 'EMR')
|
||||||
service(:federation, 'Federation')
|
service(:federation, 'Federation')
|
||||||
service(:glacier, 'Glacier')
|
service(:glacier, 'Glacier')
|
||||||
|
|
|
@ -142,7 +142,7 @@ module Fog
|
||||||
@port = options[:port] || 443
|
@port = options[:port] || 443
|
||||||
@scheme = options[:scheme] || 'https'
|
@scheme = options[:scheme] || 'https'
|
||||||
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
||||||
@version = options[:version] || '2012-06-01'
|
@version ||= options[:version] || '2012-06-01'
|
||||||
|
|
||||||
setup_credentials(options)
|
setup_credentials(options)
|
||||||
end
|
end
|
||||||
|
|
17
lib/fog/aws/elbv2.rb
Normal file
17
lib/fog/aws/elbv2.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class ELBV2 < ELB
|
||||||
|
request_path 'fog/aws/requests/elbv2'
|
||||||
|
request :describe_load_balancers
|
||||||
|
request :describe_listeners
|
||||||
|
|
||||||
|
class Real < ELB::Real
|
||||||
|
def initialize(options={})
|
||||||
|
@version = '2015-12-01'
|
||||||
|
|
||||||
|
super(options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
57
lib/fog/aws/parsers/elbv2/describe_listeners.rb
Normal file
57
lib/fog/aws/parsers/elbv2/describe_listeners.rb
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
module Fog
|
||||||
|
module Parsers
|
||||||
|
module AWS
|
||||||
|
module ELBV2
|
||||||
|
class DescribeListeners < Fog::Parsers::Base
|
||||||
|
def reset
|
||||||
|
reset_listener
|
||||||
|
@default_action = {}
|
||||||
|
@results = { 'Listeners' => [] }
|
||||||
|
@response = { 'DescribeListenersResult' => {}, 'ResponseMetadata' => {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_listener
|
||||||
|
@listener= { 'DefaultActions' => [] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_element(name, attrs = [])
|
||||||
|
super
|
||||||
|
case name
|
||||||
|
when 'DefaultActions'
|
||||||
|
@in_default_actions = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_element(name)
|
||||||
|
case name
|
||||||
|
when 'member'
|
||||||
|
if @in_default_actions
|
||||||
|
@listener['DefaultActions'] << @default_action
|
||||||
|
@default_action = {}
|
||||||
|
else
|
||||||
|
@results['Listeners'] << @listener
|
||||||
|
reset_listener
|
||||||
|
end
|
||||||
|
when 'LoadBalancerArn', 'Protocol', 'Port', 'ListenerArn'
|
||||||
|
@listener[name] = value
|
||||||
|
when 'Type', 'TargetGroupArn'
|
||||||
|
@default_action[name] = value
|
||||||
|
|
||||||
|
when 'DefaultActions'
|
||||||
|
@in_default_actions = false
|
||||||
|
|
||||||
|
when 'RequestId'
|
||||||
|
@response['ResponseMetadata'][name] = value
|
||||||
|
|
||||||
|
when 'NextMarker'
|
||||||
|
@results['NextMarker'] = value
|
||||||
|
|
||||||
|
when 'DescribeListenersResponse'
|
||||||
|
@response['DescribeListenersResult'] = @results
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
84
lib/fog/aws/parsers/elbv2/describe_load_balancers.rb
Normal file
84
lib/fog/aws/parsers/elbv2/describe_load_balancers.rb
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
module Fog
|
||||||
|
module Parsers
|
||||||
|
module AWS
|
||||||
|
module ELBV2
|
||||||
|
class DescribeLoadBalancers < Fog::Parsers::Base
|
||||||
|
def reset
|
||||||
|
reset_load_balancer
|
||||||
|
@availability_zone = { 'LoadBalancerAddresses' => [] }
|
||||||
|
@load_balancer_addresses = {}
|
||||||
|
@state = {}
|
||||||
|
@results = { 'LoadBalancers' => [] }
|
||||||
|
@response = { 'DescribeLoadBalancersResult' => {}, 'ResponseMetadata' => {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_load_balancer
|
||||||
|
@load_balancer = { 'SecurityGroups' => [], 'AvailabilityZones' => [] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_element(name, attrs = [])
|
||||||
|
super
|
||||||
|
case name
|
||||||
|
when 'AvailabilityZones'
|
||||||
|
@in_availability_zones = true
|
||||||
|
when 'LoadBalancerAddresses'
|
||||||
|
@in_load_balancer_addresses = true
|
||||||
|
when 'SecurityGroups'
|
||||||
|
@in_security_groups = true
|
||||||
|
when 'State'
|
||||||
|
@in_state = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_element(name)
|
||||||
|
case name
|
||||||
|
when 'member'
|
||||||
|
if @in_availability_zones && @in_load_balancer_addresses
|
||||||
|
@availability_zone['LoadBalancerAddresses'] << @load_balancer_addresses
|
||||||
|
elsif @in_availability_zones
|
||||||
|
@load_balancer['AvailabilityZones'] << @availability_zone
|
||||||
|
@availability_zone = {}
|
||||||
|
elsif @in_security_groups
|
||||||
|
@load_balancer['SecurityGroups'] << value
|
||||||
|
else
|
||||||
|
@results['LoadBalancers'] << @load_balancer
|
||||||
|
reset_load_balancer
|
||||||
|
end
|
||||||
|
when 'SubnetId', 'ZoneName'
|
||||||
|
@availability_zone[name] = value
|
||||||
|
when 'IpAddress', 'AllocationId'
|
||||||
|
@load_balancer_addresses[name] = value
|
||||||
|
|
||||||
|
when 'CanonicalHostedZoneName', 'CanonicalHostedZoneNameID', 'LoadBalancerName', 'DNSName', 'Scheme', 'Type',
|
||||||
|
'LoadBalancerArn', 'IpAddressType', 'CanonicalHostedZoneId', 'VpcId'
|
||||||
|
@load_balancer[name] = value
|
||||||
|
when 'CreatedTime'
|
||||||
|
@load_balancer[name] = Time.parse(value)
|
||||||
|
|
||||||
|
when 'LoadBalancerAddresses'
|
||||||
|
@in_load_balancer_addresses = false
|
||||||
|
when 'AvailabilityZones'
|
||||||
|
@in_availability_zones = false
|
||||||
|
when 'SecurityGroups'
|
||||||
|
@in_security_groups = false
|
||||||
|
when 'State'
|
||||||
|
@in_state = false
|
||||||
|
@load_balancer[name] = @state
|
||||||
|
@state = {}
|
||||||
|
when 'Code'
|
||||||
|
@state[name] = value
|
||||||
|
|
||||||
|
when 'RequestId'
|
||||||
|
@response['ResponseMetadata'][name] = value
|
||||||
|
|
||||||
|
when 'NextMarker'
|
||||||
|
@results['NextMarker'] = value
|
||||||
|
when 'DescribeLoadBalancersResponse'
|
||||||
|
@response['DescribeLoadBalancersResult'] = @results
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
38
lib/fog/aws/requests/elbv2/describe_listeners.rb
Normal file
38
lib/fog/aws/requests/elbv2/describe_listeners.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class ELBV2
|
||||||
|
class Real
|
||||||
|
require 'fog/aws/parsers/elbv2/describe_listeners'
|
||||||
|
|
||||||
|
# Describe all or specified load balancers
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'LoadBalancerArn'<~String> - The Amazon Resource Name (ARN) of the load balancer
|
||||||
|
# * options<~Hash>
|
||||||
|
# * 'Marker'<String> - Indicates where to begin in your list of load balancers
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'ResponseMetadata'<~Hash>:
|
||||||
|
# * 'RequestId'<~String> - Id of request
|
||||||
|
# * 'DescribeListenersResult'<~Hash>:
|
||||||
|
# * 'Listeners'<~Array>
|
||||||
|
# * 'LoadBalancerArn'<~String> - The Amazon Resource Name (ARN) of the load balancer
|
||||||
|
# * 'Protocol'<~String> - The protocol for connections from clients to the load balancer
|
||||||
|
# * 'Port'<~String> - The port on which the load balancer is listening
|
||||||
|
# * 'DefaultActions'<~Array> - The default actions for the listener
|
||||||
|
# * 'Type'<~String> - The type of action
|
||||||
|
# * 'TargetGroupArn'<~String> - The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward
|
||||||
|
# * 'NextMarker'<~String> - Marker to specify for next page
|
||||||
|
def describe_listeners(load_balancer_arn, options = {})
|
||||||
|
request({
|
||||||
|
'Action' => 'DescribeListeners',
|
||||||
|
'LoadBalancerArn' => load_balancer_arn,
|
||||||
|
:parser => Fog::Parsers::AWS::ELBV2::DescribeListeners.new
|
||||||
|
}.merge!(options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
52
lib/fog/aws/requests/elbv2/describe_load_balancers.rb
Normal file
52
lib/fog/aws/requests/elbv2/describe_load_balancers.rb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class ELBV2
|
||||||
|
class Real
|
||||||
|
require 'fog/aws/parsers/elbv2/describe_load_balancers'
|
||||||
|
|
||||||
|
# Describe all or specified load balancers
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * options<~Hash>
|
||||||
|
# * 'LoadBalancerNames'<~Array> - List of load balancer names to describe, defaults to all
|
||||||
|
# * 'Marker'<String> - Indicates where to begin in your list of load balancers
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'ResponseMetadata'<~Hash>:
|
||||||
|
# * 'RequestId'<~String> - Id of request
|
||||||
|
# * 'DescribeLoadBalancersResult'<~Hash>:
|
||||||
|
# * 'LoadBalancers'<~Array>
|
||||||
|
# * 'AvailabilityZones'<~Array>:
|
||||||
|
# * 'SubnetId'<~String> - ID of the subnet
|
||||||
|
# * 'ZoneName'<~String> - Name of the Availability Zone
|
||||||
|
# * 'LoadBalancerAddresses'<~Array>:
|
||||||
|
# * 'IpAddress'<~String> - IP address
|
||||||
|
# * 'AllocationId'<~String> - ID of the AWS allocation
|
||||||
|
# * 'CanonicalHostedZoneName'<~String> - name of the Route 53 hosted zone associated with the load balancer
|
||||||
|
# * 'CanonicalHostedZoneNameID'<~String> - ID of the Route 53 hosted zone associated with the load balancer
|
||||||
|
# * 'CreatedTime'<~Time> - time load balancer was created
|
||||||
|
# * 'DNSName'<~String> - external DNS name of load balancer
|
||||||
|
# * 'LoadBalancerName'<~String> - name of load balancer
|
||||||
|
# * 'SecurityGroups'<~Array> - array of security group id
|
||||||
|
# * 'NextMarker'<~String> - Marker to specify for next page
|
||||||
|
def describe_load_balancers(options = {})
|
||||||
|
unless options.is_a?(Hash)
|
||||||
|
Fog::Logger.deprecation("describe_load_balancers with #{options.class} is deprecated, use all('LoadBalancerNames' => []) instead [light_black](#{caller.first})[/]")
|
||||||
|
options = { 'LoadBalancerNames' => [options].flatten }
|
||||||
|
end
|
||||||
|
|
||||||
|
if names = options.delete('LoadBalancerNames')
|
||||||
|
options.update(Fog::AWS.indexed_param('LoadBalancerNames.member', [*names]))
|
||||||
|
end
|
||||||
|
|
||||||
|
request({
|
||||||
|
'Action' => 'DescribeLoadBalancers',
|
||||||
|
:parser => Fog::Parsers::AWS::ELBV2::DescribeLoadBalancers.new
|
||||||
|
}.merge!(options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
34
tests/parsers/elbv2/describe_listeners_tests.rb
Normal file
34
tests/parsers/elbv2/describe_listeners_tests.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
require 'fog/xml'
|
||||||
|
require 'fog/aws/parsers/elbv2/describe_listeners'
|
||||||
|
|
||||||
|
DESCRIBE_LISTENERS_RESULT = <<-EOF
|
||||||
|
<DescribeListenersResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2015-12-01/">
|
||||||
|
<DescribeListenersResult>
|
||||||
|
<Listeners>
|
||||||
|
<member>
|
||||||
|
<LoadBalancerArn>arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188</LoadBalancerArn>
|
||||||
|
<Protocol>HTTP</Protocol>
|
||||||
|
<Port>80</Port>
|
||||||
|
<ListenerArn>arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2</ListenerArn>
|
||||||
|
<DefaultActions>
|
||||||
|
<member>
|
||||||
|
<Type>forward</Type>
|
||||||
|
<TargetGroupArn>arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067</TargetGroupArn>
|
||||||
|
</member>
|
||||||
|
</DefaultActions>
|
||||||
|
</member>
|
||||||
|
</Listeners>
|
||||||
|
</DescribeListenersResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>18e470d3-f39c-11e5-a53c-67205c0d10fd</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</DescribeListenersResponse>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
Shindo.tests('AWS::ELBV2 | parsers | describe_listeners', %w[aws elb parser]) do
|
||||||
|
tests('parses the xml').formats(AWS::ELBV2::Formats::DESCRIBE_LISTENERS) do
|
||||||
|
parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELBV2::DescribeListeners.new)
|
||||||
|
parser.parse(DESCRIBE_LISTENERS_RESULT)
|
||||||
|
parser.document.response
|
||||||
|
end
|
||||||
|
end
|
48
tests/parsers/elbv2/describe_load_balancers_tests.rb
Normal file
48
tests/parsers/elbv2/describe_load_balancers_tests.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
require 'fog/xml'
|
||||||
|
require 'fog/aws/parsers/elbv2/describe_load_balancers'
|
||||||
|
|
||||||
|
DESCRIBE_LOAD_BALANCERS_RESULT = <<-EOF
|
||||||
|
<DescribeLoadBalancersResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2015-12-01/">
|
||||||
|
<DescribeLoadBalancersResult>
|
||||||
|
<LoadBalancers>
|
||||||
|
<member>
|
||||||
|
<LoadBalancerArn>arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188</LoadBalancerArn>
|
||||||
|
<Scheme>internet-facing</Scheme>
|
||||||
|
<LoadBalancerName>my-load-balancer</LoadBalancerName>
|
||||||
|
<VpcId>vpc-3ac0fb5f</VpcId>
|
||||||
|
<CanonicalHostedZoneId>Z2P70J7EXAMPLE</CanonicalHostedZoneId>
|
||||||
|
<CreatedTime>2016-03-25T21:26:12.920Z</CreatedTime>
|
||||||
|
<AvailabilityZones>
|
||||||
|
<member>
|
||||||
|
<SubnetId>subnet-8360a9e7</SubnetId>
|
||||||
|
<ZoneName>us-west-2a</ZoneName>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<SubnetId>subnet-b7d581c0</SubnetId>
|
||||||
|
<ZoneName>us-west-2b</ZoneName>
|
||||||
|
</member>
|
||||||
|
</AvailabilityZones>
|
||||||
|
<SecurityGroups>
|
||||||
|
<member>sg-5943793c</member>
|
||||||
|
</SecurityGroups>
|
||||||
|
<DNSName>my-load-balancer-424835706.us-west-2.elb.amazonaws.com</DNSName>
|
||||||
|
<State>
|
||||||
|
<Code>active</Code>
|
||||||
|
</State>
|
||||||
|
<Type>application</Type>
|
||||||
|
</member>
|
||||||
|
</LoadBalancers>
|
||||||
|
</DescribeLoadBalancersResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>6581c0ac-f39f-11e5-bb98-57195a6eb84a</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</DescribeLoadBalancersResponse>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
Shindo.tests('AWS::ELBV2 | parsers | describe_load_balancers', %w[aws elb parser]) do
|
||||||
|
tests('parses the xml').formats(AWS::ELBV2::Formats::DESCRIBE_LOAD_BALANCERS) do
|
||||||
|
parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELBV2::DescribeLoadBalancers.new)
|
||||||
|
parser.parse(DESCRIBE_LOAD_BALANCERS_RESULT)
|
||||||
|
parser.document.response
|
||||||
|
end
|
||||||
|
end
|
39
tests/requests/elbv2/helper.rb
Normal file
39
tests/requests/elbv2/helper.rb
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
class AWS
|
||||||
|
module ELBV2
|
||||||
|
module Formats
|
||||||
|
BASIC = {
|
||||||
|
'ResponseMetadata' => {'RequestId' => String}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOAD_BALANCER = {
|
||||||
|
"AvailabilityZones" => Array,
|
||||||
|
"LoadBalancerArn" => String,
|
||||||
|
"DNSName" => String,
|
||||||
|
"CreatedTime" => Time,
|
||||||
|
"LoadBalancerName" => String,
|
||||||
|
"VpcId" => String,
|
||||||
|
"CanonicalHostedZoneId" => String,
|
||||||
|
"Scheme" => String,
|
||||||
|
"Type" => String,
|
||||||
|
"State" => {"Code" => String},
|
||||||
|
"SecurityGroups" => [Fog::Nullable::String]
|
||||||
|
}
|
||||||
|
|
||||||
|
DESCRIBE_LOAD_BALANCERS = BASIC.merge({
|
||||||
|
'DescribeLoadBalancersResult' => {'LoadBalancers' => [LOAD_BALANCER], 'NextMarker' => Fog::Nullable::String}
|
||||||
|
})
|
||||||
|
|
||||||
|
LISTENER = {
|
||||||
|
"LoadBalancerArn" => String,
|
||||||
|
"Protocol" => String,
|
||||||
|
"Port" => String,
|
||||||
|
"ListenerArn" => String,
|
||||||
|
"DefaultActions" => [{"Type" => String, "TargetGroupArn" => String}]
|
||||||
|
}
|
||||||
|
|
||||||
|
DESCRIBE_LISTENERS = BASIC.merge({
|
||||||
|
'DescribeListenersResult' => {'Listeners' => [LISTENER], 'NextMarker' => Fog::Nullable::String}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue