Module: RightScale::ShutdownRequestMixin

Included in:
ShutdownRequest, ShutdownRequestProxy
Defined in:
lib/instance/shutdown_request.rb

Overview

Mixin for defining a common interface for a shutdown request class and its proxy class.

Defined Under Namespace

Classes: InvalidLevel, NotInitialized

Constant Summary collapse

CONTINUE =

initial kind; no shutdown requested.

'continue'
REBOOT =

requested a reboot.

'reboot'
STOP =

requested a stop (keep boot volume after shutdown).

'stop'
TERMINATE =

requested a terminate (discard boot volume after shutdown).

'terminate'
LEVELS =

levels.

[CONTINUE, REBOOT, STOP, TERMINATE]

Instance Method Summary collapse

Instance Method Details

#continue?Boolean

true if no shutdown was requested, false if shutdown was requested.

Returns:

  • (Boolean)


50
# File 'lib/instance/shutdown_request.rb', line 50

def continue?; CONTINUE == @level; end

#immediately!Object

Raises:



56
57
58
59
# File 'lib/instance/shutdown_request.rb', line 56

def immediately!
  raise InvalidLevel.new("Immediately is unexpected for current shutdown state") if continue?
  @immediately = true
end

#immediately?Boolean

true if any requested shutdown will interrupt sequence of running scripts immediately (current script is allowed to complete). false to defer shutdown until all outstanding scripts have run.

Returns:

  • (Boolean)


55
# File 'lib/instance/shutdown_request.rb', line 55

def immediately?; @immediately; end

#levelObject

Shutdown request level.



62
# File 'lib/instance/shutdown_request.rb', line 62

def level; @level; end

#level=(value) ⇒ Object

Raises:



63
64
65
66
67
68
69
# File 'lib/instance/shutdown_request.rb', line 63

def level=(value)
  value = value.to_s
  raise InvalidLevel.new("Invalid shutdown level: #{value.inspect}") unless LEVELS.include?(value)

  # strictly escalate to higher level and ignore lower level requests.
  @level = value if LEVELS.index(value) > LEVELS.index(@level)
end

#to_sObject

Stringizer.



72
73
74
75
76
77
# File 'lib/instance/shutdown_request.rb', line 72

def to_s
  # note that printing 'deferred' would seem strange at the time when the
  # deferred shutdown is actually being processed, so only say immediately.
  immediacy = if @immediately; ' immediately'; else; ''; end
  return "#{@level}#{immediacy}"
end