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

Implement ELBV2 creation pasrer

This commit is contained in:
KevinLoiseau 2019-12-22 12:17:30 +01:00
parent 9544e058ac
commit aaad43a616
No known key found for this signature in database
GPG key ID: 709159A779B96CC3
3 changed files with 137 additions and 1 deletions

View file

@ -0,0 +1,88 @@
module Fog
module Parsers
module AWS
module ELBV2
class CreateLoadBalancer < Fog::Parsers::Base
def reset
reset_load_balancer
reset_availability_zone
@load_balancer_addresses = {}
@state = {}
@results = { 'LoadBalancers' => [] }
@response = { 'CreateLoadBalancerResult' => {}, 'ResponseMetadata' => {} }
end
def reset_load_balancer
@load_balancer = { 'SecurityGroups' => [], 'AvailabilityZones' => [] }
end
def reset_availability_zone
@availability_zone = { 'LoadBalancerAddresses' => [] }
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
reset_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 'CreateLoadBalancerResponse'
@response['CreateLoadBalancerResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,48 @@
require 'fog/xml'
require 'fog/aws/parsers/elbv2/create_load_balancer'
CREATE_LOAD_BALANCER_RESULT = <<-EOF
<CreateLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2015-12-01/">
<CreateLoadBalancerResult>
<LoadBalancers>
<member>
<LoadBalancerArn>arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-internal-load-balancer/50dc6c495c0c9188</LoadBalancerArn>
<Scheme>internet-facing</Scheme>
<LoadBalancerName>my-load-balancer</LoadBalancerName>
<VpcId>vpc-3ac0fb5f</VpcId>
<CanonicalHostedZoneId>Z2P70J7EXAMPLE</CanonicalHostedZoneId>
<CreatedTime>2016-03-25T21:29:48.850Z</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>provisioning</Code>
</State>
<Type>application</Type>
</member>
</LoadBalancers>
</CreateLoadBalancerResult>
<ResponseMetadata>
<RequestId>32d531b2-f2d0-11e5-9192-3fff33344cfa</RequestId>
</ResponseMetadata>
</CreateLoadBalancerResponse>
EOF
Shindo.tests('AWS::ELBV2 | parsers | create_load_balancer', %w[aws elb parser]) do
tests('parses the xml').formats(AWS::ELBV2::Formats::CREATE_LOAD_BALANCER) do
parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::AWS::ELBV2::CreateLoadBalancer.new)
parser.parse(CREATE_LOAD_BALANCER_RESULT)
parser.document.response
end
end

View file

@ -27,7 +27,7 @@ class AWS
})
CREATE_LOAD_BALANCER = BASIC.merge({
'CreateLoadBalancerResult' => {'LoadBalancers' => [LOAD_BALANCER], 'NextMarker' => Fog::Nullable::String}
'CreateLoadBalancerResult' => {'LoadBalancers' => [LOAD_BALANCER]}
})
LISTENER_DEFAULT_ACTIONS = [{