mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[elb] Adding support for create_load_balancer and delete_load_balancer
This commit is contained in:
parent
f5b84e131e
commit
d9f3e880ef
5 changed files with 151 additions and 0 deletions
|
@ -5,12 +5,16 @@ module Fog
|
|||
def self.new(options={})
|
||||
|
||||
unless @required
|
||||
require 'fog/aws/parsers/elb/create_load_balancer'
|
||||
require 'fog/aws/parsers/elb/delete_load_balancer'
|
||||
require 'fog/aws/parsers/elb/deregister_instances_from_load_balancer'
|
||||
require 'fog/aws/parsers/elb/describe_instance_health'
|
||||
require 'fog/aws/parsers/elb/describe_load_balancers'
|
||||
require 'fog/aws/parsers/elb/disable_availability_zones_for_load_balancer'
|
||||
require 'fog/aws/parsers/elb/enable_availability_zones_for_load_balancer'
|
||||
require 'fog/aws/parsers/elb/register_instances_with_load_balancer'
|
||||
require 'fog/aws/requests/elb/create_load_balancer'
|
||||
require 'fog/aws/requests/elb/delete_load_balancer'
|
||||
require 'fog/aws/requests/elb/deregister_instances_from_load_balancer'
|
||||
require 'fog/aws/requests/elb/describe_instance_health'
|
||||
require 'fog/aws/requests/elb/describe_load_balancers'
|
||||
|
|
26
lib/fog/aws/parsers/elb/create_load_balancer.rb
Normal file
26
lib/fog/aws/parsers/elb/create_load_balancer.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ELB
|
||||
|
||||
class CreateLoadBalancer < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'CreateLoadBalancerResult' => {}, 'ResponseMetadata' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'DNSName'
|
||||
@response['CreateLoadBalancerResult'][name] = @value
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/aws/parsers/elb/delete_load_balancer.rb
Normal file
24
lib/fog/aws/parsers/elb/delete_load_balancer.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ELB
|
||||
|
||||
class DeleteLoadBalancer < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'DeleteLoadBalancerResult' => nil, 'ResponseMetadata' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
57
lib/fog/aws/requests/elb/create_load_balancer.rb
Normal file
57
lib/fog/aws/requests/elb/create_load_balancer.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
module Fog
|
||||
module AWS
|
||||
module ELB
|
||||
class Real
|
||||
|
||||
# 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
|
||||
# ==== 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 = ELB.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
|
||||
|
||||
listener_protocol = []
|
||||
listener_lb_port = []
|
||||
listener_instance_port = []
|
||||
listeners.each do |listener|
|
||||
listener_protocol.push(listener['Protocol'])
|
||||
listener_lb_port.push(listener['LoadBalancerPort'])
|
||||
listener_instance_port.push(listener['InstancePort'])
|
||||
end
|
||||
|
||||
params.merge!(ELB.indexed_param('Listeners.member.%.Protocol', listener_protocol, 1))
|
||||
params.merge!(ELB.indexed_param('Listeners.member.%.LoadBalancerPort', listener_lb_port, 1))
|
||||
params.merge!(ELB.indexed_param('Listeners.member.%.InstancePort', listener_instance_port, 1))
|
||||
|
||||
request({
|
||||
'Action' => 'CreateLoadBalancer',
|
||||
'LoadBalancerName' => lb_name,
|
||||
:parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_load_balancer(availability_zones, lb_name, listeners)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
40
lib/fog/aws/requests/elb/delete_load_balancer.rb
Normal file
40
lib/fog/aws/requests/elb/delete_load_balancer.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module AWS
|
||||
module ELB
|
||||
class Real
|
||||
|
||||
# Delete an existing Elastic Load Balancer
|
||||
#
|
||||
# Note that this API call, as defined by Amazon, is idempotent.
|
||||
# That is, it will not return an error if you try to delete an
|
||||
# ELB that does not exist.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * lb_name<~String> - Name of the ELB to be deleted
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'DeleteLoadBalancerResponse'<~nil>
|
||||
# * 'ResponseMetadata'<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of request
|
||||
def delete_load_balancer(lb_name)
|
||||
request({
|
||||
'Action' => 'DeleteLoadBalancer',
|
||||
'LoadBalancerName' => lb_name,
|
||||
:parser => Fog::Parsers::AWS::ELB::DeleteLoadBalancer.new
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_load_balancer(lb_name)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue