2010-05-02 22:06:03 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class ELB
|
2010-05-02 22:06:03 -04:00
|
|
|
class Real
|
|
|
|
|
2010-06-12 18:31:17 -04:00
|
|
|
require 'fog/aws/parsers/elb/describe_instance_health'
|
|
|
|
|
2010-05-02 22:06:03 -04:00
|
|
|
# Get health status for one or more instances on an existing ELB
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * lb_name<~String> - Load balancer to check instances health on
|
|
|
|
# * instance_ids<~Array> - Optional list of instance IDs to check
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'ResponseMetadata'<~Hash>:
|
|
|
|
# * 'RequestId'<~String> - Id of request
|
|
|
|
# * 'DescribeInstanceHealthResult'<~Hash>:
|
|
|
|
# * 'InstanceStates'<~Array> - array of hashes describing instance health
|
|
|
|
# * 'Description'<~String>
|
|
|
|
# * 'State'<~String>
|
|
|
|
# * 'InstanceId'<~String>
|
|
|
|
# * 'ReasonCode'<~String>
|
|
|
|
def describe_instance_health(lb_name, instance_ids = [])
|
2011-06-20 16:49:37 -04:00
|
|
|
params = Fog::AWS.indexed_param('Instances.member.%d.InstanceId', [*instance_ids])
|
2010-05-02 22:06:03 -04:00
|
|
|
request({
|
|
|
|
'Action' => 'DescribeInstanceHealth',
|
|
|
|
'LoadBalancerName' => lb_name,
|
|
|
|
:parser => Fog::Parsers::AWS::ELB::DescribeInstanceHealth.new
|
|
|
|
}.merge!(params))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-07-07 17:53:10 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
def describe_instance_health(lb_name, instance_ids = [])
|
|
|
|
raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
|
|
|
|
|
|
|
|
instance_ids = [*instance_ids]
|
|
|
|
instance_ids = load_balancer['Instances'].collect { |i| i['InstanceId'] } unless instance_ids.any?
|
|
|
|
data = instance_ids.map do |id|
|
2011-10-06 12:49:58 -04:00
|
|
|
unless Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id][:instances][id]
|
2011-07-07 17:53:10 -04:00
|
|
|
raise Fog::AWS::ELB::InvalidInstance
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
'Description' => "",
|
2011-10-05 18:20:40 -04:00
|
|
|
'InstanceId' => id,
|
2011-07-07 17:53:10 -04:00
|
|
|
'ReasonCode' => "",
|
|
|
|
'State' => 'OutOfService'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 200
|
|
|
|
|
|
|
|
response.body = {
|
|
|
|
'ResponseMetadata' => {
|
|
|
|
'RequestId' => Fog::AWS::Mock.request_id
|
|
|
|
},
|
|
|
|
'DescribeInstanceHealthResult' => {
|
|
|
|
'InstanceStates' => data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2010-05-02 22:06:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|