class Asg::Rebooter::InstanceRebooter

Constants

REBOOT_TIMEOUT

Attributes

asg[R]
asg_config[R]
target_group_config[R]

Public Class Methods

new(asg) click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 8
def initialize(asg)
  @asg = asg
end

Public Instance Methods

execute() click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 12
def execute
  puts "[start] Starting reboot sequence for: #{asg.name}"

  begin
    prepare_configuration

    instances.each do |instance|
      puts "#{'*' * 4} #{instance.instance_id} #{'*' * 4}"
      puts "#{instance.instance_id} [enter_standby]"
      instance.enter_standby

      puts "#{instance.instance_id} [reboot]"
      instance.reboot

      sleep REBOOT_TIMEOUT # TODO: Ensure instance is rebooted: how to do this?

      puts "#{instance.instance_id} [exit_standby]"
      instance.exit_standby

      puts "#{instance.instance_id} [wait_for_healthy]"
      target_group.wait_for_healthy(instance)

      puts "\n"
    end
  ensure
    restore_configuration
  end
end

Private Instance Methods

instances() click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 43
def instances
  asg.instances
end
prepare_configuration() click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 51
def prepare_configuration
  @asg_config = Asg::Rebooter::Configuration::AutoScalingGroup.new(asg)

  @target_group_config = asg.target_groups.map do |target_group|
    Asg::Rebooter::Configuration::TargetGroup.new(target_group)
  end

  asg_config.prepare
  target_group_config.each(&:prepare)
end
restore_configuration() click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 62
def restore_configuration
  asg_config.restore
  target_group_config.each(&:restore)
end
target_group() click to toggle source
# File lib/asg/rebooter/instance_rebooter.rb, line 47
def target_group
  asg.target_groups.first
end