43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/kelbim/wrapper/load-balancer.rb', line 43
def update(dsl)
log(:info, 'Update LoadBalancer', :green, log_id)
compare_instances(dsl) do |aws_instance_ids, dsl_instance_ids|
instance_names = @options.instance_names[self.vpc_id] || {}
add_ids = (dsl_instance_ids - aws_instance_ids)
unless add_ids.empty?
log(:info, ' register instances=' + add_ids.map {|i| instance_names.fetch(i, i) }.join(', '), :green)
unless @options.dry_run
@load_balancer.instances.register(*add_ids)
@options.updated = true
end
end
del_ids = (aws_instance_ids - dsl_instance_ids)
unless del_ids.empty?
log(:info, ' deregister instances=' + del_ids.map {|i| instance_names.fetch(i, i) }.join(', '), :green)
unless @options.dry_run
@load_balancer.instances.deregister(*del_ids)
@options.updated = true
end
end
end
compare_health_check(dsl) do
log(:info, ' set health_check=' + dsl.health_check.inspect, :green)
unless @options.dry_run
@load_balancer.configure_health_check(dsl.health_check)
@options.updated = true
end
end
compare_attributes(dsl) do
log(:info, ' set attributes=' + dsl.attributes.inspect, :green)
unless @options.dry_run
@load_balancer.attributes = dsl.attributes
@options.updated = true
end
end
if self.vpc_id
compare_subnet_ids(dsl) do |aws_subnet_ids, dsl_subnet_ids|
add_ids = (dsl_subnet_ids - aws_subnet_ids)
unless add_ids.empty?
log(:info, ' attach subnets=' + add_ids.join(', '), :green)
unless @options.dry_run
@options.elb.client.attach_load_balancer_to_subnets(
:load_balancer_name => @load_balancer.name,
:subnets => add_ids,
)
@options.updated = true
end
end
del_ids = (aws_subnet_ids - dsl_subnet_ids)
unless del_ids.empty?
log(:info, ' detach subnets=' + del_ids.join(', '), :green)
unless @options.dry_run
@options.elb.client.detach_load_balancer_from_subnets(
:load_balancer_name => @load_balancer.name,
:subnets => del_ids,
)
@options.updated = true
end
end
end
compare_security_groups(dsl) do |dsl_sg_ids|
sg_names = @options.security_group_names[self.vpc_id] || {}
log(:info, ' apply security groups=' + dsl_sg_ids.map {|i| sg_names.fetch(i, i) }.join(', '), :green)
unless @options.dry_run
@options.elb.client.apply_security_groups_to_load_balancer(
:load_balancer_name => @load_balancer.name,
:security_groups => dsl_sg_ids,
)
@options.updated = true
end
end
else
compare_availability_zones(dsl) do |aws_az_names, dsl_az_names|
add_names = (dsl_az_names - aws_az_names)
unless add_names.empty?
log(:info, ' enable availability zones=' + add_names.join(', '), :green)
unless @options.dry_run
add_names.each do |az_name|
@load_balancer.availability_zones.enable(az_name)
end
@options.updated = true
end
end
del_names = (aws_az_names - dsl_az_names)
unless del_names.empty?
log(:info, ' disable availability zones=' + del_names.join(', '), :green)
unless @options.dry_run
del_names.each do |az_name|
@load_balancer.availability_zones.disable(az_name)
end
@options.updated = true
end
end
end
end
end
|