Module: Bosh::Cli::DeploymentHelper
- Included in:
- Command::Base
- Defined in:
- lib/cli/deployment_helper.rb
Instance Method Summary collapse
- #build_manifest ⇒ Object
- #cancel_deployment ⇒ Object
-
#deployment_changed?(current_manifest, manifest, show = true) ⇒ Boolean
Check if the 2 deployments are different.
-
#inspect_deployment_changes(manifest, options = {}) ⇒ Object
Interactive walkthrough of deployment changes, expected to bail out of CLI using ‘cancel_deployment’ if something goes wrong, so it doesn’t need to have a meaningful return value.
- #job_exists_in_deployment?(manifest_hash, job_name) ⇒ Boolean
- #job_unique_in_deployment?(manifest_hash, job_name) ⇒ Boolean
- #jobs_and_indexes ⇒ Object
- #prepare_deployment_manifest(options = {}) ⇒ Object
-
#prompt_for_errand_name ⇒ Object
return a job/errand selected by user by name.
- #prompt_for_job_and_index ⇒ Object
Instance Method Details
#build_manifest ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/cli/deployment_helper.rb', line 3 def build_manifest deployment_required return @manifest if @manifest @manifest = Manifest.new(deployment, director) @manifest.load @manifest end |
#cancel_deployment ⇒ Object
178 179 180 |
# File 'lib/cli/deployment_helper.rb', line 178 def cancel_deployment quit('Deployment canceled'.make_red) end |
#deployment_changed?(current_manifest, manifest, show = true) ⇒ Boolean
Check if the 2 deployments are different. Print out a summary if “show” is true.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cli/deployment_helper.rb', line 24 def deployment_changed?(current_manifest, manifest, show = true) diff = Bosh::Cli::HashChangeset.new diff.add_hash(normalize_deployment_manifest(manifest), :new) diff.add_hash(normalize_deployment_manifest(current_manifest), :old) changed = diff.changed? if changed && show @_diff_key_visited = {} diff.keys.each do |key| unless @_diff_key_visited[key] print_summary(diff, key, false) nl end end end changed end |
#inspect_deployment_changes(manifest, options = {}) ⇒ Object
Interactive walkthrough of deployment changes, expected to bail out of CLI using ‘cancel_deployment’ if something goes wrong, so it doesn’t need to have a meaningful return value.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cli/deployment_helper.rb', line 48 def inspect_deployment_changes(manifest, = {}) manifest.resolve_release_aliases manifest.resolve_stemcell_aliases show_empty_changeset = .fetch(:show_empty_changeset, true) redact_diff = .fetch(:redact_diff, false) manifest_hash = manifest.hash.dup current_deployment = director.get_deployment(manifest_hash['name']) # We cannot retrieve current manifest until there was at least one # successful deployment. There used to be a warning about that # but it turned out to be confusing to many users and thus has # been removed. return if current_deployment['manifest'].nil? current_manifest = Psych.load(current_deployment['manifest']) unless current_manifest.is_a?(Hash) err('Current deployment manifest format is invalid, check if director works properly') end diff = Bosh::Cli::HashChangeset.new diff.add_hash(normalize_deployment_manifest(manifest_hash), :new) diff.add_hash(normalize_deployment_manifest(current_manifest), :old) @_diff_key_visited = { 'name' => 1, 'director_uuid' => 1 } header('Detecting deployment changes') if !diff.changed? && !show_empty_changeset return false end if diff[:release] print_summary(diff, :release, redact_diff) nl end if diff[:releases] print_summary(diff, :releases, redact_diff) nl end print_summary(diff, :compilation, redact_diff) nl print_summary(diff, :update, redact_diff) nl print_summary(diff, :resource_pools, redact_diff) nl print_summary(diff, :disk_pools, redact_diff) nl print_summary(diff, :networks, redact_diff) nl print_summary(diff, :jobs, redact_diff) nl print_summary(diff, :properties, redact_diff) nl diff.keys.each do |key| unless @_diff_key_visited[key] print_summary(diff, key, redact_diff) nl end end diff.changed? rescue Bosh::Cli::ResourceNotFound say('Cannot get current deployment information from director, possibly a new deployment'.make_red) true end |
#job_exists_in_deployment?(manifest_hash, job_name) ⇒ Boolean
129 130 131 |
# File 'lib/cli/deployment_helper.rb', line 129 def job_exists_in_deployment?(manifest_hash, job_name) !!find_job(manifest_hash, job_name) end |
#job_unique_in_deployment?(manifest_hash, job_name) ⇒ Boolean
124 125 126 127 |
# File 'lib/cli/deployment_helper.rb', line 124 def job_unique_in_deployment?(manifest_hash, job_name) job = find_job(manifest_hash, job_name) job ? job.fetch('instances') == 1 : false end |
#jobs_and_indexes ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cli/deployment_helper.rb', line 166 def jobs_and_indexes jobs = prepare_deployment_manifest.hash.fetch('jobs') jobs.inject([]) do |jobs_and_indexes, job| job_name = job.fetch('name') 0.upto(job.fetch('instances').to_i - 1) do |index| jobs_and_indexes << [job_name, index] end jobs_and_indexes end end |
#prepare_deployment_manifest(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cli/deployment_helper.rb', line 11 def prepare_deployment_manifest( = {}) manifest = build_manifest if .fetch(:show_state, false) show_current_state(manifest.name) end manifest.validate() manifest end |
#prompt_for_errand_name ⇒ Object
return a job/errand selected by user by name
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cli/deployment_helper.rb', line 153 def prompt_for_errand_name errands = list_errands err('Deployment has no available errands') if errands.size == 0 choose do || .prompt = 'Choose an errand: ' errands.each do |errand, index| .choice("#{errand['name']}") { errand } end end end |
#prompt_for_job_and_index ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cli/deployment_helper.rb', line 133 def prompt_for_job_and_index manifest = prepare_deployment_manifest deployment_name = manifest.name instances = director.fetch_vm_state(deployment_name, {}, false) return [instances.first['job'], instances.first['index'] ] if instances.size == 1 choose do || .prompt = 'Choose an instance: ' instances.each do |instance| job_name = instance['job'] index = instance['index'] id = instance['id'] name = "#{job_name}/#{index}" name = "#{name} (#{id})" if id .choice(name) { [job_name, index] } end end end |