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

Methods included from VersionCalc

#major_version, #minor_version, #version_cmp, #version_greater, #version_less, #version_same

Constructor Details

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

Instance Method Details

#run_errand(errand_name) ⇒ Object



7
8
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
# File 'lib/cli/commands/errand.rb', line 7

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

  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
end