Class: Cumulus::AutoScaling::AutoScalingDiff

Inherits:
Common::Diff show all
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

Attributes inherited from Common::Diff

#aws, #changes, #info_only, #local, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::TagsDiff

#tags_diff_string, #tags_to_add, #tags_to_remove

Methods included from Common::DiffChange

next_change_id

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_diffsObject

Returns the value of attribute policy_diffs.



34
35
36
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 34

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



71
72
73
74
75
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 71

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 43

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_typeObject



136
137
138
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 136

def asset_type
  "Autoscaling group"
end

#aws_nameObject



140
141
142
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 140

def aws_name
  @aws.auto_scaling_group_name
end

#diff_stringObject



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
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 77

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
    tags_diff_string
  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_addObject

Public: Get the load balancers to add, ie. are in local configuration but not in AWS

Returns an array of load balancer names



172
173
174
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 172

def load_balancers_to_add
  @local.load_balancers - @aws.load_balancer_names
end

#load_balancers_to_removeObject

Public: Get the load balancers to remove, ie. are in AWS and not local configuration

Returns an array of load balancer names



164
165
166
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 164

def load_balancers_to_remove
  @aws.load_balancer_names - @local.load_balancers
end

#metrics_to_disableObject

Public: Get the metrics to disable, ie. are in AWS but not in local configuration.

Returns an array of metrics



148
149
150
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 148

def metrics_to_disable
  @aws.enabled_metrics - @local.enabled_metrics
end

#metrics_to_enableObject

Public: Get the metrics to enable, ie. are in local configuration, but not AWS.

Returns an array of metrics



156
157
158
# File 'lib/autoscaling/models/AutoScalingDiff.rb', line 156

def metrics_to_enable
  @local.enabled_metrics - @aws.enabled_metrics
end