Class: RightAws::Elb
- Inherits:
-
RightAwsBase
- Object
- RightAwsBase
- RightAws::Elb
- Includes:
- RightAwsBaseInterface
- Defined in:
- lib/elb/right_elb_interface.rb
Defined Under Namespace
Classes: QElbDescribeLoadBalancersParser, QElbRegisterInstanceParser
Constant Summary collapse
- API_VERSION =
Amazon EC2 API version being used
"2008-12-01"
- DEFAULT_HOST =
"elasticloadbalancing.amazonaws.com"
- DEFAULT_PATH =
'/'
- DEFAULT_PROTOCOL =
'http'
- DEFAULT_PORT =
80
- @@bench =
AwsBenchmarkingBlock.new
- @@api =
Current API version (sometimes we have to check it outside the GEM).
ENV['EC2_API_VERSION'] || API_VERSION
Constants included from RightAwsBaseInterface
RightAwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from RightAwsBase
Instance Attribute Summary
Attributes included from RightAwsBaseInterface
#aws_access_key_id, #cache, #connection, #last_errors, #last_request, #last_request_id, #last_response, #logger, #params, #signature_version
Class Method Summary collapse
Instance Method Summary collapse
- #describe_load_balancers ⇒ Object
- #generate_request(action, params = {}) ⇒ Object
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Elb
constructor
A new instance of Elb.
- #register_instance_with_elb(instance_id, lparams = {}) ⇒ Object
-
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened.
Methods included from RightAwsBaseInterface
#cache_hits?, caching, caching=, #caching?, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info_impl, #signed_service_params, #update_cache
Methods inherited from RightAwsBase
amazon_problems, amazon_problems=
Constructor Details
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Elb
Returns a new instance of Elb.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/elb/right_elb_interface.rb', line 32 def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) init({ :name => 'ELB', :default_host => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).host : DEFAULT_HOST, :default_port => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).port : DEFAULT_PORT, :default_service => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).path : DEFAULT_PATH, :default_protocol => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).scheme : DEFAULT_PROTOCOL }, aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'], params) end |
Class Method Details
.api ⇒ Object
27 28 29 |
# File 'lib/elb/right_elb_interface.rb', line 27 def self.api @@api end |
.bench_ec2 ⇒ Object
21 22 23 |
# File 'lib/elb/right_elb_interface.rb', line 21 def self.bench_ec2 @@bench.service end |
.bench_xml ⇒ Object
18 19 20 |
# File 'lib/elb/right_elb_interface.rb', line 18 def self.bench_xml @@bench.xml end |
Instance Method Details
#describe_load_balancers ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/elb/right_elb_interface.rb', line 109 def describe_load_balancers @logger.info("Describing Load Balancers") params = {} link = generate_request("DescribeLoadBalancers", params) resp = request_info(link, QElbDescribeLoadBalancersParser.new(:logger => @logger)) rescue Exception on_exception end |
#generate_request(action, params = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elb/right_elb_interface.rb', line 44 def generate_request(action, params={}) service_hash = {"Action" => action, "AWSAccessKeyId" => @aws_access_key_id, "Version" => @@api } service_hash.update(params) service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service]) # use POST method if the length of the query string is too large if service_params.size > 2000 if signature_version == '2' # resign the request because HTTP verb is included into signature service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service]) end request = Net::HTTP::Post.new(service) request.body = service_params request['Content-Type'] = 'application/x-www-form-urlencoded' else request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}") end #puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n" #puts "#{@params[:service]}?#{service_params}\n\n" # prepare output hash { :request => request, :server => @params[:server], :port => @params[:port], :protocol => @params[:protocol] } end |
#register_instance_with_elb(instance_id, lparams = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/elb/right_elb_interface.rb', line 89 def register_instance_with_elb(instance_id, lparams={}) params = {} params['LoadBalancerName'] = lparams[:load_balancer_name] params['Instances.member.1.InstanceId'] = instance_id @logger.info("Registering Instance #{instance_id} with Load Balancer '#{params['LoadBalancerName']}'") link = generate_request("RegisterInstancesWithLoadBalancer", params) resp = request_info(link, QElbRegisterInstanceParser.new(:logger => @logger)) rescue Exception on_exception end |
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened
77 78 79 80 81 |
# File 'lib/elb/right_elb_interface.rb', line 77 def request_info(request, parser) thread = @params[:multi_thread] ? Thread.current : Thread.main thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger) request_info_impl(thread[:elb_connection], @@bench, request, parser) end |