morpheus-cli 4.2.22 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +30 -0
- data/lib/morpheus/api/billing_interface.rb +34 -0
- data/lib/morpheus/api/catalog_item_types_interface.rb +9 -0
- data/lib/morpheus/api/deploy_interface.rb +1 -1
- data/lib/morpheus/api/deployments_interface.rb +20 -1
- data/lib/morpheus/api/forgot_password_interface.rb +17 -0
- data/lib/morpheus/api/instances_interface.rb +16 -2
- data/lib/morpheus/api/rest_interface.rb +0 -6
- data/lib/morpheus/api/roles_interface.rb +14 -0
- data/lib/morpheus/api/search_interface.rb +13 -0
- data/lib/morpheus/api/servers_interface.rb +14 -0
- data/lib/morpheus/api/service_catalog_interface.rb +89 -0
- data/lib/morpheus/api/usage_interface.rb +18 -0
- data/lib/morpheus/cli.rb +7 -3
- data/lib/morpheus/cli/apps.rb +6 -27
- data/lib/morpheus/cli/backup_jobs_command.rb +3 -0
- data/lib/morpheus/cli/backups_command.rb +3 -0
- data/lib/morpheus/cli/catalog_item_types_command.rb +622 -0
- data/lib/morpheus/cli/cli_command.rb +70 -21
- data/lib/morpheus/cli/commands/standard/curl_command.rb +3 -5
- data/lib/morpheus/cli/commands/standard/history_command.rb +3 -1
- data/lib/morpheus/cli/commands/standard/man_command.rb +74 -40
- data/lib/morpheus/cli/commands/standard/source_command.rb +1 -1
- data/lib/morpheus/cli/commands/standard/update_command.rb +76 -0
- data/lib/morpheus/cli/containers_command.rb +14 -24
- data/lib/morpheus/cli/cypher_command.rb +6 -2
- data/lib/morpheus/cli/deploy.rb +199 -90
- data/lib/morpheus/cli/deployments.rb +341 -28
- data/lib/morpheus/cli/deploys.rb +206 -41
- data/lib/morpheus/cli/error_handler.rb +7 -0
- data/lib/morpheus/cli/forgot_password.rb +133 -0
- data/lib/morpheus/cli/groups.rb +1 -1
- data/lib/morpheus/cli/health_command.rb +59 -2
- data/lib/morpheus/cli/hosts.rb +295 -35
- data/lib/morpheus/cli/instances.rb +247 -130
- data/lib/morpheus/cli/invoices_command.rb +37 -19
- data/lib/morpheus/cli/library_option_lists_command.rb +15 -7
- data/lib/morpheus/cli/library_option_types_command.rb +5 -2
- data/lib/morpheus/cli/logs_command.rb +9 -6
- data/lib/morpheus/cli/mixins/accounts_helper.rb +12 -7
- data/lib/morpheus/cli/mixins/backups_helper.rb +2 -4
- data/lib/morpheus/cli/mixins/deployments_helper.rb +31 -3
- data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +46 -21
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +108 -5
- data/lib/morpheus/cli/option_types.rb +271 -22
- data/lib/morpheus/cli/ping.rb +0 -1
- data/lib/morpheus/cli/remote.rb +35 -12
- data/lib/morpheus/cli/reports_command.rb +99 -30
- data/lib/morpheus/cli/roles.rb +453 -113
- data/lib/morpheus/cli/search_command.rb +182 -0
- data/lib/morpheus/cli/service_catalog_command.rb +1474 -0
- data/lib/morpheus/cli/setup.rb +1 -1
- data/lib/morpheus/cli/shell.rb +33 -11
- data/lib/morpheus/cli/storage_providers_command.rb +40 -56
- data/lib/morpheus/cli/tasks.rb +29 -32
- data/lib/morpheus/cli/usage_command.rb +203 -0
- data/lib/morpheus/cli/user_settings_command.rb +1 -0
- data/lib/morpheus/cli/users.rb +12 -1
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +429 -254
- data/lib/morpheus/cli/whoami.rb +6 -6
- data/lib/morpheus/cli/workflows.rb +33 -40
- data/lib/morpheus/formatters.rb +75 -7
- data/lib/morpheus/terminal.rb +6 -2
- metadata +14 -2
@@ -4,8 +4,11 @@ class Morpheus::Cli::Deployments
|
|
4
4
|
include Morpheus::Cli::CliCommand
|
5
5
|
include Morpheus::Cli::DeploymentsHelper
|
6
6
|
|
7
|
+
set_command_description "View and manage deployments, including versions and files."
|
8
|
+
|
7
9
|
register_subcommands :list, :get, :add, :update, :remove
|
8
10
|
register_subcommands :list_versions, :get_version, :add_version, :update_version, :remove_version
|
11
|
+
register_subcommands :list_files, :upload, :remove_file
|
9
12
|
alias_subcommand :versions, :'list-versions'
|
10
13
|
|
11
14
|
def initialize()
|
@@ -81,7 +84,7 @@ EOT
|
|
81
84
|
if id.to_s =~ /\A\d{1,}\Z/
|
82
85
|
id
|
83
86
|
else
|
84
|
-
deployment =
|
87
|
+
deployment = find_deployment_by_name_or_id(id)
|
85
88
|
if deployment
|
86
89
|
deployment['id']
|
87
90
|
else
|
@@ -275,6 +278,9 @@ EOT
|
|
275
278
|
connect(options)
|
276
279
|
deployment = find_deployment_by_name_or_id(args[0])
|
277
280
|
return 1 if deployment.nil?
|
281
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the deployment #{deployment['name']}?")
|
282
|
+
return 9, "aborted command"
|
283
|
+
end
|
278
284
|
@deployments_interface.setopts(options)
|
279
285
|
if options[:dry_run]
|
280
286
|
print_dry_run @deployments_interface.dry.destroy(deployment['id'], params)
|
@@ -292,6 +298,9 @@ EOT
|
|
292
298
|
params = {}
|
293
299
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
294
300
|
opts.banner = subcommand_usage("[deployment] [version] [options]")
|
301
|
+
opts.on(nil, '--no-files', "Do not show files") do
|
302
|
+
options[:no_files] = true
|
303
|
+
end
|
295
304
|
build_option_type_options(opts, options, add_deployment_version_option_types)
|
296
305
|
build_option_type_options(opts, options, add_deployment_version_advanced_option_types)
|
297
306
|
build_standard_add_options(opts, options)
|
@@ -311,7 +320,7 @@ EOT
|
|
311
320
|
if id.to_s =~ /\A\d{1,}\Z/
|
312
321
|
id = id.to_i
|
313
322
|
else
|
314
|
-
deployment_version =
|
323
|
+
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], id)
|
315
324
|
if deployment_version
|
316
325
|
id = deployment_version['id']
|
317
326
|
else
|
@@ -326,6 +335,13 @@ EOT
|
|
326
335
|
end
|
327
336
|
json_response = @deployments_interface.get_version(deployment['id'], id, params)
|
328
337
|
deployment_version = json_response['version']
|
338
|
+
deploy_type = deployment_version['deployType'] || deployment_version['type']
|
339
|
+
deployment_files_response = nil
|
340
|
+
deployment_files = nil
|
341
|
+
if options[:no_files] != true
|
342
|
+
deployment_files_response = @deployments_interface.list_files(deployment['id'], deployment_version['id'], params)
|
343
|
+
deployment_files = deployment_files_response.is_a?(Array) ? deployment_files_response : deployment_files_response['files']
|
344
|
+
end
|
329
345
|
render_response(json_response, options, 'version') do
|
330
346
|
# print_h1 "Deployment Version Details", [deployment['name']], options
|
331
347
|
print_h1 "Deployment Version Details", [], options
|
@@ -334,26 +350,17 @@ EOT
|
|
334
350
|
columns = {
|
335
351
|
"ID" => 'id',
|
336
352
|
"Deployment" => lambda {|it| deployment['name'] },
|
337
|
-
"Version" =>
|
353
|
+
"Version" => lambda {|it| format_deployment_version_number(it) },
|
338
354
|
"Deploy Type" => lambda {|it| it['deployType'] },
|
339
|
-
"URL" => lambda {|it|
|
340
|
-
|
341
|
-
"#{it['fetchUrl']}"
|
342
|
-
elsif it['deployType'] == 'git'
|
343
|
-
"#{it['gitUrl']}"
|
344
|
-
end
|
345
|
-
},
|
346
|
-
"Ref" => lambda {|it|
|
347
|
-
if it['deployType'] == 'git'
|
348
|
-
"#{it['gitRef']}"
|
349
|
-
end
|
350
|
-
},
|
355
|
+
"URL" => lambda {|it| it['fetchUrl'] || it['gitUrl'] || it['url'] },
|
356
|
+
"Ref" => lambda {|it| it['gitRef'] || it['ref'] },
|
351
357
|
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
352
358
|
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
353
359
|
}
|
354
360
|
if deployment_version['deployType'] == 'git'
|
355
|
-
|
361
|
+
options[:no_files] = true
|
356
362
|
elsif deployment_version['deployType'] == 'fetch'
|
363
|
+
options[:no_files] = true
|
357
364
|
columns['Fetch URL'] = columns['URL']
|
358
365
|
columns.delete('Ref')
|
359
366
|
else
|
@@ -362,6 +369,18 @@ EOT
|
|
362
369
|
end
|
363
370
|
print_description_list(columns, deployment_version)
|
364
371
|
print reset,"\n"
|
372
|
+
|
373
|
+
if options[:no_files] != true
|
374
|
+
print_h2 "Deployment Files", options
|
375
|
+
if !deployment_files || deployment_files.empty?
|
376
|
+
print cyan,"No files found.",reset,"\n"
|
377
|
+
else
|
378
|
+
print as_pretty_table(deployment_files, deployment_file_column_definitions.upcase_keys!, options)
|
379
|
+
print_results_pagination({size:deployment_files.size,total:deployment_files.size.to_i})
|
380
|
+
end
|
381
|
+
print reset,"\n"
|
382
|
+
end
|
383
|
+
|
365
384
|
end
|
366
385
|
return 0, nil
|
367
386
|
end
|
@@ -371,7 +390,11 @@ EOT
|
|
371
390
|
params = {}
|
372
391
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
373
392
|
opts.banner = subcommand_usage("[deployment] [version] [options]")
|
393
|
+
opts.on('-t', '--type CODE', String, "Deploy Type, file, git or fetch, default is file.") do |val|
|
394
|
+
options[:options]['deployType'] = val
|
395
|
+
end
|
374
396
|
build_option_type_options(opts, options, add_deployment_version_option_types)
|
397
|
+
opts.add_hidden_option('--deployType')
|
375
398
|
build_option_type_options(opts, options, add_deployment_version_advanced_option_types)
|
376
399
|
build_standard_add_options(opts, options)
|
377
400
|
opts.footer = <<-EOT
|
@@ -485,28 +508,304 @@ EOT
|
|
485
508
|
verify_args!(args:args, optparse:optparse, count:2)
|
486
509
|
connect(options)
|
487
510
|
deployment = find_deployment_by_name_or_id(args[0])
|
488
|
-
return 1 if deployment.nil?
|
511
|
+
return 1, "deployment not found" if deployment.nil?
|
489
512
|
id = args[1]
|
513
|
+
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], id)
|
514
|
+
return 1, "version not found" if deployment_version.nil?
|
515
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the deployment version #{format_deployment_version_number(deployment_version)}?")
|
516
|
+
return 9, "aborted command"
|
517
|
+
end
|
518
|
+
@deployments_interface.setopts(options)
|
519
|
+
if options[:dry_run]
|
520
|
+
print_dry_run @deployments_interface.dry.destroy_version(deployment['id'], deployment_version['id'], params)
|
521
|
+
return
|
522
|
+
end
|
523
|
+
json_response = @deployments_interface.destroy_version(deployment['id'], deployment_version['id'], params)
|
524
|
+
render_response(json_response, options) do
|
525
|
+
print_green_success "Removed deployment #{deployment['name']} version #{format_deployment_version_number(deployment_version)}"
|
526
|
+
end
|
527
|
+
return 0, nil
|
528
|
+
end
|
490
529
|
|
491
|
-
|
492
|
-
|
530
|
+
def list_files(args)
|
531
|
+
options = {}
|
532
|
+
params = {}
|
533
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
534
|
+
opts.banner = subcommand_usage("[deployment] [version] [path] [options]")
|
535
|
+
build_standard_list_options(opts, options)
|
536
|
+
opts.footer = <<-EOT
|
537
|
+
List files in a deployment version.
|
538
|
+
[deployment] is required. This is the name or id of a deployment.
|
539
|
+
[version] is required. This is the deployment version identifier
|
540
|
+
[path] is optional. This is a the directory to search for files under.
|
541
|
+
EOT
|
542
|
+
end
|
543
|
+
optparse.parse!(args)
|
544
|
+
verify_args!(args:args, optparse:optparse, min:2, max: 3)
|
545
|
+
connect(options)
|
546
|
+
params.merge!(parse_list_options(options))
|
547
|
+
deployment = find_deployment_by_name_or_id(args[0])
|
548
|
+
return 1, "deployment not found for '#{args[0]}'" if deployment.nil?
|
549
|
+
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], args[1])
|
550
|
+
return 1, "deployment version not found for '#{args[1]}'" if deployment_version.nil?
|
551
|
+
if args[2]
|
552
|
+
params['filePath'] = args[2]
|
553
|
+
end
|
554
|
+
@deployments_interface.setopts(options)
|
555
|
+
if options[:dry_run]
|
556
|
+
print_dry_run @deployments_interface.dry.list_files(deployment['id'], deployment_version['id'], params)
|
557
|
+
return
|
558
|
+
end
|
559
|
+
json_response = @deployments_interface.list_files(deployment['id'], deployment_version['id'], params)
|
560
|
+
# odd, api used to just return an array
|
561
|
+
deployment_files = json_response.is_a?(Array) ? json_response : json_response['files']
|
562
|
+
render_response(json_response, options) do
|
563
|
+
print_h1 "Deployment Files", ["#{deployment['name']} #{format_deployment_version_number(deployment_version)}"]
|
564
|
+
if !deployment_files || deployment_files.empty?
|
565
|
+
print cyan,"No files found.",reset,"\n"
|
566
|
+
else
|
567
|
+
print as_pretty_table(deployment_files, deployment_file_column_definitions.upcase_keys!, options)
|
568
|
+
#print_results_pagination(json_response)
|
569
|
+
print_results_pagination({size:deployment_files.size,total:deployment_files.size.to_i})
|
570
|
+
end
|
571
|
+
print reset,"\n"
|
572
|
+
end
|
573
|
+
return 0, nil
|
574
|
+
end
|
575
|
+
|
576
|
+
def upload(args)
|
577
|
+
options = {}
|
578
|
+
params = {}
|
579
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
580
|
+
opts.banner = subcommand_usage("[deployment] [version] [files]")
|
581
|
+
opts.on('--files LIST', String, "Files to upload") do |val|
|
582
|
+
val_list = val.to_s.split(",").collect {|it| it.to_s.strip }.select { |it| it != "" }
|
583
|
+
options[:files] ||= []
|
584
|
+
options[:files] += val_list
|
585
|
+
end
|
586
|
+
opts.on('--workdir DIRECTORY', String, "Working directory to switch to before uploading files, determines the paths of the uploaded files. The current working directory of your terminal is used by default.") do |val|
|
587
|
+
options[:workdir] = File.expand_path(val)
|
588
|
+
if !File.directory?(options[:workdir])
|
589
|
+
raise_command_error "invalid directory: #{val}"
|
590
|
+
end
|
591
|
+
end
|
592
|
+
opts.on('--destination FILEPATH', String, "Destination filepath for file being uploaded, should include full filename and extension. Only applies when uploading a single file.") do |val|
|
593
|
+
options[:destination] = val
|
594
|
+
end
|
595
|
+
build_standard_update_options(opts, options, [:auto_confirm])
|
596
|
+
opts.footer = <<-EOT
|
597
|
+
Upload one or more files or directories to a deployment version.
|
598
|
+
[deployment] is required. This is the name or id of a deployment.
|
599
|
+
[version] is required. This is the deployment version identifier
|
600
|
+
[files] is required. This is a list of files or directories to be uploaded. Glob pattern format supported eg. build/*.html
|
601
|
+
EOT
|
602
|
+
end
|
603
|
+
optparse.parse!(args)
|
604
|
+
# verify_args!(args:args, optparse:optparse, min:0, max:2)
|
605
|
+
connect(options)
|
606
|
+
|
607
|
+
# fetch deployment
|
608
|
+
deployment = nil
|
609
|
+
if args[0]
|
610
|
+
deployment = find_deployment_by_name_or_id(args[0])
|
611
|
+
return 1 if deployment.nil?
|
493
612
|
else
|
494
|
-
|
495
|
-
|
496
|
-
|
613
|
+
all_deployments = @deployments_interface.list(max:10000)['deployments']
|
614
|
+
deployment_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'deployment', 'fieldLabel' => 'Deployment', 'type' => 'select', 'required' => true, 'description' => 'Deployment identifier (name or ID)', 'optionSource' => lambda { |api_client, api_params|
|
615
|
+
all_deployments.collect {|it| {'name' => it['name'], 'value' => it['id']} }
|
616
|
+
}}], options[:options])['deployment']
|
617
|
+
deployment = all_deployments.find {|it| deployment_id == it['id'] || deployment_id == it['name'] }
|
618
|
+
raise_command_error "Deployment not found for '#{deployment_id}'" if deployment.nil?
|
619
|
+
end
|
620
|
+
|
621
|
+
# fetch deployment version
|
622
|
+
deployment_version = nil
|
623
|
+
if args[1]
|
624
|
+
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], args[1])
|
625
|
+
return 1 if deployment_version.nil?
|
626
|
+
else
|
627
|
+
all_deployment_versions = @deployments_interface.list_versions(deployment['id'], {max:10000})['versions']
|
628
|
+
deployment_version_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'version', 'fieldLabel' => 'Version', 'type' => 'select', 'required' => true, 'description' => 'Deployment Version identifier (version or ID) to upload files to', 'optionSource' => lambda { |api_client, api_params|
|
629
|
+
all_deployment_versions.collect {|it| {'name' => it['version'] || it['userVersion'], 'value' => it['id']} }
|
630
|
+
}}], options[:options])['version']
|
631
|
+
deployment_version = all_deployment_versions.find {|it| deployment_version_id == it['id'] || deployment_version_id == it['userVersion'] || deployment_version_id == it['version'] }
|
632
|
+
raise_command_error "Deployment Version not found for '#{deployment_version_id}'" if deployment_version.nil?
|
633
|
+
end
|
634
|
+
|
635
|
+
|
636
|
+
# Determine which files to find
|
637
|
+
file_patterns = []
|
638
|
+
# [files] is args 3 - N
|
639
|
+
if args.size > 2
|
640
|
+
file_patterns += args[2..-1]
|
641
|
+
end
|
642
|
+
if options[:files]
|
643
|
+
file_patterns += options[:files]
|
644
|
+
end
|
645
|
+
if file_patterns.empty?
|
646
|
+
#raise_command_error "Files not specified. Please specify files array, each item may specify a path or pattern of file(s) to upload", args, optparse
|
647
|
+
file_patterns = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'files', 'fieldLabel' => 'Files', 'type' => 'text', 'required' => true, 'description' => 'Files or directories to upload'}], options[:options])['files'].to_s.split(",").collect {|it| it.to_s.strip }.select { |it| it != "" }
|
648
|
+
end
|
649
|
+
|
650
|
+
# Find Files to Upload
|
651
|
+
deploy_files = []
|
652
|
+
|
653
|
+
#print "\n",cyan, "Finding Files...", reset, "\n" unless options[:quiet]
|
654
|
+
original_working_dir = Dir.pwd
|
655
|
+
base_working_dir = options[:workdir] || original_working_dir
|
656
|
+
begin
|
657
|
+
file_patterns.each do |file_pattern|
|
658
|
+
# start in the working directory
|
659
|
+
# to preserve relative paths in upload file destinations
|
660
|
+
# allow passing just build instead build/**/*
|
661
|
+
Dir.chdir(base_working_dir)
|
662
|
+
fmap = nil
|
663
|
+
full_file_pattern = File.expand_path(file_pattern)
|
664
|
+
if File.exists?(full_file_pattern)
|
665
|
+
if File.directory?(full_file_pattern)
|
666
|
+
fmap = {'path' => full_file_pattern, 'pattern' => '**/*'}
|
667
|
+
else
|
668
|
+
fmap = {'path' => File.dirname(full_file_pattern), 'pattern' => File.basename(full_file_pattern)}
|
669
|
+
end
|
670
|
+
else
|
671
|
+
fmap = {'path' => nil, 'pattern' => file_pattern}
|
672
|
+
end
|
673
|
+
if fmap['path']
|
674
|
+
Dir.chdir(File.expand_path(fmap['path']))
|
675
|
+
end
|
676
|
+
files = Dir.glob(fmap['pattern'] || '**/*')
|
677
|
+
if files.empty?
|
678
|
+
raise_command_error "Found 0 files for file pattern '#{file_pattern}'"
|
679
|
+
end
|
680
|
+
files.each do |file|
|
681
|
+
if File.file?(file)
|
682
|
+
destination = file.split("/")[0..-2].join("/")
|
683
|
+
# deploy_files << {filepath: File.expand_path(file), destination: destination}
|
684
|
+
# absolute path was given, so no path is given to the destination file
|
685
|
+
# maybe apply options[:destination] as prefix here
|
686
|
+
# actually just do destination.sub!(base_working_dir, '')
|
687
|
+
if file[0].chr == "/"
|
688
|
+
deploy_files << {filepath: File.expand_path(file), destination: File.basename(file)}
|
689
|
+
else
|
690
|
+
deploy_files << {filepath: File.expand_path(file), destination: file}
|
691
|
+
end
|
692
|
+
end
|
693
|
+
end
|
694
|
+
end
|
695
|
+
#print cyan, "Found #{deploy_files.size} Files to Upload!", reset, "\n"
|
696
|
+
rescue => ex
|
697
|
+
# does not happen, just in case
|
698
|
+
#print_error "An error occured while searching for files to upload: #{ex}"
|
699
|
+
raise ex
|
700
|
+
ensure
|
701
|
+
Dir.chdir(original_working_dir)
|
702
|
+
end
|
703
|
+
|
704
|
+
# make sure we have something to upload.
|
705
|
+
if deploy_files.empty?
|
706
|
+
raise_command_error "0 files found for: #{file_patterns.join(', ')}"
|
707
|
+
else
|
708
|
+
unless options[:quiet]
|
709
|
+
print cyan, "Found #{deploy_files.size} Files to Upload!", reset, "\n"
|
710
|
+
end
|
711
|
+
end
|
712
|
+
|
713
|
+
# support uploading a local file to a custom destination
|
714
|
+
# this only works for a single file right now, should be better
|
715
|
+
# could try to add destination + filename
|
716
|
+
# for now expect filename to be included in destination
|
717
|
+
if options[:destination]
|
718
|
+
if deploy_files.size == 1
|
719
|
+
deploy_files[0][:destination] = options[:destination]
|
497
720
|
else
|
498
|
-
|
499
|
-
return 1, "deployment version not found for '#{id}'"
|
721
|
+
raise_command_error "--destination can only specified for a single file upload, not #{deploy_files} files.", args, optparse
|
500
722
|
end
|
501
723
|
end
|
724
|
+
|
725
|
+
confirm_message = "Are you sure you want to upload #{deploy_files.size} files to deployment #{deployment['name']} #{format_deployment_version_number(deployment_version)}?"
|
726
|
+
if deploy_files.size == 1
|
727
|
+
confirm_message = "Are you sure you want to upload file #{deploy_files[0][:destination]} to deployment #{deployment['name']} #{format_deployment_version_number(deployment_version)}?"
|
728
|
+
end
|
729
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm(confirm_message)
|
730
|
+
return 9, "aborted command"
|
731
|
+
end
|
732
|
+
|
733
|
+
@deployments_interface.setopts(options)
|
734
|
+
|
735
|
+
# Upload Files
|
736
|
+
if deploy_files && !deploy_files.empty?
|
737
|
+
print "\n",cyan, "Uploading #{deploy_files.size} Files...", reset, "\n" if !options[:quiet]
|
738
|
+
deploy_files.each do |f|
|
739
|
+
destination = f[:destination]
|
740
|
+
if options[:dry_run]
|
741
|
+
print_dry_run @deployments_interface.upload_file(deployment['id'], deployment_version['id'], f[:filepath], f[:destination])
|
742
|
+
else
|
743
|
+
print cyan," - Uploading #{f[:destination]} ...", reset if !options[:quiet]
|
744
|
+
upload_result = @deployments_interface.upload_file(deployment['id'], deployment_version['id'], f[:filepath], f[:destination])
|
745
|
+
#print green + "SUCCESS" + reset + "\n" if !options[:quiet]
|
746
|
+
print reset, "\n" if !options[:quiet]
|
747
|
+
end
|
748
|
+
end
|
749
|
+
if options[:dry_run]
|
750
|
+
return 0, nil
|
751
|
+
end
|
752
|
+
#print cyan, "Upload Complete!", reset, "\n" if !options[:quiet]
|
753
|
+
if options[:quiet]
|
754
|
+
return 0, nil
|
755
|
+
else
|
756
|
+
print_green_success "Upload Complete!"
|
757
|
+
return get_version([deployment["id"], deployment_version['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
758
|
+
end
|
759
|
+
else
|
760
|
+
raise_command_error "No files to upload!"
|
761
|
+
end
|
762
|
+
end
|
763
|
+
|
764
|
+
def remove_file(args)
|
765
|
+
options = {}
|
766
|
+
params = {}
|
767
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
768
|
+
opts.banner = subcommand_usage("[deployment] [version] [file] [options]")
|
769
|
+
opts.on( '-R', '--recursive', "Delete a directory and all of its files. This must be passed if specifying a directory." ) do
|
770
|
+
# do_recursive = true
|
771
|
+
params['force'] = true
|
772
|
+
end
|
773
|
+
opts.on( '-f', '--force', "Force delete, this will do a recursive delete of directories." ) do
|
774
|
+
params['force'] = true
|
775
|
+
end
|
776
|
+
build_standard_remove_options(opts, options)
|
777
|
+
opts.footer = <<-EOT
|
778
|
+
Delete a deployment file.
|
779
|
+
[deployment] is required. This is the name or id of a deployment.
|
780
|
+
[version] is required. This is the version identifier of a deployment version.
|
781
|
+
[file] is required. This is the name of the file to be deleted.
|
782
|
+
EOT
|
783
|
+
end
|
784
|
+
optparse.parse!(args)
|
785
|
+
verify_args!(args:args, optparse:optparse, min:2, max:3)
|
786
|
+
connect(options)
|
787
|
+
deployment = find_deployment_by_name_or_id(args[0])
|
788
|
+
return 1, "deployment not found" if deployment.nil?
|
789
|
+
id = args[1]
|
790
|
+
deployment_version = find_deployment_version_by_name_or_id(deployment['id'], id)
|
791
|
+
return 1, "version not found" if deployment_version.nil?
|
792
|
+
# could look it up here, or allow a directory instead of a single file
|
793
|
+
filename = args[2]
|
794
|
+
if filename.nil?
|
795
|
+
#raise_command_error "Files not specified. Please specify files array, each item may specify a path or pattern of file(s) to upload", args, optparse
|
796
|
+
filename = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'file', 'fieldLabel' => 'Files', 'type' => 'text', 'required' => true, 'description' => 'Files or directories to upload'}], options[:options])['file'].to_s #.split(",").collect {|it| it.to_s.strip }.select { |it| it != "" }
|
797
|
+
end
|
798
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the file #{filename}?")
|
799
|
+
return 9, "aborted command"
|
800
|
+
end
|
502
801
|
@deployments_interface.setopts(options)
|
503
802
|
if options[:dry_run]
|
504
|
-
print_dry_run @deployments_interface.dry.
|
803
|
+
print_dry_run @deployments_interface.dry.destroy_file(deployment['id'], deployment_version['id'], filename, params)
|
505
804
|
return
|
506
805
|
end
|
507
|
-
json_response = @deployments_interface.
|
806
|
+
json_response = @deployments_interface.destroy_file(deployment['id'], deployment_version['id'], filename, params)
|
508
807
|
render_response(json_response, options) do
|
509
|
-
print_green_success "Removed deployment
|
808
|
+
print_green_success "Removed deployment file #{filename}"
|
510
809
|
end
|
511
810
|
return 0, nil
|
512
811
|
end
|
@@ -557,7 +856,7 @@ EOT
|
|
557
856
|
def deployment_version_column_definitions
|
558
857
|
{
|
559
858
|
"ID" => 'id',
|
560
|
-
"Version" =>
|
859
|
+
"Version" => lambda {|it| format_deployment_version_number(it) },
|
561
860
|
"Deploy Type" => lambda {|it| it['deployType'] },
|
562
861
|
"URL" => lambda {|it|
|
563
862
|
if it['deployType'] == 'fetch'
|
@@ -607,4 +906,18 @@ EOT
|
|
607
906
|
}
|
608
907
|
end
|
609
908
|
|
909
|
+
# Deployment Files
|
910
|
+
|
911
|
+
def deployment_file_column_definitions
|
912
|
+
{
|
913
|
+
#"ID" => 'id',
|
914
|
+
"Name" => 'name',
|
915
|
+
"Type" => lambda {|it| (it['directory'] || it['isDirectory']) ? "directory" : (it["contentType"] || "file") },
|
916
|
+
"Size" => lambda {|it| (it['directory'] || it['isDirectory']) ? "" : format_bytes_short(it['contentLength']) },
|
917
|
+
#"Content Type" => lambda {|it| it['contentType'] },
|
918
|
+
# "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
919
|
+
# "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
920
|
+
}
|
921
|
+
end
|
922
|
+
|
610
923
|
end
|