fog-aws 3.5.2 → 3.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +82 -7
- data/LICENSE.md +1 -1
- data/README.md +39 -6
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fog-aws.gemspec +3 -3
- data/lib/fog/aws.rb +6 -1
- data/lib/fog/aws/credential_fetcher.rb +27 -4
- data/lib/fog/aws/elasticache.rb +4 -2
- data/lib/fog/aws/elb.rb +1 -1
- data/lib/fog/aws/elbv2.rb +72 -0
- data/lib/fog/aws/kinesis.rb +23 -15
- data/lib/fog/aws/models/compute/flavors.rb +1556 -134
- data/lib/fog/aws/models/compute/server.rb +4 -2
- data/lib/fog/aws/models/compute/servers.rb +2 -0
- data/lib/fog/aws/models/compute/snapshot.rb +7 -6
- data/lib/fog/aws/models/compute/vpc.rb +8 -2
- data/lib/fog/aws/models/storage/directory.rb +0 -1
- data/lib/fog/aws/models/storage/file.rb +3 -0
- data/lib/fog/aws/parsers/compute/create_snapshot.rb +1 -1
- data/lib/fog/aws/parsers/compute/create_subnet.rb +33 -6
- data/lib/fog/aws/parsers/compute/describe_subnets.rb +33 -6
- data/lib/fog/aws/parsers/dns/create_hosted_zone.rb +1 -1
- data/lib/fog/aws/parsers/dns/get_hosted_zone.rb +3 -3
- data/lib/fog/aws/parsers/dns/list_hosted_zones.rb +3 -1
- data/lib/fog/aws/parsers/elbv2/create_load_balancer.rb +88 -0
- data/lib/fog/aws/parsers/elbv2/describe_listeners.rb +110 -0
- data/lib/fog/aws/parsers/elbv2/describe_load_balancers.rb +88 -0
- data/lib/fog/aws/parsers/elbv2/describe_tags.rb +53 -0
- data/lib/fog/aws/parsers/elbv2/empty.rb +10 -0
- data/lib/fog/aws/parsers/storage/get_object_tagging.rb +33 -0
- data/lib/fog/aws/parsers/sts/assume_role_with_web_identity.rb +1 -1
- data/lib/fog/aws/requests/compute/create_vpc.rb +2 -2
- data/lib/fog/aws/requests/compute/run_instances.rb +20 -0
- data/lib/fog/aws/requests/compute/stop_instances.rb +11 -3
- data/lib/fog/aws/requests/elbv2/add_tags.rb +45 -0
- data/lib/fog/aws/requests/elbv2/create_load_balancer.rb +160 -0
- data/lib/fog/aws/requests/elbv2/describe_listeners.rb +38 -0
- data/lib/fog/aws/requests/elbv2/describe_load_balancers.rb +100 -0
- data/lib/fog/aws/requests/elbv2/describe_tags.rb +50 -0
- data/lib/fog/aws/requests/elbv2/remove_tags.rb +45 -0
- data/lib/fog/aws/requests/storage/get_object_tagging.rb +41 -0
- data/lib/fog/aws/requests/storage/put_object_tagging.rb +42 -0
- data/lib/fog/aws/requests/sts/assume_role_with_web_identity.rb +7 -6
- data/lib/fog/aws/storage.rb +2 -0
- data/lib/fog/aws/version.rb +1 -1
- data/tests/credentials_tests.rb +20 -0
- data/tests/parsers/elbv2/create_load_balancer_tests.rb +48 -0
- data/tests/parsers/elbv2/describe_listeners_tests.rb +76 -0
- data/tests/parsers/elbv2/describe_load_balancers_tests.rb +54 -0
- data/tests/parsers/elbv2/describe_tags_tests.rb +35 -0
- data/tests/requests/compute/vpc_tests.rb +6 -0
- data/tests/requests/elbv2/helper.rb +66 -0
- data/tests/requests/elbv2/load_balancer_tests.rb +50 -0
- metadata +32 -9
@@ -0,0 +1,88 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module ELBV2
|
5
|
+
class DescribeLoadBalancers < Fog::Parsers::Base
|
6
|
+
def reset
|
7
|
+
reset_load_balancer
|
8
|
+
reset_availability_zone
|
9
|
+
@load_balancer_addresses = {}
|
10
|
+
@state = {}
|
11
|
+
@results = { 'LoadBalancers' => [] }
|
12
|
+
@response = { 'DescribeLoadBalancersResult' => {}, 'ResponseMetadata' => {} }
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset_load_balancer
|
16
|
+
@load_balancer = { 'SecurityGroups' => [], 'AvailabilityZones' => [] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_availability_zone
|
20
|
+
@availability_zone = { 'LoadBalancerAddresses' => [] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def start_element(name, attrs = [])
|
24
|
+
super
|
25
|
+
case name
|
26
|
+
when 'AvailabilityZones'
|
27
|
+
@in_availability_zones = true
|
28
|
+
when 'LoadBalancerAddresses'
|
29
|
+
@in_load_balancer_addresses = true
|
30
|
+
when 'SecurityGroups'
|
31
|
+
@in_security_groups = true
|
32
|
+
when 'State'
|
33
|
+
@in_state = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def end_element(name)
|
38
|
+
case name
|
39
|
+
when 'member'
|
40
|
+
if @in_availability_zones && @in_load_balancer_addresses
|
41
|
+
@availability_zone['LoadBalancerAddresses'] << @load_balancer_addresses
|
42
|
+
elsif @in_availability_zones
|
43
|
+
@load_balancer['AvailabilityZones'] << @availability_zone
|
44
|
+
reset_availability_zone
|
45
|
+
elsif @in_security_groups
|
46
|
+
@load_balancer['SecurityGroups'] << value
|
47
|
+
else
|
48
|
+
@results['LoadBalancers'] << @load_balancer
|
49
|
+
reset_load_balancer
|
50
|
+
end
|
51
|
+
when 'SubnetId', 'ZoneName'
|
52
|
+
@availability_zone[name] = value
|
53
|
+
when 'IpAddress', 'AllocationId'
|
54
|
+
@load_balancer_addresses[name] = value
|
55
|
+
|
56
|
+
when 'CanonicalHostedZoneName', 'CanonicalHostedZoneNameID', 'LoadBalancerName', 'DNSName', 'Scheme', 'Type',
|
57
|
+
'LoadBalancerArn', 'IpAddressType', 'CanonicalHostedZoneId', 'VpcId'
|
58
|
+
@load_balancer[name] = value
|
59
|
+
when 'CreatedTime'
|
60
|
+
@load_balancer[name] = Time.parse(value)
|
61
|
+
|
62
|
+
when 'LoadBalancerAddresses'
|
63
|
+
@in_load_balancer_addresses = false
|
64
|
+
when 'AvailabilityZones'
|
65
|
+
@in_availability_zones = false
|
66
|
+
when 'SecurityGroups'
|
67
|
+
@in_security_groups = false
|
68
|
+
when 'State'
|
69
|
+
@in_state = false
|
70
|
+
@load_balancer[name] = @state
|
71
|
+
@state = {}
|
72
|
+
when 'Code'
|
73
|
+
@state[name] = value
|
74
|
+
|
75
|
+
when 'RequestId'
|
76
|
+
@response['ResponseMetadata'][name] = value
|
77
|
+
|
78
|
+
when 'NextMarker'
|
79
|
+
@results['NextMarker'] = value
|
80
|
+
when 'DescribeLoadBalancersResponse'
|
81
|
+
@response['DescribeLoadBalancersResult'] = @results
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module ELBV2
|
5
|
+
class DescribeTags < Fog::Parsers::Base
|
6
|
+
def reset
|
7
|
+
@this_key = nil
|
8
|
+
@this_value = nil
|
9
|
+
@tags = Hash.new
|
10
|
+
@response = { 'DescribeTagsResult' => { 'TagDescriptions' => [] }, 'ResponseMetadata' => {} }
|
11
|
+
@in_tags = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def start_element(name, attrs = [])
|
15
|
+
super
|
16
|
+
case name
|
17
|
+
when 'member'
|
18
|
+
unless @in_tags
|
19
|
+
@resource_arn = nil
|
20
|
+
@tags = {}
|
21
|
+
end
|
22
|
+
when 'Tags'
|
23
|
+
@in_tags = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def end_element(name)
|
28
|
+
super
|
29
|
+
case name
|
30
|
+
when 'member'
|
31
|
+
if @in_tags
|
32
|
+
@tags[@this_key] = @this_value
|
33
|
+
@this_key, @this_value = nil, nil
|
34
|
+
else
|
35
|
+
@response['DescribeTagsResult']['TagDescriptions'] << { 'Tags' => @tags, 'ResourceArn' => @resource_arn }
|
36
|
+
end
|
37
|
+
when 'Key'
|
38
|
+
@this_key = value
|
39
|
+
when 'Value'
|
40
|
+
@this_value = value
|
41
|
+
when 'ResourceArn'
|
42
|
+
@resource_arn = value
|
43
|
+
when 'RequestId'
|
44
|
+
@response['ResponseMetadata'][name] = value
|
45
|
+
when 'Tags'
|
46
|
+
@in_tags = false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module Storage
|
5
|
+
class GetObjectTagging < Fog::Parsers::Base
|
6
|
+
def reset
|
7
|
+
@in_tag = {}
|
8
|
+
@response = {'ObjectTagging' => {}}
|
9
|
+
end
|
10
|
+
|
11
|
+
def start_element(name, *args)
|
12
|
+
super
|
13
|
+
if name == 'Tag'
|
14
|
+
@in_tag = {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def end_element(name)
|
19
|
+
case name
|
20
|
+
when 'Tag'
|
21
|
+
@response['ObjectTagging'].merge!(@in_tag)
|
22
|
+
@in_tag = {}
|
23
|
+
when 'Key'
|
24
|
+
@in_tag[value] = nil
|
25
|
+
when 'Value'
|
26
|
+
@in_tag = {@in_tag.keys.first => value}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -11,7 +11,6 @@ module Fog
|
|
11
11
|
# * options<~Hash>:
|
12
12
|
# * InstanceTenancy<~String> - The allowed tenancy of instances launched into the VPC. A value of default
|
13
13
|
# means instances can be launched with any tenancy; a value of dedicated means instances must be launched with tenancy as dedicated.
|
14
|
-
# please not that the documentation is incorrect instanceTenancy will not work while InstanceTenancy will
|
15
14
|
#
|
16
15
|
# === Returns
|
17
16
|
# * response<~Excon::Response>:
|
@@ -54,7 +53,8 @@ module Fog
|
|
54
53
|
'classicLinkEnabled' => false,
|
55
54
|
'classicLinkDnsSupport' => false,
|
56
55
|
'cidrBlockAssociationSet' => [{ 'cidrBlock' => cidrBlock, 'state' => 'associated', 'associationId' => "vpc-cidr-assoc-#{vpc_id}" }],
|
57
|
-
'ipv6CidrBlockAssociationSet' => []
|
56
|
+
'ipv6CidrBlockAssociationSet' => [],
|
57
|
+
'instanceTenancy' => options['InstanceTenancy'] || 'default'
|
58
58
|
}
|
59
59
|
self.data[:vpcs].push(vpc)
|
60
60
|
|
@@ -30,6 +30,8 @@ module Fog
|
|
30
30
|
# * 'Ebs.Encrypted'<~Boolean> - specifies whether or not the volume is to be encrypted unless snapshot is specified
|
31
31
|
# * 'Ebs.VolumeType'<~String> - Type of EBS volue. Valid options in ['standard', 'io1'] default is 'standard'.
|
32
32
|
# * 'Ebs.Iops'<~String> - The number of I/O operations per second (IOPS) that the volume supports. Required when VolumeType is 'io1'
|
33
|
+
# * 'HibernationOptions'<~Array>: array of hashes
|
34
|
+
# * 'Configured'<~Boolean> - specifies whether or not the instance is configued for hibernation. This parameter is valid only if the instance meets the hibernation prerequisites.
|
33
35
|
# * 'NetworkInterfaces'<~Array>: array of hashes
|
34
36
|
# * 'NetworkInterfaceId'<~String> - An existing interface to attach to a single instance
|
35
37
|
# * 'DeviceIndex'<~String> - The device index. Applies both to attaching an existing network interface and creating a network interface
|
@@ -75,6 +77,8 @@ module Fog
|
|
75
77
|
# * 'deviceName'<~String> - specifies how volume is exposed to instance
|
76
78
|
# * 'status'<~String> - status of attached volume
|
77
79
|
# * 'volumeId'<~String> - Id of attached volume
|
80
|
+
# * 'hibernationOptions'<~Array>
|
81
|
+
# * 'configured'<~Boolean> - whether or not the instance is enabled for hibernation
|
78
82
|
# * 'dnsName'<~String> - public dns name, blank until instance is running
|
79
83
|
# * 'imageId'<~String> - image id of ami used to launch instance
|
80
84
|
# * 'instanceId'<~String> - id of the instance
|
@@ -111,6 +115,13 @@ module Fog
|
|
111
115
|
end
|
112
116
|
end
|
113
117
|
end
|
118
|
+
if hibernation_options = options.delete('HibernationOptions')
|
119
|
+
hibernation_options.each_with_index do |mapping, index|
|
120
|
+
for key, value in mapping
|
121
|
+
options.merge!({ format("HibernationOptions.%d.#{key}", index) => value })
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
114
125
|
if security_groups = options.delete('SecurityGroup')
|
115
126
|
options.merge!(Fog::AWS.indexed_param('SecurityGroup', [*security_groups]))
|
116
127
|
end
|
@@ -182,6 +193,14 @@ module Fog
|
|
182
193
|
}
|
183
194
|
end
|
184
195
|
|
196
|
+
hibernation_options = (options['HibernationOptions'] || []).reduce([]) do |mapping, device|
|
197
|
+
configure = device.fetch("Configure", true)
|
198
|
+
|
199
|
+
mapping << {
|
200
|
+
"Configure" => configure,
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
185
204
|
if options['SubnetId']
|
186
205
|
if options['PrivateIpAddress']
|
187
206
|
ni_options = {'PrivateIpAddress' => options['PrivateIpAddress']}
|
@@ -221,6 +240,7 @@ module Fog
|
|
221
240
|
'associatePublicIP' => options['associatePublicIP'] || false,
|
222
241
|
'architecture' => 'i386',
|
223
242
|
'blockDeviceMapping' => block_device_mapping,
|
243
|
+
'hibernationOptions' => hibernation_options,
|
224
244
|
'networkInterfaces' => network_interfaces,
|
225
245
|
'clientToken' => options['clientToken'],
|
226
246
|
'dnsName' => nil,
|
@@ -16,9 +16,17 @@ module Fog
|
|
16
16
|
# * TODO: fill in the blanks
|
17
17
|
#
|
18
18
|
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StopInstances.html]
|
19
|
-
def stop_instances(instance_id,
|
19
|
+
def stop_instances(instance_id, options = {})
|
20
20
|
params = Fog::AWS.indexed_param('InstanceId', instance_id)
|
21
|
-
|
21
|
+
unless options.is_a?(Hash)
|
22
|
+
Fog::Logger.warning("stop_instances with #{options.class} param is deprecated, use stop_instances('force' => boolean) instead [light_black](#{caller.first})[/]")
|
23
|
+
options = {'force' => options}
|
24
|
+
end
|
25
|
+
params.merge!('Force' => 'true') if options['force']
|
26
|
+
if options['hibernate']
|
27
|
+
params.merge!('Hibernate' => 'true')
|
28
|
+
params.merge!('Force' => 'false')
|
29
|
+
end
|
22
30
|
request({
|
23
31
|
'Action' => 'StopInstances',
|
24
32
|
:idempotent => true,
|
@@ -28,7 +36,7 @@ module Fog
|
|
28
36
|
end
|
29
37
|
|
30
38
|
class Mock
|
31
|
-
def stop_instances(instance_id,
|
39
|
+
def stop_instances(instance_id, options = {})
|
32
40
|
instance_ids = Array(instance_id)
|
33
41
|
|
34
42
|
instance_set = self.data[:instances].values
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ELBV2
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/elbv2/empty'
|
6
|
+
|
7
|
+
# adds tags to a load balancer instance
|
8
|
+
# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_AddTags.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * resource_arn <~String> - The Amazon Resource Name (ARN) of the resource
|
11
|
+
# * tags <~Hash> A Hash of (String) key-value pairs
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
def add_tags(resource_arn, tags)
|
16
|
+
keys = tags.keys.sort
|
17
|
+
values = keys.map {|key| tags[key]}
|
18
|
+
request({
|
19
|
+
'Action' => 'AddTags',
|
20
|
+
'ResourceArns.member.1' => resource_arn,
|
21
|
+
:parser => Fog::Parsers::AWS::ELBV2::Empty.new,
|
22
|
+
}.merge(Fog::AWS.indexed_param('Tags.member.%d.Key', keys))
|
23
|
+
.merge(Fog::AWS.indexed_param('Tags.member.%d.Value', values)))
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def add_tags(resource_arn, tags)
|
30
|
+
response = Excon::Response.new
|
31
|
+
if self.data[:load_balancers_v2][resource_arn]
|
32
|
+
self.data[:tags][resource_arn].merge! tags
|
33
|
+
response.status = 200
|
34
|
+
response.body = {
|
35
|
+
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
|
36
|
+
}
|
37
|
+
response
|
38
|
+
else
|
39
|
+
raise Fog::AWS::ELBV2::NotFound.new("Elastic load balancer #{resource_arn} not found")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ELBV2
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/elbv2/create_load_balancer'
|
6
|
+
|
7
|
+
# Create a new Elastic Load Balancer
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * name<~String> - The name of the load balancer.
|
11
|
+
# This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens,
|
12
|
+
# must not begin or end with a hyphen, and must not begin with "internal-".
|
13
|
+
# - Required: Yes
|
14
|
+
# * options<~Hash>:
|
15
|
+
# * ip_address_type<~String> - [Application Load Balancers] The type of IP addresses used by the subnets for your load balancer.
|
16
|
+
# The possible values are ipv4 (for IPv4 addresses) and dualstack (for IPv4 and IPv6 addresses).
|
17
|
+
# Internal load balancers must use ipv4.
|
18
|
+
# - Required: No
|
19
|
+
# * scheme<~String> - The default is an Internet-facing load balancer. Valid Values: internet-facing | internal
|
20
|
+
# - Required: No
|
21
|
+
# * security_groups<~Array> - The IDs of the security groups for the load balancer.
|
22
|
+
# - Required: No
|
23
|
+
# * subnet_mappings<~Array> - The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.
|
24
|
+
# - [Application Load Balancers] You must specify subnets from at least two Availability Zones.
|
25
|
+
# You cannot specify Elastic IP addresses for your subnets.
|
26
|
+
# - [Network Load Balancers] You can specify subnets from one or more Availability Zones.
|
27
|
+
# You can specify one Elastic IP address per subnet if you need static IP addresses for your internet-facing load balancer.
|
28
|
+
# For internal load balancers, you can specify one private IP address per subnet from the IPv4 range of the subnet.
|
29
|
+
# - Required: No
|
30
|
+
# * subnets<~Array> - The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.
|
31
|
+
# - [Application Load Balancers] You must specify subnets from at least two Availability Zones.
|
32
|
+
# - [Network Load Balancers] You can specify subnets from one or more Availability Zones.
|
33
|
+
# - Required: No
|
34
|
+
# * tags<~Hash> - One or more tags to assign to the load balancer.
|
35
|
+
# - Required: No
|
36
|
+
# * type<~String> - The type of load balancer. The default is application. Valid Values: application | network
|
37
|
+
# - Required: No
|
38
|
+
# ==== Returns
|
39
|
+
# * response<~Excon::Response>:
|
40
|
+
# * body<~Hash>:
|
41
|
+
# * 'ResponseMetadata'<~Hash>:
|
42
|
+
# * 'RequestId'<~String> - Id of request
|
43
|
+
# * 'CreateLoadBalancerResult'<~Hash>:
|
44
|
+
# * 'LoadBalancers'<~Array>
|
45
|
+
# * 'AvailabilityZones'<~Array>:
|
46
|
+
# * 'SubnetId'<~String> - ID of the subnet
|
47
|
+
# * 'ZoneName'<~String> - Name of the Availability Zone
|
48
|
+
# * 'LoadBalancerAddresses'<~Array>:
|
49
|
+
# * 'IpAddress'<~String> - IP address
|
50
|
+
# * 'AllocationId'<~String> - ID of the AWS allocation
|
51
|
+
# * 'CanonicalHostedZoneName'<~String> - name of the Route 53 hosted zone associated with the load balancer
|
52
|
+
# * 'CanonicalHostedZoneNameID'<~String> - ID of the Route 53 hosted zone associated with the load balancer
|
53
|
+
# * 'CreatedTime'<~Time> - time load balancer was created
|
54
|
+
# * 'DNSName'<~String> - external DNS name of load balancer
|
55
|
+
# * 'LoadBalancerName'<~String> - name of load balancer
|
56
|
+
# * 'SecurityGroups'<~Array> - array of security group id
|
57
|
+
def create_load_balancer(name, options = {})
|
58
|
+
params = {}
|
59
|
+
params.merge!(Fog::AWS.indexed_param('Subnets.member.%d', options[:subnets]))
|
60
|
+
params.merge!(Fog::AWS.indexed_param('SecurityGroups.member.%d', options[:security_groups]))
|
61
|
+
params.merge!(Fog::AWS.serialize_keys('Scheme', options[:scheme]))
|
62
|
+
params.merge!(Fog::AWS.serialize_keys('Type', options[:type]))
|
63
|
+
params.merge!(Fog::AWS.serialize_keys('IpAddressType', options[:ip_address_type]))
|
64
|
+
|
65
|
+
|
66
|
+
unless options[:tags].nil?
|
67
|
+
tag_keys = options[:tags].keys.sort
|
68
|
+
tag_values = tag_keys.map { |key| options[:tags][key] }
|
69
|
+
params.merge!(Fog::AWS.indexed_param('Tags.member.%d.Key', tag_keys))
|
70
|
+
params.merge!(Fog::AWS.indexed_param('Tags.member.%d.Value', tag_values))
|
71
|
+
end
|
72
|
+
|
73
|
+
unless options[:subnet_mappings].nil?
|
74
|
+
subnet_ids = []
|
75
|
+
allocation_ids = []
|
76
|
+
private_ipv4_address = []
|
77
|
+
options[:subnet_mappings].each do |subnet_mapping|
|
78
|
+
subnet_ids.push(subnet_mapping[:subnet_id])
|
79
|
+
allocation_ids.push(subnet_mapping[:allocation_id])
|
80
|
+
private_ipv4_address.push(subnet_mapping[:private_ipv4_address])
|
81
|
+
end
|
82
|
+
params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.SubnetId', subnet_ids))
|
83
|
+
params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.AllocationId', allocation_ids))
|
84
|
+
params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.PrivateIPv4Address', private_ipv4_address))
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
request({
|
89
|
+
'Action' => 'CreateLoadBalancer',
|
90
|
+
'Name' => name,
|
91
|
+
:parser => Fog::Parsers::AWS::ELBV2::CreateLoadBalancer.new
|
92
|
+
}.merge!(params))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Mock
|
97
|
+
def create_load_balancer(name, options = {})
|
98
|
+
response = Excon::Response.new
|
99
|
+
response.status = 200
|
100
|
+
|
101
|
+
raise Fog::AWS::ELBV2::IdentifierTaken if self.data[:load_balancers_v2].key? name
|
102
|
+
|
103
|
+
dns_name = Fog::AWS::ELBV2::Mock.dns_name(name, @region)
|
104
|
+
type = options[:type] || 'application'
|
105
|
+
load_balancer_arn = Fog::AWS::Mock.arn('elasticloadbalancing', self.data[:owner_id], "loadbalancer/#{type[0..2]}/#{name}/#{Fog::AWS::Mock.key_id}")
|
106
|
+
|
107
|
+
subnet_ids = options[:subnets] || []
|
108
|
+
region = if subnet_ids.any?
|
109
|
+
# using Hash here for Rubt 1.8.7 support.
|
110
|
+
Hash[
|
111
|
+
Fog::AWS::Compute::Mock.data.select do |_, region_data|
|
112
|
+
unless region_data[@aws_access_key_id].nil?
|
113
|
+
region_data[@aws_access_key_id][:subnets].any? do |region_subnets|
|
114
|
+
subnet_ids.include? region_subnets['subnetId']
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
].keys[0]
|
119
|
+
else
|
120
|
+
'us-east-1'
|
121
|
+
end
|
122
|
+
|
123
|
+
subnets = Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:subnets].select {|e| subnet_ids.include?(e["subnetId"]) }
|
124
|
+
availability_zones = subnets.map do |subnet|
|
125
|
+
{ "LoadBalancerAddresses"=>[], "SubnetId"=>subnet["subnetId"], "ZoneName"=>subnet["availabilityZone"]}
|
126
|
+
end
|
127
|
+
vpc_id = subnets.first['vpcId']
|
128
|
+
|
129
|
+
self.data[:tags] ||= {}
|
130
|
+
self.data[:tags][load_balancer_arn] = options[:tags] || {}
|
131
|
+
|
132
|
+
load_balancer = {
|
133
|
+
'AvailabilityZones' => availability_zones || [],
|
134
|
+
'Scheme' => options[:scheme] || 'internet-facing',
|
135
|
+
'SecurityGroups' => options[:security_groups] || [],
|
136
|
+
'CanonicalHostedZoneId' => '',
|
137
|
+
'CreatedTime' => Time.now,
|
138
|
+
'DNSName' => dns_name,
|
139
|
+
'VpcId' => vpc_id,
|
140
|
+
'Type' => type,
|
141
|
+
'State' => {'Code' => 'provisioning'},
|
142
|
+
'LoadBalancerArn' => load_balancer_arn,
|
143
|
+
'LoadBalancerName' => name
|
144
|
+
}
|
145
|
+
self.data[:load_balancers_v2][load_balancer_arn] = load_balancer
|
146
|
+
response.body = {
|
147
|
+
'ResponseMetadata' => {
|
148
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
149
|
+
},
|
150
|
+
'CreateLoadBalancerResult' => {
|
151
|
+
'LoadBalancers' => [load_balancer]
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
response
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|