Class: Bosh::Cli::Command::Task

Inherits:
Base show all
Defined in:
lib/cli/commands/task.rb

Constant Summary collapse

INCLUDE_ALL =
"Include all task types (ssh, logs, vms, etc)"

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #exit_code, #info, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #run_nested_command, #show_current_state, #target, #target_name, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

#desc, #method_added, #option, #register_command, #usage

Methods included from DeploymentHelper

#build_manifest, #cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_unique_in_deployment?, #jobs_and_indexes, #prepare_deployment_manifest, #prompt_for_errand_name, #prompt_for_job_and_index

Constructor Details

This class inherits a constructor from Bosh::Cli::Command::Base

Instance Method Details

#cancel(task_id) ⇒ Object


98
99
100
101
102
103
104
# File 'lib/cli/commands/task.rb', line 98

def cancel(task_id)
  auth_required
  show_current_state
  task = Bosh::Cli::DirectorTask.new(director, task_id)
  task.cancel
  say("Task #{task_id} is getting canceled")
end

#list_recent(count = 30) ⇒ Object


85
86
87
88
89
90
91
92
93
# File 'lib/cli/commands/task.rb', line 85

def list_recent(count = 30)
  auth_required
  show_current_state
  use_filter = !options.key?(:no_filter)
  tasks = director.list_recent_tasks(count, get_verbose_level(use_filter), options[:deployment])
  err("No recent tasks") if tasks.empty?
  show_tasks_table(tasks)
  say("Showing #{tasks.size} recent #{tasks.size == 1 ? "task" : "tasks"}")
end

#list_runningObject


70
71
72
73
74
75
76
77
78
# File 'lib/cli/commands/task.rb', line 70

def list_running
  auth_required
  show_current_state
  use_filter = !options.key?(:no_filter)
  tasks = director.list_running_tasks(get_verbose_level(use_filter), options[:deployment])
  err("No running tasks") if tasks.empty?
  show_tasks_table(tasks.sort_by { |t| t["id"].to_i * -1 })
  say("Total tasks running now: %d" % [tasks.size])
end

#track(task_id = nil) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cli/commands/task.rb', line 15

def track(task_id = nil)
  auth_required
  show_current_state
  use_filter = !options.key?(:no_filter)
  raw_output = options[:raw]

  log_type = "event"
  n_types = 0
  if options[:cpi]
    log_type = "cpi"
    n_types += 1
  end

  if options[:debug]
    log_type = "debug"
    n_types += 1
  end

  if options[:event]
    log_type = "event"
    n_types += 1
  end

  if options[:result]
    log_type = "result"
    raw_output = true
    n_types += 1
  end

  if n_types > 1
    err("Cannot track more than one log type")
  end

  track_options = {
    :log_type => log_type,
    :raw_output => raw_output
  }

  if task_id.nil? || %w(last latest).include?(task_id)
    task_id = get_last_task_id(get_verbose_level(use_filter))
  end

  if task_id.to_i <= 0
    err("Task id must be a positive integer")
  end

  tracker = Bosh::Cli::TaskTracking::TaskTracker.new(director, task_id, track_options)
  tracker.track
end