mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[elb] Adding register/deregister instances with/from load balancer
This commit is contained in:
parent
fc29d82c4d
commit
ae603ca624
5 changed files with 140 additions and 0 deletions
|
@ -6,7 +6,11 @@ module Fog
|
|||
|
||||
unless @required
|
||||
require 'fog/aws/requests/elb/describe_load_balancers'
|
||||
require 'fog/aws/requests/elb/register_instances_with_load_balancer.rb'
|
||||
require 'fog/aws/requests/elb/deregister_instances_from_load_balancer.rb'
|
||||
require 'fog/aws/parsers/elb/describe_load_balancers'
|
||||
require 'fog/aws/parsers/elb/register_instances_with_load_balancer.rb'
|
||||
require 'fog/aws/parsers/elb/deregister_instances_from_load_balancer.rb'
|
||||
@required = true
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ELB
|
||||
|
||||
class DeregisterInstancesFromLoadBalancer < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'DeregisterInstancesFromLoadBalancerResult' => { 'Instances' => [] }, 'ResponseMetadata' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'InstanceId'
|
||||
@response['DeregisterInstancesFromLoadBalancerResult']['Instances'] << {name => @value}
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ELB
|
||||
|
||||
class RegisterInstancesWithLoadBalancer < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'RegisterInstancesWithLoadBalancerResult' => { 'Instances' => [] }, 'ResponseMetadata' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'InstanceId'
|
||||
@response['RegisterInstancesWithLoadBalancerResult']['Instances'] << {name => @value}
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
module ELB
|
||||
class Real
|
||||
|
||||
# Deregister an instance from an existing ELB
|
||||
#
|
||||
# ==== Parameters
|
||||
# * instance_ids<~Array> - List of instance IDs to remove from ELB
|
||||
# * lb_name<~String> - Load balancer to remove instances from
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def deregister_instances_from_load_balancer(instance_ids, lb_name)
|
||||
params = ELB.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
|
||||
request({
|
||||
'Action' => 'DeregisterInstancesFromLoadBalancer',
|
||||
'LoadBalancerName' => lb_name,
|
||||
:parser => Fog::Parsers::AWS::ELB::DeregisterInstancesFromLoadBalancer.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
alias :deregister_instances :deregister_instances_from_load_balancer
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def deregister_instances_from_load_balancer(lb_name = [])
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
alias :deregister_instances :deregister_instances_from_load_balancer
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
module ELB
|
||||
class Real
|
||||
|
||||
# Register an instance with an existing ELB
|
||||
#
|
||||
# ==== Parameters
|
||||
# * instance_ids<~Array> - List of instance IDs to associate with ELB
|
||||
# * lb_name<~String> - Load balancer to assign instances to
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def register_instances_with_load_balancer(instance_ids, lb_name)
|
||||
params = ELB.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
|
||||
request({
|
||||
'Action' => 'RegisterInstancesWithLoadBalancer',
|
||||
'LoadBalancerName' => lb_name,
|
||||
:parser => Fog::Parsers::AWS::ELB::RegisterInstancesWithLoadBalancer.new
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
alias :register_instances :register_instances_with_load_balancer
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def register_instances_with_load_balancer(lb_name = [])
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
alias :register_instances :register_instances_with_load_balancer
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue