2010-05-09 21:53:56 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class ELB
|
2010-05-09 21:53:56 -04:00
|
|
|
class Real
|
|
|
|
|
2010-06-12 18:31:17 -04:00
|
|
|
require 'fog/aws/parsers/elb/create_load_balancer'
|
|
|
|
|
2010-05-09 21:53:56 -04:00
|
|
|
# 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
|
2012-01-22 20:00:48 -05:00
|
|
|
# * 'Protocol'<~String> - Protocol to use. Either HTTP, HTTPS, TCP or SSL.
|
2010-05-09 21:53:56 -04:00
|
|
|
# * '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
|
2012-01-22 20:00:48 -05:00
|
|
|
# * 'InstanceProtocol'<~String> - Protocol for sending traffic to an instance. Either HTTP, HTTPS, TCP or SSL.
|
2011-02-28 19:22:31 -05:00
|
|
|
# * 'SSLCertificateId'<~String> - ARN of the server certificate
|
2010-05-09 21:53:56 -04:00
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'ResponseMetadata'<~Hash>:
|
|
|
|
# * 'RequestId'<~String> - Id of request
|
|
|
|
# * 'CreateLoadBalancerResult'<~Hash>:
|
|
|
|
# * 'DNSName'<~String> - DNS name for the newly created ELB
|
2012-05-21 14:37:00 -04:00
|
|
|
def create_load_balancer(availability_zones, lb_name, listeners, options = {})
|
2011-06-20 16:49:37 -04:00
|
|
|
params = Fog::AWS.indexed_param('AvailabilityZones.member', [*availability_zones])
|
2012-05-21 14:37:00 -04:00
|
|
|
params.merge!(Fog::AWS.indexed_param('Subnets.member.%d', options[:subnet_ids]))
|
2012-06-12 19:18:20 -04:00
|
|
|
params.merge!(Fog::AWS.serialize_keys('Scheme', options[:scheme]))
|
2012-05-21 14:37:00 -04:00
|
|
|
params.merge!(Fog::AWS.indexed_param('SecurityGroups.member.%d', options[:security_groups]))
|
2010-05-09 21:53:56 -04:00
|
|
|
|
|
|
|
listener_protocol = []
|
|
|
|
listener_lb_port = []
|
|
|
|
listener_instance_port = []
|
2012-01-22 20:00:48 -05:00
|
|
|
listener_instance_protocol = []
|
2011-02-28 19:22:31 -05:00
|
|
|
listener_ssl_certificate_id = []
|
2010-05-09 21:53:56 -04:00
|
|
|
listeners.each do |listener|
|
|
|
|
listener_protocol.push(listener['Protocol'])
|
|
|
|
listener_lb_port.push(listener['LoadBalancerPort'])
|
|
|
|
listener_instance_port.push(listener['InstancePort'])
|
2012-01-22 20:00:48 -05:00
|
|
|
listener_instance_protocol.push(listener['InstanceProtocol'])
|
2011-02-28 19:22:31 -05:00
|
|
|
listener_ssl_certificate_id.push(listener['SSLCertificateId'])
|
2010-05-09 21:53:56 -04:00
|
|
|
end
|
|
|
|
|
2011-06-20 16:49:37 -04:00
|
|
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol))
|
|
|
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.LoadBalancerPort', listener_lb_port))
|
|
|
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstancePort', listener_instance_port))
|
2012-01-22 20:00:48 -05:00
|
|
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.InstanceProtocol', listener_instance_protocol))
|
2011-06-20 16:49:37 -04:00
|
|
|
params.merge!(Fog::AWS.indexed_param('Listeners.member.%d.SSLCertificateId', listener_ssl_certificate_id))
|
2010-05-09 21:53:56 -04:00
|
|
|
|
|
|
|
request({
|
|
|
|
'Action' => 'CreateLoadBalancer',
|
|
|
|
'LoadBalancerName' => lb_name,
|
|
|
|
:parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new
|
|
|
|
}.merge!(params))
|
|
|
|
end
|
|
|
|
end
|
2011-07-06 19:11:14 -04:00
|
|
|
|
|
|
|
class Mock
|
2012-05-21 14:37:00 -04:00
|
|
|
def create_load_balancer(availability_zones, lb_name, listeners = [], options = {})
|
2011-07-06 19:11:14 -04:00
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 200
|
|
|
|
|
2011-07-07 17:53:10 -04:00
|
|
|
raise Fog::AWS::ELB::IdentifierTaken if self.data[:load_balancers].has_key? lb_name
|
|
|
|
|
2011-10-05 18:20:40 -04:00
|
|
|
certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map {|n, c| c['Arn'] }
|
2011-07-07 20:53:25 -04:00
|
|
|
|
|
|
|
listeners = [*listeners].map do |listener|
|
|
|
|
if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId']
|
2011-07-18 20:53:32 -04:00
|
|
|
raise Fog::AWS::IAM::NotFound.new('CertificateNotFound')
|
2011-07-07 20:53:25 -04:00
|
|
|
end
|
|
|
|
{'Listener' => listener, 'PolicyNames' => []}
|
|
|
|
end
|
|
|
|
|
2011-07-06 19:11:14 -04:00
|
|
|
dns_name = Fog::AWS::ELB::Mock.dns_name(lb_name, @region)
|
2013-04-01 15:03:32 -04:00
|
|
|
|
|
|
|
Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id][:security_groups]['amazon-elb-sg'] ||= {
|
|
|
|
'groupDescription' => 'amazon-elb-sg',
|
|
|
|
'groupName' => 'amazon-elb-sg',
|
|
|
|
'groupId' => 'amazon-elb',
|
|
|
|
'ownerId' => 'amazon-elb',
|
|
|
|
'ipPermissionsEgree' => [],
|
|
|
|
'ipPermissions' => [],
|
|
|
|
}
|
|
|
|
|
2011-07-06 19:11:14 -04:00
|
|
|
self.data[:load_balancers][lb_name] = {
|
|
|
|
'AvailabilityZones' => availability_zones,
|
2012-08-16 16:17:42 -04:00
|
|
|
'Subnets' => options[:subnet_ids] || [],
|
2012-06-25 16:36:21 -04:00
|
|
|
'Scheme' => options[:scheme].nil? ? 'internet-facing' : options[:scheme],
|
2012-08-07 12:20:57 -04:00
|
|
|
'SecurityGroups' => options[:security_groups].nil? ? [] : options[:security_groups],
|
2011-07-06 19:11:14 -04:00
|
|
|
'CanonicalHostedZoneName' => '',
|
|
|
|
'CanonicalHostedZoneNameID' => '',
|
|
|
|
'CreatedTime' => Time.now,
|
|
|
|
'DNSName' => dns_name,
|
|
|
|
'HealthCheck' => {
|
2011-07-07 17:53:10 -04:00
|
|
|
'HealthyThreshold' => 10,
|
|
|
|
'Timeout' => 5,
|
|
|
|
'UnhealthyThreshold' => 2,
|
|
|
|
'Interval' => 30,
|
|
|
|
'Target' => 'TCP:80'
|
2011-07-06 19:11:14 -04:00
|
|
|
},
|
|
|
|
'Instances' => [],
|
2011-07-07 20:53:25 -04:00
|
|
|
'ListenerDescriptions' => listeners,
|
2011-07-06 19:11:14 -04:00
|
|
|
'LoadBalancerName' => lb_name,
|
2011-12-19 19:14:27 -05:00
|
|
|
'Policies' => {
|
|
|
|
'AppCookieStickinessPolicies' => [],
|
|
|
|
'LBCookieStickinessPolicies' => [],
|
|
|
|
'Proper' => []
|
|
|
|
},
|
2011-07-06 19:11:14 -04:00
|
|
|
'SourceSecurityGroup' => {
|
|
|
|
'GroupName' => '',
|
|
|
|
'OwnerAlias' => ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response.body = {
|
|
|
|
'ResponseMetadata' => {
|
|
|
|
'RequestId' => Fog::AWS::Mock.request_id
|
|
|
|
},
|
|
|
|
'CreateLoadBalancerResult' => {
|
|
|
|
'DNSName' => dns_name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2010-05-09 21:53:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|