Class: Aws::Elb
- Includes:
- AwsBaseInterface
- Defined in:
- lib/elb/elb_interface.rb
Defined Under Namespace
Classes: QElbCreateParser, QElbDeleteParser, QElbDescribeInstancesHealthParser, QElbDescribeLoadBalancersParser, QElbRegisterInstancesParser
Constant Summary collapse
- API_VERSION =
Amazon ELB API version being used
"2009-05-15"
- DEFAULT_HOST =
"elasticloadbalancing.amazonaws.com"
- DEFAULT_PATH =
'/'
- DEFAULT_PROTOCOL =
'https'
- DEFAULT_PORT =
443
- @@bench =
AwsBenchmarkingBlock.new
- @@api =
Current API version (sometimes we have to check it outside the GEM).
ENV['ELB_API_VERSION'] || API_VERSION
Constants included from AwsBaseInterface
AwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from AwsBase
Instance Attribute Summary
Attributes included from AwsBaseInterface
#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
-
#create_load_balancer(name, availability_zones, listeners) ⇒ Object
name: name of load balancer availability_zones: array of zones listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol eg: :instance_port=>8080, :protocol=>“HTTP”.
- #delete_load_balancer(name) ⇒ Object
- #deregister_instances_from_load_balancer(name, instance_ids) ⇒ Object
- #describe_instance_health(name, instance_ids = []) ⇒ Object
- #describe_load_balancers(lparams = {}) ⇒ Object
-
#do_request(action, params, options = {}) ⇒ Object
todo: convert to xml-simple version and get rid of parser below.
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Elb
constructor
A new instance of Elb.
-
#register_instances_with_load_balancer(name, instance_ids) ⇒ Object
name: name of load balancer instance_ids: array of instance_id’s to add to load balancer.
-
#request_info(request, parser) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened.
Methods included from AwsBaseInterface
#cache_hits?, caching, caching=, #caching?, #close_conn, #generate_request, #generate_request2, #get_conn, #hash_params, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info2, #request_info_impl, #request_info_xml_simple, #signed_service_params, #symbolize, #update_cache
Methods inherited from AwsBase
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.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elb/elb_interface.rb', line 36 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, :api_version => API_VERSION }, 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
31 32 33 |
# File 'lib/elb/elb_interface.rb', line 31 def self.api @@api end |
.bench_ec2 ⇒ Object
24 25 26 |
# File 'lib/elb/elb_interface.rb', line 24 def self.bench_ec2 @@bench.service end |
.bench_xml ⇒ Object
20 21 22 |
# File 'lib/elb/elb_interface.rb', line 20 def self.bench_xml @@bench.xml end |
Instance Method Details
#create_load_balancer(name, availability_zones, listeners) ⇒ Object
name: name of load balancer availability_zones: array of zones listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol
eg: {:load_balancer_port=>80, :instance_port=>8080, :protocol=>"HTTP"}
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/elb/elb_interface.rb', line 84 def create_load_balancer(name, availability_zones, listeners) params = hash_params('AvailabilityZones.member', availability_zones) i = 1 listeners.each do |l| params["Listeners.member.#{i}.Protocol"] = "#{l[:protocol]}" params["Listeners.member.#{i}.LoadBalancerPort"] = "#{l[:load_balancer_port]}" params["Listeners.member.#{i}.InstancePort"] = "#{l[:instance_port]}" i += 1 end params['LoadBalancerName'] = name @logger.info("Creating LoadBalancer called #{params['LoadBalancerName']}") link = generate_request("CreateLoadBalancer", params) resp = request_info(link, QElbCreateParser.new(:logger => @logger)) rescue Exception on_exception end |
#delete_load_balancer(name) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/elb/elb_interface.rb', line 184 def delete_load_balancer(name) @logger.info("Deleting Load Balancer - " + name.to_s) params = {} params['LoadBalancerName'] = name link = generate_request("DeleteLoadBalancer", params) resp = request_info(link, QElbDeleteParser.new(:logger => @logger)) rescue Exception on_exception end |
#deregister_instances_from_load_balancer(name, instance_ids) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/elb/elb_interface.rb', line 126 def deregister_instances_from_load_balancer(name, instance_ids) params = {} params['LoadBalancerName'] = name i = 1 instance_ids.each do |l| params["Instances.member.#{i}.InstanceId"] = "#{l}" i += 1 end @logger.info("Deregistering Instances #{instance_ids.join(',')} from Load Balancer '#{name}'") link = generate_request("DeregisterInstancesFromLoadBalancer", params) # Same response as register I believe resp = request_info(link, QElbRegisterInstancesParser.new(:logger => @logger)) rescue Exception on_exception end |
#describe_instance_health(name, instance_ids = []) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/elb/elb_interface.rb', line 161 def describe_instance_health(name, instance_ids=[]) instance_ids = [instance_ids] if instance_ids.is_a?(String) # @logger.info("Describing Instance Health") params = {} params['LoadBalancerName'] = name i = 1 instance_ids.each do |l| params["Instances.member.#{i}.InstanceId"] = "#{l}" i += 1 end @logger.info("Describing Instances Health #{instance_ids.join(',')} with Load Balancer '#{name}'") link = generate_request("DescribeInstanceHealth", params) resp = request_info(link, QElbDescribeInstancesHealthParser.new(:logger => @logger)) rescue Exception on_exception end |
#describe_load_balancers(lparams = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/elb/elb_interface.rb', line 146 def describe_load_balancers(lparams={}) @logger.info("Describing Load Balancers") params = {} params.update( hash_params('LoadBalancerNames.member', lparams[:names]) ) if lparams[:names] link = generate_request("DescribeLoadBalancers", params) resp = request_info(link, QElbDescribeLoadBalancersParser.new(:logger => @logger)) rescue Exception on_exception end |
#do_request(action, params, options = {}) ⇒ Object
todo: convert to xml-simple version and get rid of parser below
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elb/elb_interface.rb', line 56 def do_request(action, params, ={}) link = generate_request(action, params) resp = request_info_xml_simple(:rds_connection, @params, link, @logger, :group_tags=>{"LoadBalancersDescriptions"=>"LoadBalancersDescription", "DBParameterGroups"=>"DBParameterGroup", "DBSecurityGroups"=>"DBSecurityGroup", "EC2SecurityGroups"=>"EC2SecurityGroup", "IPRanges"=>"IPRange"}, :force_array=>["DBInstances", "DBParameterGroups", "DBSecurityGroups", "EC2SecurityGroups", "IPRanges"], :pull_out_array=>[:pull_out_array], :pull_out_single=>[:pull_out_single], :wrapper=>[:wrapper]) end |
#register_instances_with_load_balancer(name, instance_ids) ⇒ Object
name: name of load balancer instance_ids: array of instance_id’s to add to load balancer
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/elb/elb_interface.rb', line 107 def register_instances_with_load_balancer(name, instance_ids) params = {} params['LoadBalancerName'] = name i = 1 instance_ids.each do |l| params["Instances.member.#{i}.InstanceId"] = "#{l}" i += 1 end @logger.info("Registering Instances #{instance_ids.join(',')} with Load Balancer '#{name}'") link = generate_request("RegisterInstancesWithLoadBalancer", params) resp = request_info(link, QElbRegisterInstancesParser.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
51 52 53 |
# File 'lib/elb/elb_interface.rb', line 51 def request_info(request, parser) request_info2(request, parser, @params, :elb_connection, @logger, @@bench) end |