Class: Cumulus::ELB::LoadBalancerDiff
- Inherits:
-
Common::Diff
- Object
- Common::Diff
- Cumulus::ELB::LoadBalancerDiff
- Includes:
- LoadBalancerChange
- Defined in:
- lib/elb/models/LoadBalancerDiff.rb
Overview
Public: Represents a single difference between local configuration and an AWS Load Balancer.
Defined Under Namespace
Classes: BackendChange, TagChange
Constant Summary
Constants included from LoadBalancerChange
Cumulus::ELB::LoadBalancerChange::BACKEND, Cumulus::ELB::LoadBalancerChange::CROSS, Cumulus::ELB::LoadBalancerChange::DRAINING, Cumulus::ELB::LoadBalancerChange::HEALTH, Cumulus::ELB::LoadBalancerChange::IDLE, Cumulus::ELB::LoadBalancerChange::INSTANCES, Cumulus::ELB::LoadBalancerChange::INTERNAL, Cumulus::ELB::LoadBalancerChange::LISTENERS, Cumulus::ELB::LoadBalancerChange::LOG, Cumulus::ELB::LoadBalancerChange::SECURITY, Cumulus::ELB::LoadBalancerChange::SUBNETS, Cumulus::ELB::LoadBalancerChange::TAGS
Constants included from Common::DiffChange
Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED
Instance Attribute Summary collapse
-
#backend_policies ⇒ Object
Returns the value of attribute backend_policies.
-
#health_diffs ⇒ Object
Returns the value of attribute health_diffs.
-
#instances ⇒ Object
Returns the value of attribute instances.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#log_diffs ⇒ Object
Returns the value of attribute log_diffs.
-
#security_groups ⇒ Object
Returns the value of attribute security_groups.
-
#subnets ⇒ Object
Returns the value of attribute subnets.
-
#tags ⇒ Object
Returns the value of attribute tags.
Attributes inherited from Common::Diff
#aws, #changes, #info_only, #local, #type
Class Method Summary collapse
- .access_log(log_diffs) ⇒ Object
- .backend_policies(aws, local) ⇒ Object
- .health_check(health_diffs) ⇒ Object
- .instances(aws, local) ⇒ Object
- .internal(aws, local) ⇒ Object
- .listeners(aws, local) ⇒ Object
- .security_groups(aws, local) ⇒ Object
- .subnets(aws, local) ⇒ Object
- .tags(aws, local) ⇒ Object
Instance Method Summary collapse
Methods included from Common::DiffChange
Methods inherited from Common::Diff
#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string
Constructor Details
This class inherits a constructor from Cumulus::Common::Diff
Instance Attribute Details
#backend_policies ⇒ Object
Returns the value of attribute backend_policies.
37 38 39 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 37 def backend_policies @backend_policies end |
#health_diffs ⇒ Object
Returns the value of attribute health_diffs.
36 37 38 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 36 def health_diffs @health_diffs end |
#instances ⇒ Object
Returns the value of attribute instances.
35 36 37 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 35 def instances @instances end |
#listeners ⇒ Object
Returns the value of attribute listeners.
31 32 33 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 31 def listeners @listeners end |
#log_diffs ⇒ Object
Returns the value of attribute log_diffs.
38 39 40 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 38 def log_diffs @log_diffs end |
#security_groups ⇒ Object
Returns the value of attribute security_groups.
33 34 35 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 33 def security_groups @security_groups end |
#subnets ⇒ Object
Returns the value of attribute subnets.
32 33 34 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 32 def subnets @subnets end |
#tags ⇒ Object
Returns the value of attribute tags.
34 35 36 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 34 def @tags end |
Class Method Details
.access_log(log_diffs) ⇒ Object
149 150 151 152 153 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 149 def self.access_log(log_diffs) diff = LoadBalancerDiff.new(LOG, nil, nil) diff.log_diffs = log_diffs diff end |
.backend_policies(aws, local) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 127 def self.backend_policies(aws, local) # map the aws and local policies to their ports aws_backends = Hash[aws.map { |b| [b.instance_port, b.policy_names] }] local_backends = Hash[local.map { |b| [b.instance_port, b.policy_names] }] added = local_backends.reject { |port, _| aws_backends.has_key? port }.map do |port, policies| BackendChange.new(port, nil, policies) end removed = aws_backends.reject { |port, _| local_backends.has_key? port }.map do |port, policies| BackendChange.new(port, policies, nil) end modified = local_backends.reject { |port, _| !aws_backends.has_key? port }.map do |port, policies| if aws_backends[port].sort != policies.sort BackendChange.new(port, aws_backends[port], policies) end end.reject(&:nil?) diff = LoadBalancerDiff.new(BACKEND, aws, local) diff.backend_policies = Common::ListChange.new(added, removed, modified) diff end |
.health_check(health_diffs) ⇒ Object
120 121 122 123 124 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 120 def self.health_check(health_diffs) diff = LoadBalancerDiff.new(HEALTH, nil, nil) diff.health_diffs = health_diffs diff end |
.instances(aws, local) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 112 def self.instances(aws, local) added = local - aws removed = aws - local diff = LoadBalancerDiff.new(INSTANCES, aws, local) diff.instances = Common::ListChange.new(added, removed) diff end |
.internal(aws, local) ⇒ Object
81 82 83 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 81 def self.internal(aws, local) LoadBalancerDiff.new(INTERNAL, aws, local) end |
.listeners(aws, local) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 40 def self.listeners(aws, local) # map listeners to load balancer port aws_listeners = Hash[aws.map { |l| [l.listener.load_balancer_port, l] }] local_listeners = Hash[local.map { |l| [l.load_balancer_port, l] }] added_listeners = local_listeners.reject { |k, v| aws_listeners.has_key? k } removed_listeners = aws_listeners.reject { |k, v| local_listeners.has_key? k } modified_listeners = local_listeners.select { |k, v| aws_listeners.has_key? k } added_diffs = Hash[added_listeners.map { |port, added| [port, ListenerDiff.added(added)] }] removed_diffs = Hash[removed_listeners.map { |port, removed| [port, ListenerDiff.unmanaged(removed)] }] modified_diffs = Hash[modified_listeners.map do |port, modified| [port, modified.diff(aws_listeners[port])] end].reject { |k, v| v.empty? } if !added_diffs.empty? or !removed_diffs.empty? or !modified_diffs.empty? diff = LoadBalancerDiff.new(LISTENERS, aws, local) diff.listeners = Common::ListChange.new(added_diffs, removed_diffs, modified_diffs) diff end end |
.security_groups(aws, local) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 73 def self.security_groups(aws, local) added = local - aws removed = aws - local diff = LoadBalancerDiff.new(SECURITY, aws, local) diff.security_groups = Common::ListChange.new(added, removed) diff end |
.subnets(aws, local) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 62 def self.subnets(aws, local) local_ids = local.map { |s| s.subnet_id } aws_ids = aws.map { |s| s.subnet_id } added = local.reject { |s| aws_ids.include? s.subnet_id } removed = aws.reject { |s| local_ids.include? s.subnet_id } diff = LoadBalancerDiff.new(SUBNETS, aws, local) diff.subnets = Common::ListChange.new(added, removed) diff end |
.tags(aws, local) ⇒ Object
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 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 86 def self.(aws, local) added = [] removed = [] modified = [] aws.each_pair do |key, val| if local.has_key?(key) if local[key] != val modified << TagChange.new(key, val, local[key]) end else removed << TagChange.new(key, val, nil) end end local.each_pair do |key, val| if !aws.has_key?(key) added << TagChange.new(key, nil, val) end end diff = LoadBalancerDiff.new(TAGS, aws, local) diff. = Common::ListChange.new(added, removed, modified) diff end |
Instance Method Details
#asset_type ⇒ Object
155 156 157 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 155 def asset_type "Load Balancer" end |
#aws_name ⇒ Object
159 160 161 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 159 def aws_name @aws.load_balancer_name end |
#diff_string ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/elb/models/LoadBalancerDiff.rb', line 163 def diff_string case @type when LISTENERS [ "listeners:", @listeners.removed.map { |_, diff| "\t#{diff}" }, @listeners.added.map { |_, diff| "\t#{diff}" }, @listeners.modified.map do |port, diffs| [ "\tListener for port #{port}:", diffs.map do |diff| diff.to_s.lines.map { |l| "\t\t#{l}".chomp("\n") } end ].join("\n") end ].flatten.join("\n") when SUBNETS [ "subnets:", @subnets.removed.map { |s| Colors.removed("\t#{s.subnet_id} (#{s.name})") }, @subnets.added.map { |s| Colors.added("\t#{s.subnet_id} (#{s.name})") }, ].flatten.join("\n") when SECURITY [ "security groups:", @security_groups.removed.map { |s| Colors.removed("\t#{s}") }, @security_groups.added.map { |s| Colors.added("\t#{s}") }, ].flatten.join("\n") when INTERNAL [ "internal:", Colors.aws_changes("\tAWS - #{aws}"), Colors.local_changes("\tLocal - #{local}"), ].join("\n") when TAGS [ "tags:", @tags.removed.map { |t| Colors.removed("\t#{t.key}: #{t.aws}") }, @tags.added.map { |t| Colors.added("\t#{t.key}: #{t.local}") }, @tags.modified.map do |t| [ "\t#{t.key}:", Colors.aws_changes("(AWS) #{t.aws}"), Colors.local_changes("(Local) #{t.local}") ].join(" ") end ].flatten.join("\n") when INSTANCES [ "managed instances:", @instances.removed.map { |i| Colors.removed("\t#{i}") }, @instances.added.map { |i| Colors.added("\t#{i}") }, ].flatten.join("\n") when HEALTH [ "health check:", @health_diffs.map do |d| d.to_s.lines.map { |l| "\t#{l}".chomp("\n") } end ].join("\n") when BACKEND [ "backend policies:", @backend_policies.removed.map { |bc| Colors.removed("\tinstance port #{bc.port}: #{bc.aws_policies.join(" ")}") }, @backend_policies.added.map { |bc| Colors.added("\tinstance port #{bc.port}: #{bc.local_policies.join(" ")}") }, @backend_policies.modified.map do |bc| [ "\tinstance port #{bc.port}:", (bc.aws_policies - bc.local_policies).map { |p| Colors.removed("#{p}") }, (bc.local_policies - bc.aws_policies).map { |p| Colors.added("#{p}") }, ].flatten.join(" ") end ].flatten.join("\n") when CROSS [ "cross zone load balancing:", Colors.aws_changes("\tAWS - #{aws}"), Colors.local_changes("\tLocal - #{local}"), ].flatten.join("\n") when LOG [ "access log:", @log_diffs.map do |d| d.to_s.lines.map { |l| "\t#{l}".chomp("\n") } end ].join("\n") when DRAINING [ "connection draining:", Colors.aws_changes("\tAWS - #{aws}"), Colors.local_changes("\tLocal - #{local}"), ].join("\n") when IDLE [ "idle timeout:", Colors.aws_changes("\tAWS - #{aws}"), Colors.local_changes("\tLocal - #{local}"), ].join("\n") end end |