Class: Morpheus::Cli::Deployments
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#deployment_list_key, #deployment_object_key, #deployment_version_list_key, #deployment_version_object_key, #deployments_interface, #find_deployment_by_id, #find_deployment_by_name, #find_deployment_by_name_or_id, #find_deployment_type_by_name, #find_deployment_version_by_id, #find_deployment_version_by_name, #find_deployment_version_by_name_or_id, included
Methods included from CliCommand
#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_name, #default_refresh_interval, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Constructor Details
Returns a new instance of Deployments.
11
12
13
|
# File 'lib/morpheus/cli/deployments.rb', line 11
def initialize()
end
|
Instance Method Details
#_get(id, params, options) ⇒ Object
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
|
# File 'lib/morpheus/cli/deployments.rb', line 97
def _get(id, params, options)
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.get(id, params)
print_dry_run @deployments_interface.dry.list_versions(id, {})
return
end
json_response = @deployments_interface.get(id, params)
deployment_versions = @deployments_interface.list_versions(id)['versions']
deployment = json_response['deployment']
render_response(json_response, options, 'deployment') do
print_h1 "Deployment Details", [], options
print cyan
print_description_list(deployment_column_definitions, deployment)
print_h2 "Versions", options
if deployment_versions.empty?
print cyan,"No versions found.",reset,"\n"
else
print as_pretty_table(deployment_versions, deployment_version_column_definitions.upcase_keys!, options)
({'size' => deployment_versions.size(), 'total' => deployment['versionCount']}, {:label => "version", :n_label => "versions"})
end
print reset,"\n"
end
return 0, nil
end
|
#add(args) ⇒ Object
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
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/morpheus/cli/deployments.rb', line 168
def add(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name] [options]")
build_option_type_options(opts, options, add_deployment_option_types)
build_option_type_options(opts, options, add_deployment_advanced_option_types)
build_standard_add_options(opts, options)
opts. = "Create a new deployment.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:0, max:1)
options[:options]['name'] = args[0] if args[0]
connect(options)
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'deployment' => parse_passed_options(options)})
else
payload.deep_merge!({'deployment' => parse_passed_options(options)})
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_deployment_option_types, options[:options], @api_client, options[:params])
params.deep_merge!(v_prompt)
advanced_config = Morpheus::Cli::OptionTypes.no_prompt(add_deployment_advanced_option_types, options[:options], @api_client, options[:params])
advanced_config.deep_compact!
params.deep_merge!(advanced_config)
payload['deployment'].deep_merge!(params)
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.create(payload)
return 0, nil
end
json_response = @deployments_interface.create(payload)
deployment = json_response['deployment']
render_response(json_response, options, 'deployment') do
print_green_success "Added deployment #{deployment['name']}"
return _get(deployment["id"], {}, options)
end
return 0, nil
end
|
#add_version(args) ⇒ Object
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
# File 'lib/morpheus/cli/deployments.rb', line 369
def add_version(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [version] [options]")
build_option_type_options(opts, options, add_deployment_version_option_types)
build_option_type_options(opts, options, add_deployment_version_advanced_option_types)
build_standard_add_options(opts, options)
opts. = "Create a new deployment version.\n[deployment] is required. This is the name or id of a deployment.\n[version] is required. This is the deployment version identifier\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:0, max:2)
connect(options)
deployment = nil
if args[0]
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
else
deployment_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'deploymentId', 'fieldLabel' => 'Deployment', 'type' => 'select', 'required' => true, 'description' => 'Deployment to add version to', 'optionSource' => lambda { |api_client, api_params|
@deployments_interface.list(max:10000)['deployments'].collect {|it|
{'name' => it['name'], 'value' => it['id']}
}
}}], options[:options])['deploymentId']
deployment = {'id' => deployment_id.to_i}
end
options[:options]['userVersion'] = args[1] if args[1]
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'version' => parse_passed_options(options)})
else
payload.deep_merge!({'version' => parse_passed_options(options)})
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_deployment_version_option_types, options[:options], @api_client, options[:params])
params.deep_merge!(v_prompt)
advanced_config = Morpheus::Cli::OptionTypes.no_prompt(add_deployment_version_advanced_option_types, options[:options], @api_client, options[:params])
advanced_config.deep_compact!
params.deep_merge!(advanced_config)
payload['version'].deep_merge!(params)
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.create_version(deployment['id'], payload)
return 0, nil
end
json_response = @deployments_interface.create_version(deployment['id'], payload)
deployment_version = json_response['version']
render_response(json_response, options, 'version') do
print_green_success "Added deployment version #{deployment_version['userVersion']}"
return get_version([deployment["id"], deployment_version['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
end
end
|
#connect(opts) ⇒ Object
15
16
17
18
|
# File 'lib/morpheus/cli/deployments.rb', line 15
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@deployments_interface = @api_client.deployments
end
|
#get(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/deployments.rb', line 64
def get(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment]")
build_standard_get_options(opts, options)
opts. = "Get details about a specific deployment.\n[deployment] is required. This is the name or id of a deployment.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1)
connect(options)
id_list = parse_id_list(args)
id_list = id_list.collect do |id|
if id.to_s =~ /\A\d{1,}\Z/
id
else
deployment = find_deployment_by_name(id)
if deployment
deployment['id']
else
raise_command_error "deployment not found for name '#{id}'"
end
end
end
return run_command_for_each_arg(id_list) do |arg|
_get(arg, params, options)
end
end
|
#get_version(args) ⇒ Object
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
# File 'lib/morpheus/cli/deployments.rb', line 290
def get_version(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [version] [options]")
build_option_type_options(opts, options, add_deployment_version_option_types)
build_option_type_options(opts, options, add_deployment_version_advanced_option_types)
build_standard_add_options(opts, options)
opts. = "Create a new deployment version.\n[deployment] is required. This is the name or id of a deployment.\n[version] is required. This is the deployment version identifier\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:2)
connect(options)
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
id = args[1]
if id.to_s =~ /\A\d{1,}\Z/
id = id.to_i
else
deployment_version = find_deployment_version_by_name(deployment['id'], id)
if deployment_version
id = deployment_version['id']
else
return 1, "deployment version not found for name '#{id}'"
end
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.get_version(deployment['id'], id, params)
return
end
json_response = @deployments_interface.get_version(deployment['id'], id, params)
deployment_version = json_response['version']
render_response(json_response, options, 'version') do
print_h1 "Deployment Version Details", [], options
print cyan
columns = {
"ID" => 'id',
"Deployment" => lambda {|it| deployment['name'] },
"Version" => 'userVersion',
"Deploy Type" => lambda {|it| it['deployType'] },
"URL" => lambda {|it|
if it['deployType'] == 'fetch'
"#{it['fetchUrl']}"
elsif it['deployType'] == 'git'
"#{it['gitUrl']}"
end
},
"Ref" => lambda {|it|
if it['deployType'] == 'git'
"#{it['gitRef']}"
end
},
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
}
if deployment_version['deployType'] == 'git'
columns['Git URL'] = columns['URL']
elsif deployment_version['deployType'] == 'fetch'
columns['Fetch URL'] = columns['URL']
columns.delete('Ref')
else
columns.delete('URL')
columns.delete('Ref')
end
print_description_list(columns, deployment_version)
print reset,"\n"
end
return 0, nil
end
|
#handle(args) ⇒ Object
20
21
22
|
# File 'lib/morpheus/cli/deployments.rb', line 20
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/deployments.rb', line 24
def list(args)
options = {}
params = {}
ref_ids = []
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[search]")
build_standard_list_options(opts, options)
opts. = "List deployments."
end
optparse.parse!(args)
connect(options)
if args.count > 0
options[:phrase] = args.join(" ")
end
params.merge!(parse_list_options(options))
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.list(params)
return
end
json_response = @deployments_interface.list(params)
deployments = json_response['deployments']
render_response(json_response, options, 'deployments') do
print_h1 "Morpheus Deployments", parse_list_subtitles(options), options
if deployments.empty?
print cyan,"No deployments found.",reset,"\n"
else
print as_pretty_table(deployments, deployment_column_definitions.upcase_keys!, options)
(json_response)
end
print reset,"\n"
end
if deployments.empty?
return 1, "no deployments found"
else
return 0, nil
end
end
|
#list_versions(args) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
|
# File 'lib/morpheus/cli/deployments.rb', line 123
def list_versions(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [search]")
build_standard_list_options(opts, options)
opts. = "List versions of a specific deployment.\n[deployment] is required. This is the name or id of a deployment.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1,max:2)
deployment_name = args[0]
if args.count > 1
options[:phrase] = args[1]
end
connect(options)
params.merge!(parse_list_options(options))
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.list(params)
return
end
deployment = find_deployment_by_name_or_id(deployment_name)
exit 1 if deployment.nil?
json_response = @deployments_interface.list_versions(deployment['id'], params)
deployment_versions = json_response['versions']
render_response(json_response, options, 'versions') do
print_h1 "Deployment Versions", ["#{deployment['name']}"] + parse_list_subtitles(options), options
if deployment_versions.empty?
print cyan,"No versions found.",reset,"\n"
else
print as_pretty_table(deployment_versions, deployment_version_column_definitions.upcase_keys!, options)
(json_response)
end
print reset,"\n"
end
if deployment_versions.empty?
return 1, "no versions found"
else
return 0, nil
end
end
|
#remove(args) ⇒ Object
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/morpheus/cli/deployments.rb', line 262
def remove(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [options]")
build_standard_remove_options(opts, options)
opts. = "Delete a deployment.\n[deployment] is required. This is the name or id of a deployment.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.destroy(deployment['id'], params)
return
end
json_response = @deployments_interface.destroy(deployment['id'], params)
render_response(json_response, options) do
print_green_success "Removed deployment #{deployment['name']}"
end
return 0, nil
end
|
#remove_version(args) ⇒ Object
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
# File 'lib/morpheus/cli/deployments.rb', line 472
def remove_version(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [version] [options]")
build_standard_remove_options(opts, options)
opts. = "Delete a deployment version.\n[deployment] is required. This is the name or id of a deployment.\n[version] is required. This is the version identifier of a deployment version.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:2)
connect(options)
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
id = args[1]
if id.to_s =~ /\A\d{1,}\Z/
id = id.to_i
else
deployment_version = find_deployment_version_by_name(deployment['id'], id)
if deployment_version
id = deployment_version['id']
else
return 1, "deployment version not found for '#{id}'"
end
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.destroy(deployment['id'], params)
return
end
json_response = @deployments_interface.destroy(deployment['id'], params)
render_response(json_response, options) do
print_green_success "Removed deployment version #{deployment_version['userVersion']}"
end
return 0, nil
end
|
#update(args) ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/morpheus/cli/deployments.rb', line 211
def update(args)
options = {}
params = {}
payload = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [options]")
build_option_type_options(opts, options, update_deployment_option_types)
build_option_type_options(opts, options, update_deployment_advanced_option_types)
build_standard_update_options(opts, options)
opts. = "Update a deployment.\n[deployment] is required. This is the name or id of a deployment.\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'deployment' => parse_passed_options(options)})
else
payload.deep_merge!({'deployment' => parse_passed_options(options)})
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_deployment_option_types, options[:options], @api_client, options[:params])
v_prompt.deep_compact!
params.deep_merge!(v_prompt)
advanced_config = Morpheus::Cli::OptionTypes.no_prompt(update_deployment_advanced_option_types, options[:options], @api_client, options[:params])
advanced_config.deep_compact!
params.deep_merge!(advanced_config)
payload.deep_merge!({'deployment' => params})
if payload['deployment'].empty?
raise_command_error "Specify at least one option to update.\n#{optparse}"
end
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.update(deployment['id'], payload)
return
end
json_response = @deployments_interface.update(deployment['id'], payload)
deployment = json_response['deployment']
render_response(json_response, options, 'deployment') do
print_green_success "Updated deployment #{deployment['name']}"
return _get(deployment["id"], {}, options)
end
return 0, nil
end
|
#update_version(args) ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
# File 'lib/morpheus/cli/deployments.rb', line 425
def update_version(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[deployment] [version] [options]")
build_option_type_options(opts, options, update_deployment_version_option_types)
build_option_type_options(opts, options, update_deployment_version_advanced_option_types)
build_standard_update_options(opts, options)
opts. = "Update a deployment version.\n[deployment] is required. This is the name or id of a deployment.\n[version] is required. This is the deployment version identifier\n"
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:0, max:2)
connect(options)
deployment = find_deployment_by_name_or_id(args[0])
return 1 if deployment.nil?
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], args[1])
return 1 if deployment_version.nil?
payload = {}
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'version' => parse_passed_options(options)})
else
payload.deep_merge!({'version' => parse_passed_options(options)})
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_deployment_version_option_types, options[:options], @api_client, options[:params])
params.deep_merge!(v_prompt)
advanced_config = Morpheus::Cli::OptionTypes.no_prompt(update_deployment_version_advanced_option_types, options[:options], @api_client, options[:params])
advanced_config.deep_compact!
params.deep_merge!(advanced_config)
payload['version'].deep_merge!(params)
end
@deployments_interface.setopts(options)
if options[:dry_run]
print_dry_run @deployments_interface.dry.update_version(deployment['id'], deployment_version['id'], payload)
return 0, nil
end
json_response = @deployments_interface.update_version(deployment['id'], deployment_version['id'], payload)
deployment_version = json_response['version']
render_response(json_response, options, 'version') do
print_green_success "Updated deployment version #{deployment_version['userVersion']}"
return get_version([deployment["id"], deployment_version['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
end
end
|