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

Create service ELBV2 to handle specificities of 2015-12-01 API version

This commit is contained in:
KevinLoiseau 2019-10-23 15:58:08 +02:00
parent 00c10ab1b4
commit 3360398638
No known key found for this signature in database
GPG key ID: 709159A779B96CC3
5 changed files with 155 additions and 1 deletions

View file

@ -26,6 +26,7 @@ module Fog
autoload :ECS, File.expand_path('../aws/ecs', __FILE__)
autoload :EFS, File.expand_path('../aws/efs', __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 :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
autoload :Elasticache, File.expand_path('../aws/elasticache', __FILE__)
@ -58,6 +59,7 @@ module Fog
service(:ecs, 'ECS')
service(:efs, 'EFS')
service(:elb, 'ELB')
service(:elbv2, 'ELBV2')
service(:emr, 'EMR')
service(:federation, 'Federation')
service(:glacier, 'Glacier')

View file

@ -142,7 +142,7 @@ module Fog
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@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)
end

16
lib/fog/aws/elbv2.rb Normal file
View file

@ -0,0 +1,16 @@
module Fog
module AWS
class ELBV2 < ELB
request_path 'fog/aws/requests/elbv2'
request :describe_load_balancers
class Real < ELB::Real
def initialize(options={})
@version = '2015-12-01'
super(options)
end
end
end
end
end

View 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

View 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