1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/elb/create_load_balancer.rb

54 lines
2.4 KiB
Ruby

module Fog
module AWS
class ELB
class Real
require 'fog/aws/parsers/elb/create_load_balancer'
# Create a new Elastic Load Balancer
#
# ==== Parameters
# * availability_zones<~Array> - List of availability zones for the ELB
# * lb_name<~String> - Name for the new ELB -- must be unique
# * listeners<~Array> - Array of Hashes describing ELB listeners to assign to the ELB
# * 'Protocol'<~String> - Protocol to use. Either HTTP or TCP.
# * '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
# * 'SSLCertificateId'<~String> - ARN of the server certificate
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'CreateLoadBalancerResult'<~Hash>:
# * 'DNSName'<~String> - DNS name for the newly created ELB
def create_load_balancer(availability_zones, lb_name, listeners)
params = AWS.indexed_param('AvailabilityZones.member', [*availability_zones])
listener_protocol = []
listener_lb_port = []
listener_instance_port = []
listener_ssl_certificate_id = []
listeners.each do |listener|
listener_protocol.push(listener['Protocol'])
listener_lb_port.push(listener['LoadBalancerPort'])
listener_instance_port.push(listener['InstancePort'])
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
end
params.merge!(AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol))
params.merge!(AWS.indexed_param('Listeners.member.%d.LoadBalancerPort', listener_lb_port))
params.merge!(AWS.indexed_param('Listeners.member.%d.InstancePort', listener_instance_port))
params.merge!(AWS.indexed_param('Listeners.member.%d.SSLCertificateId', listener_ssl_certificate_id))
request({
'Action' => 'CreateLoadBalancer',
'LoadBalancerName' => lb_name,
:parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new
}.merge!(params))
end
end
end
end
end