Class: Bosh::Cli::Command::CloudCheck

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

Constant Summary

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

#perform(deployment_name = nil) ⇒ Object


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cli/commands/cloudcheck.rb', line 14

def perform(deployment_name = nil)
  auth_required
  no_track_unsupported
  @auto_mode = options[:auto]
  @report_mode = options[:report]

  deployment_name ||= prepare_deployment_manifest(show_state: true).name

  if non_interactive? && !(@report_mode || @auto_mode)
    err ("Cloudcheck cannot be run in non-interactive mode\n" +
         "Please use '--auto' flag if you want automated resolutions " +
         "or '--report' if you just want a report of the errors")
  end

  if @auto_mode && @report_mode
    err("Can't use --auto and --report mode together")
  end


  say("Performing cloud check...")

  status, task_id = director.perform_cloud_scan(deployment_name)

  if status != :done
    task_report(status, task_id)
    exit(1)
  end

  nl
  say("Scan is complete, checking if any problems found...")
  @problems = director.list_problems(deployment_name)

  verify_problems
  nl
  say("Found #{pluralize(@problems.size, "problem")}".make_yellow)
  nl

  @resolutions = {}

  @problems.each_with_index do |problem, index|
    description = problem["description"].to_s.chomp(".") + "."
    say("Problem #{index+1} of #{@problems.size}: #{description}".make_yellow)
    next if @report_mode
    if @auto_mode
      @resolutions[problem["id"]] = {
        "name" => nil,
        "plan" => "apply default resolution"
      }
    else
      @resolutions[problem["id"]] = get_resolution(problem)
    end
    nl
  end

  if @report_mode
    exit(@problems.empty? ? 0 : 1)
  end

  confirm_resolutions unless @auto_mode
  say("Applying resolutions...")

  action_map = @resolutions.inject({}) do |hash, (id, resolution)|
    hash[id] = resolution["name"]
    hash
  end

  status, task_id = director.apply_resolutions(deployment_name, action_map)

  if status != :done
    task_report(status, task_id)
    exit(1)
  end

  say("Cloudcheck is finished".make_green)
end