2010-05-02 03:13:35 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class ELB < Fog::Service
|
2010-05-02 03:13:35 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent
|
2010-05-02 03:13:35 -04:00
|
|
|
|
2010-06-12 18:31:17 -04:00
|
|
|
request_path 'fog/aws/requests/elb'
|
2010-09-02 19:01:19 -04:00
|
|
|
request :create_load_balancer
|
|
|
|
request :delete_load_balancer
|
|
|
|
request :deregister_instances_from_load_balancer
|
|
|
|
request :describe_instance_health
|
|
|
|
request :describe_load_balancers
|
|
|
|
request :disable_availability_zones_for_load_balancer
|
|
|
|
request :enable_availability_zones_for_load_balancer
|
|
|
|
request :register_instances_with_load_balancer
|
2010-05-02 03:13:35 -04:00
|
|
|
|
2010-06-12 18:31:17 -04:00
|
|
|
class Mock
|
|
|
|
|
|
|
|
def initialize(options={})
|
2010-05-02 03:13:35 -04:00
|
|
|
end
|
2010-06-12 18:31:17 -04:00
|
|
|
|
2010-05-02 03:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Initialize connection to ELB
|
|
|
|
#
|
|
|
|
# ==== Notes
|
2010-05-02 19:21:35 -04:00
|
|
|
# options parameter must include values for :aws_access_key_id and
|
2010-05-02 03:13:35 -04:00
|
|
|
# :aws_secret_access_key in order to create a connection
|
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
# elb = ELB.new(
|
|
|
|
# :aws_access_key_id => your_aws_access_key_id,
|
|
|
|
# :aws_secret_access_key => your_aws_secret_access_key
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
|
|
|
# * region<~String> - optional region to use, in ['eu-west-1', 'us-east-1', 'us-west-1'i, 'ap-southeast-1']
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * ELB object with connection to AWS.
|
|
|
|
def initialize(options={})
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2010-05-02 03:13:35 -04:00
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
2010-06-16 00:04:16 -04:00
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
2011-03-02 13:57:52 -05:00
|
|
|
|
2010-08-24 18:27:50 -04:00
|
|
|
options[:region] ||= 'us-east-1'
|
2010-05-02 03:13:35 -04:00
|
|
|
@host = options[:host] || case options[:region]
|
2011-03-02 13:57:52 -05:00
|
|
|
when 'ap-northeast-1'
|
|
|
|
'elasticloadbalancing.ap-northeast-1.amazonaws.com'
|
2010-05-02 16:25:14 -04:00
|
|
|
when 'ap-southeast-1'
|
|
|
|
'elasticloadbalancing.ap-southeast-1.amazonaws.com'
|
2010-05-02 03:13:35 -04:00
|
|
|
when 'eu-west-1'
|
|
|
|
'elasticloadbalancing.eu-west-1.amazonaws.com'
|
|
|
|
when 'us-east-1'
|
|
|
|
'elasticloadbalancing.us-east-1.amazonaws.com'
|
|
|
|
when 'us-west-1'
|
|
|
|
'elasticloadbalancing.us-west-1.amazonaws.com'
|
|
|
|
else
|
2010-08-24 18:27:50 -04:00
|
|
|
raise ArgumentError, "Unknown region: #{options[:region].inspect}"
|
2010-05-02 03:13:35 -04:00
|
|
|
end
|
2010-09-29 20:53:32 -04:00
|
|
|
@path = options[:path] || '/'
|
2010-05-02 03:13:35 -04:00
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2010-09-29 20:53:32 -04:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
|
2010-06-19 21:56:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
2010-05-02 03:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
|
2010-05-02 16:25:39 -04:00
|
|
|
body = AWS.signed_params(
|
|
|
|
params,
|
|
|
|
{
|
|
|
|
:aws_access_key_id => @aws_access_key_id,
|
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
2010-09-29 20:53:32 -04:00
|
|
|
:path => @path,
|
2010-12-23 16:54:02 -05:00
|
|
|
:port => @port,
|
2011-02-28 19:22:31 -05:00
|
|
|
:version => '2010-07-01'
|
2010-05-02 16:25:39 -04:00
|
|
|
}
|
|
|
|
)
|
2010-05-02 03:13:35 -04:00
|
|
|
|
|
|
|
response = @connection.request({
|
|
|
|
:body => body,
|
|
|
|
:expects => 200,
|
|
|
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
|
|
|
:idempotent => idempotent,
|
|
|
|
:host => @host,
|
|
|
|
:method => 'POST',
|
|
|
|
:parser => parser
|
|
|
|
})
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|