Class: Fog::AWS::ELB::LoadBalancer
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::ELB::LoadBalancer
- Defined in:
- lib/fog/aws/models/elb/load_balancer.rb
Instance Method Summary collapse
- #add_tags(new_tags) ⇒ Object
- #apply_security_groups(security_groups) ⇒ Object
- #attach_subnets(subnet_ids) ⇒ Object
- #backend_server_descriptions ⇒ Object
- #configure_health_check(health_check) ⇒ Object
- #connection_draining? ⇒ Boolean
- #connection_draining_timeout ⇒ Object
- #connection_settings_idle_timeout ⇒ Object
- #cross_zone_load_balancing=(value) ⇒ Object
- #cross_zone_load_balancing? ⇒ Boolean
- #deregister_instances(instances) ⇒ Object
- #destroy ⇒ Object
- #detach_subnets(subnet_ids) ⇒ Object
- #disable_availability_zones(zones) ⇒ Object
- #enable_availability_zones(zones) ⇒ Object
-
#initialize(attributes = {}) ⇒ LoadBalancer
constructor
A new instance of LoadBalancer.
- #instance_health ⇒ Object
- #instances_in_service ⇒ Object
- #instances_out_of_service ⇒ Object
- #listeners ⇒ Object
- #policies ⇒ Object
- #policy_descriptions ⇒ Object
- #ready? ⇒ Boolean
- #register_instances(instances) ⇒ Object
- #reload ⇒ Object
- #remove_tags(tag_keys) ⇒ Object
- #save ⇒ Object
- #set_connection_draining(enabled, timeout = nil) ⇒ Object
- #set_connection_settings_idle_timeout(timeout = 60) ⇒ Object
- #set_listener_policy(port, policy_name) ⇒ Object
- #set_listener_ssl_certificate(port, ssl_certificate_id) ⇒ Object
- #tags ⇒ Object
- #unset_listener_policy(port) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ LoadBalancer
Returns a new instance of LoadBalancer.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 21 def initialize(attributes={}) if attributes[:subnet_ids] ||= attributes['Subnets'] attributes[:availability_zones] ||= attributes['AvailabilityZones'] else attributes[:availability_zones] ||= attributes['AvailabilityZones'] || %w(us-east-1a us-east-1b us-east-1c us-east-1d) end unless attributes['ListenerDescriptions'] new_listener = Fog::AWS::ELB::Listener.new attributes['ListenerDescriptions'] = [{ 'Listener' => new_listener.to_params, 'PolicyNames' => new_listener.policy_names }] end super end |
Instance Method Details
#add_tags(new_tags) ⇒ Object
195 196 197 198 199 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 195 def () requires :id service.(id, ) end |
#apply_security_groups(security_groups) ⇒ Object
113 114 115 116 117 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 113 def apply_security_groups(security_groups) requires :id data = service.apply_security_groups_to_load_balancer(security_groups, id).body['ApplySecurityGroupsToLoadBalancerResult'] merge_attributes(data) end |
#attach_subnets(subnet_ids) ⇒ Object
101 102 103 104 105 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 101 def attach_subnets(subnet_ids) requires :id data = service.attach_load_balancer_to_subnets(subnet_ids, id).body['AttachLoadBalancerToSubnetsResult'] merge_attributes(data) end |
#backend_server_descriptions ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 138 def backend_server_descriptions Fog::AWS::ELB::BackendServerDescriptions.new({ :data => attributes['BackendServerDescriptions'], :service => service, :load_balancer => self }) end |
#configure_health_check(health_check) ⇒ Object
132 133 134 135 136 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 132 def configure_health_check(health_check) requires :id data = service.configure_health_check(id, health_check).body['ConfigureHealthCheckResult']['HealthCheck'] merge_attributes(:health_check => data) end |
#connection_draining? ⇒ Boolean
37 38 39 40 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 37 def connection_draining? requires :id service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Enabled'] end |
#connection_draining_timeout ⇒ Object
42 43 44 45 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 42 def connection_draining_timeout requires :id service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Timeout'] end |
#connection_settings_idle_timeout ⇒ Object
64 65 66 67 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 64 def connection_settings_idle_timeout requires :id service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionSettings']['IdleTimeout'] end |
#cross_zone_load_balancing=(value) ⇒ Object
59 60 61 62 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 59 def cross_zone_load_balancing= value requires :id service.modify_load_balancer_attributes(id, 'CrossZoneLoadBalancing' => {'Enabled' => value}) end |
#cross_zone_load_balancing? ⇒ Boolean
54 55 56 57 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 54 def cross_zone_load_balancing? requires :id service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing']['Enabled'] end |
#deregister_instances(instances) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 82 def deregister_instances(instances) requires :id data = service.deregister_instances_from_load_balancer(instances, id).body['DeregisterInstancesFromLoadBalancerResult'] data['Instances'].map!{|h| h['InstanceId']} merge_attributes(data) end |
#destroy ⇒ Object
234 235 236 237 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 234 def destroy requires :id service.delete_load_balancer(id) end |
#detach_subnets(subnet_ids) ⇒ Object
107 108 109 110 111 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 107 def detach_subnets(subnet_ids) requires :id data = service.detach_load_balancer_from_subnets(subnet_ids, id).body['DetachLoadBalancerFromSubnetsResult'] merge_attributes(data) end |
#disable_availability_zones(zones) ⇒ Object
95 96 97 98 99 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 95 def disable_availability_zones(zones) requires :id data = service.disable_availability_zones_for_load_balancer(zones, id).body['DisableAvailabilityZonesForLoadBalancerResult'] merge_attributes(data) end |
#enable_availability_zones(zones) ⇒ Object
89 90 91 92 93 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 89 def enable_availability_zones(zones) requires :id data = service.enable_availability_zones_for_load_balancer(zones, id).body['EnableAvailabilityZonesForLoadBalancerResult'] merge_attributes(data) end |
#instance_health ⇒ Object
119 120 121 122 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 119 def instance_health requires :id @instance_health ||= service.describe_instance_health(id).body['DescribeInstanceHealthResult']['InstanceStates'] end |
#instances_in_service ⇒ Object
124 125 126 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 124 def instances_in_service instance_health.select{|hash| hash['State'] == 'InService'}.map{|hash| hash['InstanceId']} end |
#instances_out_of_service ⇒ Object
128 129 130 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 128 def instances_out_of_service instance_health.select{|hash| hash['State'] == 'OutOfService'}.map{|hash| hash['InstanceId']} end |
#listeners ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 146 def listeners Fog::AWS::ELB::Listeners.new({ :data => attributes['ListenerDescriptions'], :service => service, :load_balancer => self }) end |
#policies ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 154 def policies Fog::AWS::ELB::Policies.new({ :data => policy_descriptions, :service => service, :load_balancer => self }) end |
#policy_descriptions ⇒ Object
162 163 164 165 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 162 def policy_descriptions requires :id @policy_descriptions ||= service.describe_load_balancer_policies(id).body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"] end |
#ready? ⇒ Boolean
184 185 186 187 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 184 def ready? # ELB requests are synchronous true end |
#register_instances(instances) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 75 def register_instances(instances) requires :id data = service.register_instances_with_load_balancer(instances, id).body['RegisterInstancesWithLoadBalancerResult'] data['Instances'].map!{|h| h['InstanceId']} merge_attributes(data) end |
#reload ⇒ Object
227 228 229 230 231 232 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 227 def reload super @instance_health = nil @policy_descriptions = nil self end |
#remove_tags(tag_keys) ⇒ Object
201 202 203 204 205 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 201 def (tag_keys) requires :id service.(id, tag_keys) end |
#save ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 208 def save requires :id requires :listeners # with the VPC release, the ELB can have either availability zones or subnets # if both are specified, the availability zones have preference #requires :availability_zones if (availability_zones || subnet_ids) service.create_load_balancer(availability_zones, id, listeners.map{|l| l.to_params}) if availability_zones service.create_load_balancer(nil, id, listeners.map{|l| l.to_params}, {:subnet_ids => subnet_ids, :security_groups => security_groups, :scheme => scheme}) if subnet_ids && !availability_zones else throw Fog::Errors::Error.new("No availability zones or subnet ids specified") end # reload instead of merge attributes b/c some attrs (like HealthCheck) # may be set, but only the DNS name is returned in the create_load_balance # API call reload end |
#set_connection_draining(enabled, timeout = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 47 def set_connection_draining(enabled, timeout=nil) requires :id attrs = {'Enabled' => enabled} attrs['Timeout'] = timeout if timeout service.modify_load_balancer_attributes(id, 'ConnectionDraining' => attrs) end |
#set_connection_settings_idle_timeout(timeout = 60) ⇒ Object
69 70 71 72 73 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 69 def set_connection_settings_idle_timeout(timeout=60) requires :id attrs = {'IdleTimeout' => timeout} service.modify_load_balancer_attributes(id,'ConnectionSettings' => attrs) end |
#set_listener_policy(port, policy_name) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 167 def set_listener_policy(port, policy_name) requires :id policy_name = [policy_name].flatten service.set_load_balancer_policies_of_listener(id, port, policy_name) reload end |
#set_listener_ssl_certificate(port, ssl_certificate_id) ⇒ Object
174 175 176 177 178 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 174 def set_listener_ssl_certificate(port, ssl_certificate_id) requires :id service.set_load_balancer_listener_ssl_certificate(id, port, ssl_certificate_id) reload end |
#tags ⇒ Object
189 190 191 192 193 194 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 189 def requires :id service.(id). body['DescribeTagsResult']["LoadBalancers"][0]["Tags"] end |
#unset_listener_policy(port) ⇒ Object
180 181 182 |
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 180 def unset_listener_policy(port) set_listener_policy(port, []) end |