Class: Fog::AWS::ELB::LoadBalancer
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::ELB::LoadBalancer
show all
- Defined in:
- lib/fog/aws/models/elb/load_balancer.rb
Instance Attribute Summary
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Model
#inspect, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ LoadBalancer
Returns a new instance of LoadBalancer.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 22
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
attributes['Policies'] ||= {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => []}
super
end
|
Instance Method Details
#apply_security_groups(security_groups) ⇒ Object
77
78
79
80
81
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 77
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
65
66
67
68
69
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 65
def attach_subnets(subnet_ids)
requires :id
data = service.attach_load_balancer_to_subnets(subnet_ids, id).body['AttachLoadBalancerToSubnetsResult']
merge_attributes(data)
end
|
96
97
98
99
100
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 96
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
|
#deregister_instances(instances) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 46
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
165
166
167
168
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 165
def destroy
requires :id
service.delete_load_balancer(id)
end
|
#detach_subnets(subnet_ids) ⇒ Object
71
72
73
74
75
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 71
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
59
60
61
62
63
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 59
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
53
54
55
56
57
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 53
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
83
84
85
86
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 83
def instance_health
requires :id
@instance_health ||= service.describe_instance_health(id).body['DescribeInstanceHealthResult']['InstanceStates']
end
|
#instances_in_service ⇒ Object
88
89
90
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 88
def instances_in_service
instance_health.select{|hash| hash['State'] == 'InService'}.map{|hash| hash['InstanceId']}
end
|
#instances_out_of_service ⇒ Object
92
93
94
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 92
def instances_out_of_service
instance_health.select{|hash| hash['State'] == 'OutOfService'}.map{|hash| hash['InstanceId']}
end
|
#listeners ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 102
def listeners
Fog::AWS::ELB::Listeners.new({
:data => attributes['ListenerDescriptions'],
:service => service,
:load_balancer => self
})
end
|
#policies ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 110
def policies
Fog::AWS::ELB::Policies.new({
:data => attributes['Policies'],
:service => service,
:load_balancer => self
})
end
|
#ready? ⇒ Boolean
135
136
137
138
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 135
def ready?
true
end
|
#register_instances(instances) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 39
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
159
160
161
162
163
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 159
def reload
super
@instance_health = nil
self
end
|
#save ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 140
def save
requires :id
requires :listeners
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
end
|
#set_listener_policy(port, policy_name) ⇒ Object
118
119
120
121
122
123
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 118
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
125
126
127
128
129
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 125
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
|
#unset_listener_policy(port) ⇒ Object
131
132
133
|
# File 'lib/fog/aws/models/elb/load_balancer.rb', line 131
def unset_listener_policy(port)
set_listener_policy(port, [])
end
|