Class: Bosh::Cli::Command::Errand

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

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #config, #confirmed?, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #username, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

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

Methods included from DeploymentHelper

#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes

Constructor Details

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

Instance Method Details

#run_errand(errand_name) ⇒ Object

Raises:

  • (@download_logs_error)


9
10
11
12
13
14
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
# File 'lib/cli/commands/errand.rb', line 9

def run_errand(errand_name)
  auth_required
  deployment_required

  deployment_name = prepare_deployment_manifest['name']

  errands_client = Bosh::Cli::Client::ErrandsClient.new(director)
  status, task_id, errand_result = errands_client.run_errand(deployment_name, errand_name)

  unless errand_result
    task_report(status, task_id, nil, "Errand `#{errand_name}' did not complete")
    return
  end

  nl

  say('[stdout]')
  say(errand_result.stdout.empty?? 'None' : errand_result.stdout)
  nl

  say('[stderr]')
  say(errand_result.stderr.empty?? 'None' : errand_result.stderr)
  nl

  if options[:download_logs] && errand_result.logs_blobstore_id
    logs_downloader = Bosh::Cli::LogsDownloader.new(director, self)
    logs_path = logs_downloader.build_destination_path(errand_name, 0, options[:logs_dir] || Dir.pwd)

    begin
      logs_downloader.download(errand_result.logs_blobstore_id, logs_path)
    rescue Bosh::Cli::CliError => e
      @download_logs_error = e
    end
  end

  title_prefix = "Errand `#{errand_name}'"
  exit_code_suffix = "(exit code #{errand_result.exit_code})"

  if errand_result.exit_code == 0
    say("#{title_prefix} completed successfully #{exit_code_suffix}".make_green)
  elsif errand_result.exit_code > 128
    err("#{title_prefix} was canceled #{exit_code_suffix}")
  else
    err("#{title_prefix} completed with error #{exit_code_suffix}")
  end

  raise @download_logs_error if @download_logs_error
end