Class: Bosh::Cli::Command::CloudCheck
- Includes:
- DeploymentHelper
- Defined in:
- lib/cli/commands/cloudcheck.rb
Constant Summary
Constants inherited from Base
Base::BLOBS_DIR, Base::BLOBS_INDEX_FILE
Instance Attribute Summary
Attributes inherited from Base
#cache, #config, #options, #out, #usage, #work_dir
Instance Method Summary collapse
Methods included from DeploymentHelper
#deployment_changed?, #inspect_deployment_changes, #prepare_deployment_manifest
Methods inherited from Base
#blob_manager, #blobstore, command, #confirmed?, #director, #dry_run?, #exit_code, #full_target_name, #initialize, #interactive?, #logged_in?, #non_interactive?, #redirect, #release, #run, #show_usage, #target_name, #target_version, #task_report, #verbose?
Constructor Details
This class inherits a constructor from Bosh::Cli::Command::Base
Instance Method Details
#perform(*options) ⇒ 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 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 |
# File 'lib/cli/commands/cloudcheck.rb', line 7 def perform(*) auth_required @auto_mode = .delete("--auto") @report_mode = .delete("--report") if non_interactive? && !@report_mode err ("Cloudcheck cannot be run in non-interactive mode\n" + "Please use `--auto' flag if you want automated resolutions") end if .size > 0 err("Unknown options: #{.join(", ")}") end if @auto_mode && @report_mode err("Can't use --auto and --report mode together") end say("Performing cloud check...") manifest = prepare_deployment_manifest deployment_name = manifest["name"] status, _ = director.perform_cloud_scan(deployment_name) if status != :done task_report(status) 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")}".yellow) nl @resolutions = {} @problems.each_with_index do |problem, index| description = problem["description"].to_s.chomp(".") + "." say("Problem #{index+1} of #{@problems.size}: #{description}".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, _ = director.apply_resolutions(deployment_name, action_map) if status != :done task_report(status) exit(1) end say("Cloudcheck is finished".green) end |