Class: Bosh::Cli::JobState

Inherits:
Object show all
Defined in:
lib/cli/job_state.rb

Constant Summary collapse

OPERATION_DESCRIPTIONS =
{
    start: 'start %s',
    stop: 'stop %s',
    detach: 'stop %s and power off its VM(s)',
    restart: 'restart %s',
    recreate: 'recreate %s'
}
NEW_STATES =
{
    start: 'started',
    stop: 'stopped',
    detach: 'detached',
    restart: 'restart',
    recreate: 'recreate'
}
COMPLETION_DESCRIPTIONS =
{
    start: '%s has been started',
    stop: '%s has been stopped, VM(s) still running',
    detach: '%s has been detached, VM(s) powered off',
    restart: '%s has been restarted',
    recreate: '%s has been recreated'
}

Instance Method Summary collapse

Constructor Details

#initialize(command, vm_state) ⇒ JobState

Returns a new instance of JobState.



27
28
29
30
# File 'lib/cli/job_state.rb', line 27

def initialize(command, vm_state)
  @command = command
  @vm_state = vm_state
end

Instance Method Details

#change(state, job, index) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/cli/job_state.rb', line 32

def change(state, job, index)
  job_desc = job_description(job, index)
  op_desc = OPERATION_DESCRIPTIONS.fetch(state) % job_desc
  new_state = NEW_STATES.fetch(state)
  completion_desc = COMPLETION_DESCRIPTIONS.fetch(state) % job_desc.make_green

  status, task_id = perform_vm_state_change(job, index, new_state, op_desc)

  [status, task_id, completion_desc]
end