class Asg::Rebooter::Wrappers::Instance

Constants

HEALTH_STATUS_HEALTHY
LIFECYCLE_CHANGE_POLL_TIMEOUT
LIFECYCLE_IN_SERVICE
LIFECYCLE_STANDBY
POLL_TIMEOUT
SLEEP_AFTER_REBOOT
SLEEP_AFTER_STANDBY

Attributes

instance[R]

Public Class Methods

new(instance) click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 37
def initialize(instance)
  #
  # @instance is of type Aws::AutoScaling::Instance
  #
  # #ec2_instance is of type Aws::EC2::Instance
  #
  @instance = instance
end

Public Instance Methods

ensure_lifecycle_state(state) click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 66
def ensure_lifecycle_state(state)
  loop do
    instance.reload

    break if instance.lifecycle_state == state

    sleep LIFECYCLE_CHANGE_POLL_TIMEOUT
  end

  true
end
enter_standby() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 50
def enter_standby
  # raise when in invalid state for action

  instance.enter_standby(should_decrement_desired_capacity: true)

  ensure_lifecycle_state(LIFECYCLE_STANDBY)
end
exit_standby() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 58
def exit_standby
  # raise if in invalid state for action

  instance.exit_standby

  ensure_lifecycle_state(LIFECYCLE_IN_SERVICE)
end
health_status() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 84
def health_status
  instance.reload.health_status
end
healthy?() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 88
def healthy?
  health_status == HEALTH_STATUS_HEALTHY
end
method_missing(m, *args, &block) click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 46
def method_missing(m, *args, &block)
  instance.send(m, *args, &block)
end
reboot() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 105
def reboot
  ec2_instance.reboot
end
standby?() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 78
def standby?
  instance.reload

  instance.lifecycle_state == LIFECYCLE_STANDBY
end
wait_for_healthy() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 92
def wait_for_healthy
  #
  # TODO: Should check health state on the TargetGroup to ensure the instance is ready for work
  #
  loop do
    break if healthy?

    sleep(POLL_TIMEOUT)
  end

  true
end

Private Instance Methods

ec2_instance() click to toggle source
# File lib/asg/rebooter/wrappers/instance.rb, line 111
def ec2_instance
  Aws::EC2::Instance.new(instance.instance_id)
end