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 delete 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 started',
    stop: '%s stopped, VM(s) still running',
    detach: '%s detached, VM(s) deleted',
    restart: '%s restarted',
    recreate: '%s recreated'
}

Instance Method Summary collapse

Constructor Details

#initialize(command, manifest, options) ⇒ JobState

Returns a new instance of JobState.



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

def initialize(command, manifest, options)
  @command = command
  @manifest = manifest
  @options = options
end

Instance Method Details

#change(state, job, index_or_id, force) ⇒ Object



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

def change(state, job, index_or_id, force)
  job, index_or_id = job.split('/') if index_or_id.nil?
  description = job_description(job, index_or_id)
  op_desc = OPERATION_DESCRIPTIONS.fetch(state) % description
  new_state = NEW_STATES.fetch(state)
  completion_desc = COMPLETION_DESCRIPTIONS.fetch(state) % description.make_green
  status, task_id = change_job_state(new_state, job, index_or_id, op_desc, force)

  [status, task_id, completion_desc]
end