Class: Aws::Elb
- Includes:
- AwsBaseInterface
- Defined in:
- lib/elb/elb_interface.rb
Defined Under Namespace
Classes: QElbConfigureHealthCheckParser, QElbCreateParser, QElbDescribeInstancesHealthParser, QElbDescribeLoadBalancersParser, QElbEmptyResponseParser, QElbRegisterInstancesParser
Constant Summary collapse
- API_VERSION =
Amazon ELB API version being used
"2012-06-01"
- 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, #last_errors, #last_request, #last_request_id, #last_response, #logger, #params, #signature_version
Class Method Summary collapse
Instance Method Summary collapse
-
#configure_health_check(name, healthy_threshold, unhealthy_threshold, interval, target, timeout) ⇒ Object
name: name of load balancer healthy_threshold: number of successful probes required to enter Healthy state.
-
#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”.
-
#create_load_balancer_listeners(name, listeners) ⇒ Object
name: name of load balancer listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol eg: :instance_port=>8080, :protocol=>“HTTP”.
- #delete_load_balancer(name) ⇒ Object
-
#delete_load_balancer_listeners(name, ports) ⇒ Object
name: name of load balancer ports: array of client port number(s) of the load balancer listener(s) to be removed.
- #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, options = {}) ⇒ 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, #close_connection, #connection, #escape_params, #generate_request, #generate_request2, #get_conn, #hash_params, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info2, #request_info3, #request_info_impl, #request_info_xml_simple, #request_info_xml_simple3, #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.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elb/elb_interface.rb', line 43 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
38 39 40 |
# File 'lib/elb/elb_interface.rb', line 38 def self.api @@api end |
.bench ⇒ Object
23 24 25 |
# File 'lib/elb/elb_interface.rb', line 23 def self.bench @@bench end |
.bench_ec2 ⇒ Object
31 32 33 |
# File 'lib/elb/elb_interface.rb', line 31 def self.bench_ec2 @@bench.service end |
.bench_xml ⇒ Object
27 28 29 |
# File 'lib/elb/elb_interface.rb', line 27 def self.bench_xml @@bench.xml end |
.connection_name ⇒ Object
17 18 19 |
# File 'lib/elb/elb_interface.rb', line 17 def self.connection_name :elb_connection end |
Instance Method Details
#configure_health_check(name, healthy_threshold, unhealthy_threshold, interval, target, timeout) ⇒ Object
name: name of load balancer healthy_threshold: number of successful probes required to enter Healthy state. unhealthy_threshold: number of unsuccessful probes required to enter Unhealthy state. interval: interval between probes (seconds) target: probe target (protocol:port) timeout: probe response timeout
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/elb/elb_interface.rb', line 204 def configure_health_check(name, healthy_threshold, unhealthy_threshold, interval, target, timeout ) params = {} params['LoadBalancerName'] = name params['HealthCheck.HealthyThreshold'] = "#{healthy_threshold}" params['HealthCheck.UnhealthyThreshold'] = "#{unhealthy_threshold}" params['HealthCheck.Interval'] = "#{interval}" params['HealthCheck.Target'] = target params['HealthCheck.Timeout'] = "#{timeout}" @logger.info("Configuring health check for Load Balancer '#{name}'") link = generate_request("ConfigureHealthCheck", params) resp = request_info(link, QElbConfigureHealthCheckParser.new(:logger => @logger)) rescue Exception on_exception end |
#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"}
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/elb/elb_interface.rb', line 91 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 |
#create_load_balancer_listeners(name, listeners) ⇒ Object
name: name of load balancer listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol
eg: {:load_balancer_port=>80, :instance_port=>8080, :protocol=>"HTTP"}
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/elb/elb_interface.rb', line 116 def create_load_balancer_listeners(name, listeners) params = {} params['LoadBalancerName'] = name 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 @logger.info("Creating Listeners for LoadBalancer #{name}") link = generate_request("CreateLoadBalancerListeners", params) resp = request_info(link, QElbEmptyResponseParser.new(:logger => @logger)) rescue Exception on_exception end |
#delete_load_balancer(name) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/elb/elb_interface.rb', line 261 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, QElbEmptyResponseParser.new(:logger => @logger)) rescue Exception on_exception end |
#delete_load_balancer_listeners(name, ports) ⇒ Object
name: name of load balancer ports: array of client port number(s) of the load balancer listener(s) to be removed.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/elb/elb_interface.rb', line 140 def delete_load_balancer_listeners(name, ports) params = {} params['LoadBalancerName'] = name i = 1 ports.each do |l| params["LoadBalancerPorts.member.#{i}"] = "#{l}" i += 1 end @logger.info("Deleting Listeners for LoadBalancer #{name}") link = generate_request("DeleteLoadBalancerListeners", params) resp = request_info(link, QElbEmptyResponseParser.new(:logger => @logger)) rescue Exception on_exception end |
#deregister_instances_from_load_balancer(name, instance_ids) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/elb/elb_interface.rb', line 179 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
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/elb/elb_interface.rb', line 238 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
223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/elb/elb_interface.rb', line 223 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/elb/elb_interface.rb', line 63 def do_request(action, params, ={}) link = generate_request(action, params) resp = request_info_xml_simple(self.class.connection_name, @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
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/elb/elb_interface.rb', line 160 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, options = {}) ⇒ Object
Sends request to Amazon and parses the response Raises AwsError if any banana happened
58 59 60 |
# File 'lib/elb/elb_interface.rb', line 58 def request_info(request, parser, ={}) request_info2(request, parser, @params, self.class.connection_name, @logger, @@bench, ) end |