Class: Cumulus::AutoScaling::AutoScalingDiff
- Inherits:
-
Common::Diff
- Object
- Common::Diff
- Cumulus::AutoScaling::AutoScalingDiff
- Includes:
- AutoScalingChange, Common::TagsDiff
- Defined in:
- lib/autoscaling/models/AutoScalingDiff.rb
Overview
Public: Represents a single difference between local configuration and AWS configuration of AutoScaling Groups
Constant Summary
Constants included from AutoScalingChange
Cumulus::AutoScaling::AutoScalingChange::CHECK_GRACE, Cumulus::AutoScaling::AutoScalingChange::CHECK_TYPE, Cumulus::AutoScaling::AutoScalingChange::COOLDOWN, Cumulus::AutoScaling::AutoScalingChange::DESIRED, Cumulus::AutoScaling::AutoScalingChange::LAUNCH, Cumulus::AutoScaling::AutoScalingChange::LOAD_BALANCER, Cumulus::AutoScaling::AutoScalingChange::MAX, Cumulus::AutoScaling::AutoScalingChange::METRICS, Cumulus::AutoScaling::AutoScalingChange::MIN, Cumulus::AutoScaling::AutoScalingChange::POLICY, Cumulus::AutoScaling::AutoScalingChange::SCHEDULED, Cumulus::AutoScaling::AutoScalingChange::SUBNETS, Cumulus::AutoScaling::AutoScalingChange::TAGS, Cumulus::AutoScaling::AutoScalingChange::TERMINATION
Constants included from Common::DiffChange
Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED
Instance Attribute Summary collapse
-
#policy_diffs ⇒ Object
Returns the value of attribute policy_diffs.
Attributes inherited from Common::Diff
#aws, #changes, #info_only, #local, #type
Class Method Summary collapse
-
.policies(local, policy_diffs) ⇒ Object
Public: Static method that will produce a diff that contains changes in scaling policies.
-
.scheduled(aws, local) ⇒ Object
Public: Static method that will produce a diff that contains changes in scheduled actions.
Instance Method Summary collapse
- #asset_type ⇒ Object
- #aws_name ⇒ Object
- #diff_string ⇒ Object
-
#load_balancers_to_add ⇒ Object
Public: Get the load balancers to add, ie.
-
#load_balancers_to_remove ⇒ Object
Public: Get the load balancers to remove, ie.
-
#metrics_to_disable ⇒ Object
Public: Get the metrics to disable, ie.
-
#metrics_to_enable ⇒ Object
Public: Get the metrics to enable, ie.
Methods included from Common::TagsDiff
#tags_diff_string, #tags_to_add, #tags_to_remove
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
#policy_diffs ⇒ Object
Returns the value of attribute policy_diffs.
35 36 37 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 35 def policy_diffs @policy_diffs end |
Class Method Details
.policies(local, policy_diffs) ⇒ Object
Public: Static method that will produce a diff that contains changes in scaling policies
local - the local configuration policy_diffs - the differences in scaling policies
Returns the diff
72 73 74 75 76 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 72 def AutoScalingDiff.policies(local, policy_diffs) diff = AutoScalingDiff.new(POLICY, nil, local) diff.policy_diffs = policy_diffs diff end |
.scheduled(aws, local) ⇒ Object
Public: Static method that will produce a diff that contains changes in scheduled actions
aws - the array of AWS scheduled actions local - the map of scheduled action name to local configuration
Returns the AutoScalingDiff
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 44 def AutoScalingDiff.scheduled(aws, local) aws_scheduled = Hash[aws.map { |s| [s.scheduled_action_name, s] }] removed = aws_scheduled.reject { |k, v| local.include?(k) }.map { |_, sched| ScheduledActionDiff.unmanaged(sched) } added = local.reject { |k, v| aws_scheduled.include? k }.map { |_, sched| ScheduledActionDiff.added(sched) } modified = local.select { |k, v| aws_scheduled.include? k }.map do |name, local_sched| aws_sched = aws_scheduled[name] sched_diffs = local_sched.diff(aws_sched) if !sched_diffs.empty? ScheduledActionDiff.modified(aws_sched, local_sched, sched_diffs) end end.reject { |v| !v } if !removed.empty? or !added.empty? or !modified.empty? diff = AutoScalingDiff.new(AutoScalingChange::SCHEDULED, aws, local) diff.changes = Common::ListChange.new(added, removed, modified) diff end end |
Instance Method Details
#asset_type ⇒ Object
137 138 139 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 137 def asset_type "Autoscaling group" end |
#aws_name ⇒ Object
141 142 143 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 141 def aws_name @aws.auto_scaling_group_name end |
#diff_string ⇒ Object
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 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 78 def diff_string case @type when LAUNCH "Launch configuration: AWS - #{Colors.aws_changes(@aws.launch_configuration_name)}, Local - #{Colors.local_changes(@local.launch)}" when MIN "Min size: AWS - #{Colors.aws_changes(@aws)}, Local - #{Colors.local_changes(@local)}" when MAX "Max size: AWS - #{Colors.aws_changes(@aws)}, Local - #{Colors.local_changes(@local)}" when DESIRED "Desired size: AWS - #{Colors.aws_changes(@aws)}, Local - #{Colors.local_changes(@local)}" when METRICS lines = ["Enabled Metrics:"] lines << metrics_to_disable.map { |m| "\t#{Colors.removed(m)}" } lines << metrics_to_enable.map { |m| "\t#{Colors.added(m)}" } lines.flatten.join("\n") when CHECK_TYPE "Health check type: AWS - #{Colors.aws_changes(@aws.health_check_type)}, Local - #{Colors.local_changes(@local.check_type)}" when CHECK_GRACE "Health check grace period: AWS - #{Colors.aws_changes(@aws.health_check_grace_period)}, Local - #{Colors.local_changes(@local.check_grace)}" when LOAD_BALANCER lines = ["Load balancers:"] lines << load_balancers_to_remove.map { |l| "\t#{Colors.removed(l)}" } lines << load_balancers_to_add.map { |l| "\t#{Colors.added(l)}" } lines.flatten.join("\n") when SUBNETS lines = ["Subnets:"] lines << (@aws - @local).map { |s| s.vpc_subnet_name || s.subnet_id }.map { |s| "\t#{Colors.removed(s)}" } lines << (@local - @aws).map { |s| s.vpc_subnet_name || s.subnet_id }.map { |s| "\t#{Colors.added(s)}" } lines.flatten.join("\n") when TAGS when TERMINATION lines = ["Termination policies:"] lines << (@aws.termination_policies - @local.termination).map { |t| "\t#{Colors.removed(t)}" } lines << (@local.termination - @aws.termination_policies).map { |t| "\t#{Colors.added(t)}" } lines.flatten.join("\n") when COOLDOWN "Cooldown: AWS - #{Colors.aws_changes(@aws.default_cooldown)}, Local - #{Colors.local_changes(@local.cooldown)}" when SCHEDULED [ "Scheduled Actions:", changes.removed.map { |added_diff| "\t#{added_diff}" }, changes.added.map { |removed_diff| "\t#{removed_diff}" }, changes.modified.map do |modified_diff| [ "\t#{modified_diff.local.name}:", modified_diff.changes.map do |scheduled_diff| scheduled_diff.to_s.lines.map { |l| "\t\t#{l}".chomp("\n") } end ] end ].flatten.join("\n") when POLICY lines = ["Scaling policies:"] lines << policy_diffs.map { |d| "\t#{d}" } lines.flatten.join("\n") end end |
#load_balancers_to_add ⇒ Object
Public: Get the load balancers to add, ie. are in local configuration but not in AWS
Returns an array of load balancer names
173 174 175 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 173 def load_balancers_to_add @local.load_balancers - @aws.load_balancer_names end |
#load_balancers_to_remove ⇒ Object
Public: Get the load balancers to remove, ie. are in AWS and not local configuration
Returns an array of load balancer names
165 166 167 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 165 def load_balancers_to_remove @aws.load_balancer_names - @local.load_balancers end |
#metrics_to_disable ⇒ Object
Public: Get the metrics to disable, ie. are in AWS but not in local configuration.
Returns an array of metrics
149 150 151 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 149 def metrics_to_disable @aws.enabled_metrics.map { |k| k.metric }.deep_sort - @local.enabled_metrics.deep_sort end |
#metrics_to_enable ⇒ Object
Public: Get the metrics to enable, ie. are in local configuration, but not AWS.
Returns an array of metrics
157 158 159 |
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 157 def metrics_to_enable @local.enabled_metrics.deep_sort - @aws.enabled_metrics.map { |k| k.metric }.deep_sort end |