Class: Fog::AWS::ELB::LoadBalancer

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/elb/load_balancer.rb

Instance Method Summary (collapse)

Constructor Details

- (LoadBalancer) initialize(attributes = {})

Returns a new instance of LoadBalancer



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 20

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

- (Object) apply_security_groups(security_groups)



101
102
103
104
105
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 101

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

- (Object) attach_subnets(subnet_ids)



89
90
91
92
93
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 89

def attach_subnets(subnet_ids)
  requires :id
  data = service.attach_load_balancer_to_subnets(subnet_ids, id).body['AttachLoadBalancerToSubnetsResult']
  merge_attributes(data)
end

- (Object) backend_server_descriptions



126
127
128
129
130
131
132
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 126

def backend_server_descriptions
  Fog::AWS::ELB::BackendServerDescriptions.new({
    :data => attributes['BackendServerDescriptions'],
    :service => service,
    :load_balancer => self
  })
end

- (Object) configure_health_check(health_check)



120
121
122
123
124
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 120

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

- (Boolean) connection_draining?

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 36

def connection_draining?
  requires :id
  service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Enabled']
end

- (Object) connection_draining_timeout



41
42
43
44
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 41

def connection_draining_timeout
  requires :id
  service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['ConnectionDraining']['Timeout']
end

- (Object) cross_zone_load_balancing=(value)



58
59
60
61
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 58

def cross_zone_load_balancing= value
  requires :id
  service.modify_load_balancer_attributes(id, 'CrossZoneLoadBalancing' => {'Enabled' => value})
end

- (Boolean) cross_zone_load_balancing?

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 53

def cross_zone_load_balancing?
  requires :id
  service.describe_load_balancer_attributes(id).body['DescribeLoadBalancerAttributesResult']['LoadBalancerAttributes']['CrossZoneLoadBalancing']['Enabled']
end

- (Object) deregister_instances(instances)



70
71
72
73
74
75
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 70

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

- (Object) destroy



203
204
205
206
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 203

def destroy
  requires :id
  service.delete_load_balancer(id)
end

- (Object) detach_subnets(subnet_ids)



95
96
97
98
99
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 95

def detach_subnets(subnet_ids)
  requires :id
  data = service.detach_load_balancer_from_subnets(subnet_ids, id).body['DetachLoadBalancerFromSubnetsResult']
  merge_attributes(data)
end

- (Object) disable_availability_zones(zones)



83
84
85
86
87
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 83

def disable_availability_zones(zones)
  requires :id
  data = service.disable_availability_zones_for_load_balancer(zones, id).body['DisableAvailabilityZonesForLoadBalancerResult']
  merge_attributes(data)
end

- (Object) enable_availability_zones(zones)



77
78
79
80
81
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 77

def enable_availability_zones(zones)
  requires :id
  data = service.enable_availability_zones_for_load_balancer(zones, id).body['EnableAvailabilityZonesForLoadBalancerResult']
  merge_attributes(data)
end

- (Object) instance_health



107
108
109
110
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 107

def instance_health
  requires :id
  @instance_health ||= service.describe_instance_health(id).body['DescribeInstanceHealthResult']['InstanceStates']
end

- (Object) instances_in_service



112
113
114
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 112

def instances_in_service
  instance_health.select{|hash| hash['State'] == 'InService'}.map{|hash| hash['InstanceId']}
end

- (Object) instances_out_of_service



116
117
118
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 116

def instances_out_of_service
  instance_health.select{|hash| hash['State'] == 'OutOfService'}.map{|hash| hash['InstanceId']}
end

- (Object) listeners



134
135
136
137
138
139
140
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 134

def listeners
  Fog::AWS::ELB::Listeners.new({
    :data => attributes['ListenerDescriptions'],
    :service => service,
    :load_balancer => self
  })
end

- (Object) policies



142
143
144
145
146
147
148
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 142

def policies
  Fog::AWS::ELB::Policies.new({
    :data => policy_descriptions,
    :service => service,
    :load_balancer => self
  })
end

- (Object) policy_descriptions



150
151
152
153
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 150

def policy_descriptions
  requires :id
  @policy_descriptions ||= service.describe_load_balancer_policies(id).body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"]
end

- (Boolean) ready?

Returns:

  • (Boolean)


172
173
174
175
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 172

def ready?
  # ELB requests are synchronous
  true
end

- (Object) register_instances(instances)



63
64
65
66
67
68
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 63

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

- (Object) reload



196
197
198
199
200
201
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 196

def reload
  super
  @instance_health = nil
  @policy_descriptions = nil
  self
end

- (Object) save



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 177

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

- (Object) set_connection_draining(enabled, timeout = nil)



46
47
48
49
50
51
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 46

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

- (Object) set_listener_policy(port, policy_name)



155
156
157
158
159
160
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 155

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

- (Object) set_listener_ssl_certificate(port, ssl_certificate_id)



162
163
164
165
166
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 162

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

- (Object) unset_listener_policy(port)



168
169
170
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 168

def unset_listener_policy(port)
  set_listener_policy(port, [])
end