Class: Bosh::Cli::Command::Deployment
- Inherits:
-
Base
show all
- Defined in:
- lib/cli/commands/deployment.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, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #target, #target_name, #verbose?
#desc, #method_added, #option, #register_command, #usage
#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_errand_name, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes
Instance Method Details
#delete(name) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/cli/commands/deployment.rb', line 115
def delete(name)
auth_required
force = !!options[:force]
say("\nYou are going to delete deployment `#{name}'.".make_red)
nl
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
unless confirmed?
say("Canceled deleting deployment".make_green)
return
end
begin
status, result = director.delete_deployment(name, :force => force)
task_report(status, result, "Deleted deployment `#{name}'")
rescue Bosh::Cli::ResourceNotFound
task_report(:done, nil, "Skipped delete of missing deployment `#{name}'")
end
end
|
#download_manifest(deployment_name, save_as = nil) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/cli/commands/deployment.rb', line 225
def download_manifest(deployment_name, save_as = nil)
auth_required
if save_as && File.exists?(save_as) &&
!confirmed?("Overwrite `#{save_as}'?")
err("Please choose another file to save the manifest to")
end
deployment = director.get_deployment(deployment_name)
if save_as
File.open(save_as, "w") do |f|
f.write(deployment["manifest"])
end
say("Deployment manifest saved to `#{save_as}'".make_green)
else
say(deployment["manifest"])
end
end
|
73
74
75
76
77
|
# File 'lib/cli/commands/deployment.rb', line 73
def edit
deployment_required
editor = ENV['EDITOR'] || "vi"
system("#{editor} #{deployment}")
end
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/cli/commands/deployment.rb', line 202
def list
auth_required
deployments = director.list_deployments
err("No deployments") if deployments.empty?
deployments_table = table do |t|
t.headings = ['Name', 'Release(s)', 'Stemcell(s)', 'Cloud Config']
deployments.each do |d|
t.add_row(row_for_deployments_table(d))
t.add_separator unless d == deployments.last
end
end
nl
say(deployments_table)
nl
say("Deployments total: %d" % deployments.size)
end
|
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
|
# File 'lib/cli/commands/deployment.rb', line 84
def perform
auth_required
recreate = !!options[:recreate]
redact_diff = !!options[:redact_diff]
manifest_yaml = prepare_deployment_manifest(
:yaml => true, :resolve_properties => true)
inspect_deployment_changes(Psych.load(manifest_yaml),
interactive: interactive?, redact_diff: redact_diff)
say('Please review all changes carefully'.make_yellow) if interactive?
deployment_name = File.basename(deployment)
('Deploying')
say("Deployment name: `#{deployment_name.make_green}'")
say("Director name: `#{target_name.make_green}'")
unless confirmed?('Are you sure you want to deploy?')
cancel_deployment
end
status, task_id = director.deploy(manifest_yaml, :recreate => recreate)
task_report(status, task_id, "Deployed `#{deployment_name.make_green}' to `#{target_name.make_green}'")
end
|
#set_current(filename = nil) ⇒ 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
|
# File 'lib/cli/commands/deployment.rb', line 7
def set_current(filename = nil)
if filename.nil?
show_current
return
end
manifest_filename = find_deployment(filename)
unless File.exists?(manifest_filename)
err("Missing manifest for `#{filename}'")
end
manifest = load_yaml_file(manifest_filename)
unless manifest.is_a?(Hash)
err("Invalid manifest format")
end
unless manifest["target"].blank?
err(manifest_target_upgrade_notice)
end
if manifest["director_uuid"].blank?
err("Director UUID is not defined in deployment manifest")
end
if target
old_director = Bosh::Cli::Client::Director.new(target, credentials)
old_director_uuid = old_director.get_status["uuid"] rescue nil
else
old_director_uuid = nil
end
new_director_uuid = manifest["director_uuid"]
if old_director_uuid != new_director_uuid
new_target_url = config.resolve_alias(:target, new_director_uuid)
if new_target_url.blank?
err("This manifest references director with UUID " +
"#{new_director_uuid}.\n" +
"You've never targeted it before.\n" +
"Please find your director IP or hostname and target it first.")
end
new_director = Bosh::Cli::Client::Director.new(
new_target_url, credentials)
status = new_director.get_status
config.target = new_target_url
config.target_name = status["name"]
config.target_version = status["version"]
config.target_uuid = status["uuid"]
say("#{"WARNING!".make_red} Your target has been " +
"changed to `#{target.make_red}'!")
end
say("Deployment set to `#{manifest_filename.make_green}'")
config.set_deployment(manifest_filename)
config.save
end
|
#validate_jobs ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/cli/commands/deployment.rb', line 140
def validate_jobs
check_if_release_dir
manifest = prepare_deployment_manifest(:resolve_properties => true)
if manifest["release"]
release_name = manifest["release"]["name"]
elsif manifest["releases"].count > 1
err("Cannot validate a deployment manifest with more than 1 release")
else
release_name = manifest["releases"].first["name"]
end
if release_name == release.dev_name || release_name == release.final_name
nl
say("Analyzing release directory...".make_yellow)
else
err("This release was not found in deployment manifest")
end
say(" - discovering packages")
packages = Bosh::Cli::Resources::Package.discover(work_dir)
say(" - discovering jobs")
jobs = Bosh::Cli::Resources::Job.discover(
work_dir,
packages.map {|package| package['name']}
)
say(" - validating properties")
validator = Bosh::Cli::JobPropertyValidator.new(jobs, manifest)
validator.validate
unless validator.jobs_without_properties.empty?
nl
say("Legacy jobs (no properties defined): ".make_yellow)
validator.jobs_without_properties.sort { |a, b|
a.name <=> b.name
}.each do |job|
say(" - #{job.name}")
end
end
if validator.template_errors.empty?
nl
say("No template errors found".make_green)
else
nl
say("Template errors: ".make_yellow)
validator.template_errors.each do |error|
nl
path = Pathname.new(error.template_path)
rel_path = path.relative_path_from(Pathname.new(release.dir))
say(" - #{rel_path}:")
say(" line #{error.line}:".make_yellow + " #{error.exception.to_s}")
end
end
end
|