Class: Ec2::Blackout::AutoScalingGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2-blackout/auto_scaling_group.rb

Constant Summary collapse

TIMESTAMP_TAG_NAME =
'ec2:blackout:on'
DESIRED_CAPACITY_TAG_NAME =
'ec2:blackout:desired_capacity'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, options) ⇒ AutoScalingGroup

Returns a new instance of AutoScalingGroup


13
14
15
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 13

def initialize(group, options)
  @group, @options = group, options
end

Class Method Details

.groups(region, options) ⇒ Object


7
8
9
10
11
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 7

def self.groups(region, options)
  AWS::AutoScaling.new(:region => region).groups.map do |group|
    Ec2::Blackout::AutoScalingGroup.new(group, options)
  end
end

Instance Method Details

#startObject


22
23
24
25
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 22

def start
  restore_desired_capacity
  untag
end

#startable?Boolean

Returns:

  • (Boolean)

43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 43

def startable?
  if @group.max_size == 0
    [false, "maximum ASG size is zero"]
  elsif @options.force
    true
  elsif !tags[TIMESTAMP_TAG_NAME]
    [false, "instance was not originally stopped by ec2-blackout"]
  else
    true
  end
end

#stopObject


17
18
19
20
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 17

def stop
  tag
  zero_desired_capacity
end

#stoppable?Boolean

Returns:

  • (Boolean)

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 27

def stoppable?
  AWS.memoize do
    if @options.matches_exclude_tags?(tags)
      [false, "matches exclude tags"]
    elsif !@options.matches_include_tags?(tags)
      [false, "does not match include tags"]
    elsif @group.desired_capacity == 0
      [false, "group has already been stopped"]
    elsif @group.min_size > 0
      [false, "minimum ASG size is greater than zero - set min_size to 0 if you want to be able to stop this AutoScalingGroup"]
    else
      true
    end
  end
end

#to_sObject


55
56
57
# File 'lib/ec2-blackout/auto_scaling_group.rb', line 55

def to_s
  "autoscaling group #{@group.name}"
end