morpheus-cli 8.0.8 → 8.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d39fa950eadfba7a601a27fb2930e536f4e10f4afa9993f98bfa6e9b69c2160f
|
4
|
+
data.tar.gz: 040fbc7832669327f0abbd84b31d372ce6d08d680bf2869e7daf25c9cf7d1900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 054f318d130302f9e322d2ea4c66fbd5e7cd87c0014af16df7ea20f5e52d4770421f081d107062f861e4f53b39e19e1c171ed077ff6b91e3e129660f1a056abb
|
7
|
+
data.tar.gz: 8fda4aaf40dc9449f7e9f54b9186520d6f5bf28934cee6d715104d670fdf3502899d9b2b5c32365473802ee0224861a318782ba87b86124eac4c4a55fc05f293
|
data/Dockerfile
CHANGED
@@ -149,6 +149,35 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
|
|
149
149
|
execute(method: :delete, url: url, headers: headers)
|
150
150
|
end
|
151
151
|
|
152
|
+
def download_chunked(id, outfile, params={})
|
153
|
+
raise "#{self.class}.download_chunked() passed a blank id!" if id.to_s == ''
|
154
|
+
url = "#{@base_url}/api/virtual-images/#{id}/download"
|
155
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
156
|
+
opts = {method: :get, url: url, headers: headers}
|
157
|
+
# execute(opts, {parse_json: false})
|
158
|
+
if Dir.exist?(outfile)
|
159
|
+
raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
|
160
|
+
end
|
161
|
+
# if @verify_ssl == false
|
162
|
+
# opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
|
163
|
+
# end
|
164
|
+
if @dry_run
|
165
|
+
return opts
|
166
|
+
end
|
167
|
+
http_response = nil
|
168
|
+
File.open(outfile, 'w') {|f|
|
169
|
+
block = proc { |response|
|
170
|
+
response.read_body do |chunk|
|
171
|
+
# writing to #{outfile} ..."
|
172
|
+
f.write chunk
|
173
|
+
end
|
174
|
+
}
|
175
|
+
opts[:block_response] = block
|
176
|
+
http_response = Morpheus::RestClient.execute(opts)
|
177
|
+
}
|
178
|
+
return http_response
|
179
|
+
end
|
180
|
+
|
152
181
|
def location_base_path(resource_id)
|
153
182
|
"/api/virtual-images/#{resource_id}/locations"
|
154
183
|
end
|
@@ -1523,9 +1523,13 @@ EOT
|
|
1523
1523
|
else
|
1524
1524
|
print_green_success json_response['msg']
|
1525
1525
|
end
|
1526
|
-
|
1527
|
-
if
|
1528
|
-
|
1526
|
+
process_id = json_response['processId'] || (json_response['processIds'] ? json_response['processIds'][0] : nil)
|
1527
|
+
if process_id
|
1528
|
+
unless options[:no_refresh]
|
1529
|
+
process = wait_for_process_execution(process_id, options)
|
1530
|
+
end
|
1531
|
+
else
|
1532
|
+
# puts "No process returned"
|
1529
1533
|
end
|
1530
1534
|
else
|
1531
1535
|
# never reached because unsuccessful requests raise an exception
|
@@ -6,7 +6,8 @@ class Morpheus::Cli::VirtualImages
|
|
6
6
|
include Morpheus::Cli::CliCommand
|
7
7
|
include Morpheus::Cli::ProvisioningHelper
|
8
8
|
|
9
|
-
register_subcommands :list, :get, :add, :add_file, :remove_file, :update, :remove,
|
9
|
+
register_subcommands :list, :get, :add, :add_file, :remove_file, :update, :remove,
|
10
|
+
:convert, {:types => :virtual_image_types}, :download
|
10
11
|
register_subcommands :list_locations, :get_location, :remove_location
|
11
12
|
|
12
13
|
# def initialize()
|
@@ -973,6 +974,94 @@ EOT
|
|
973
974
|
return 0, nil
|
974
975
|
end
|
975
976
|
|
977
|
+
def download(args)
|
978
|
+
full_command_string = "#{command_name} download #{args.join(' ')}".strip
|
979
|
+
options = {}
|
980
|
+
outfile = nil
|
981
|
+
do_overwrite = false
|
982
|
+
do_mkdir = false
|
983
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
984
|
+
opts.banner = subcommand_usage("[image] [local-file]")
|
985
|
+
opts.on( '-f', '--force', "Overwrite existing [local-file] if it exists." ) do
|
986
|
+
do_overwrite = true
|
987
|
+
# do_mkdir = true
|
988
|
+
end
|
989
|
+
opts.on( '-p', '--mkdir', "Create missing directories for [local-file] if they do not exist." ) do
|
990
|
+
do_mkdir = true
|
991
|
+
end
|
992
|
+
build_common_options(opts, options, [:dry_run, :quiet])
|
993
|
+
opts.footer = "Download a virtual image as a .zip file.\n" +
|
994
|
+
"[image] is required. This is the name or id of a virtual image.\n" +
|
995
|
+
"[local-file] is required. This is the full local filepath for the downloaded zip file."
|
996
|
+
end
|
997
|
+
optparse.parse!(args)
|
998
|
+
verify_args!(args:args, optparse:optparse, count:2)
|
999
|
+
connect(options)
|
1000
|
+
|
1001
|
+
virtual_image = find_virtual_image_by_name_or_id(args[0])
|
1002
|
+
return 1 if virtual_image.nil?
|
1003
|
+
outfile = args[1]
|
1004
|
+
# if outfile.end_with?(".zip")
|
1005
|
+
# print_red_alert "[local-file] is invalid. It must use extension .zip: #{outfile}"
|
1006
|
+
# return 1
|
1007
|
+
# end
|
1008
|
+
outfile = File.expand_path(outfile)
|
1009
|
+
if Dir.exist?(outfile)
|
1010
|
+
raise_command_error "[local-file] is invalid. It is the name of an existing directory: #{outfile}", args, optparse
|
1011
|
+
end
|
1012
|
+
destination_dir = File.dirname(outfile)
|
1013
|
+
if !Dir.exist?(destination_dir)
|
1014
|
+
if do_mkdir
|
1015
|
+
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
1016
|
+
FileUtils.mkdir_p(destination_dir)
|
1017
|
+
else
|
1018
|
+
raise_command_error "[local-file] is invalid. Directory not found: #{destination_dir}", args, optparse
|
1019
|
+
end
|
1020
|
+
end
|
1021
|
+
if File.exist?(outfile)
|
1022
|
+
if do_overwrite
|
1023
|
+
# uhh need to be careful wih the passed filepath here..
|
1024
|
+
# don't delete, just overwrite.
|
1025
|
+
# File.delete(outfile)
|
1026
|
+
else
|
1027
|
+
raise_command_error "[local-file] is invalid. File already exists: #{outfile}", "Use -f to overwrite the existing file.", args, optparse
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
@virtual_images_interface.setopts(options)
|
1032
|
+
if options[:dry_run]
|
1033
|
+
print_dry_run @virtual_images_interface.dry.download_chunked(virtual_image['id'], outfile), full_command_string
|
1034
|
+
return 0, nil
|
1035
|
+
end
|
1036
|
+
if !options[:quiet]
|
1037
|
+
print cyan + "Downloading archive file #{virtual_image['name']} to #{outfile} ... "
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
http_response = @virtual_images_interface.download_chunked(virtual_image['id'], outfile)
|
1041
|
+
|
1042
|
+
# FileUtils.chmod(0600, outfile)
|
1043
|
+
success = http_response.code.to_i == 200
|
1044
|
+
if success
|
1045
|
+
if !options[:quiet]
|
1046
|
+
print green + "SUCCESS" + reset + "\n"
|
1047
|
+
end
|
1048
|
+
return 0, nil
|
1049
|
+
else
|
1050
|
+
if !options[:quiet]
|
1051
|
+
print red + "ERROR" + reset + " HTTP #{http_response.code}" + "\n"
|
1052
|
+
end
|
1053
|
+
# F it, just remove a bad result
|
1054
|
+
if File.exist?(outfile) && File.file?(outfile)
|
1055
|
+
Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
|
1056
|
+
File.delete(outfile)
|
1057
|
+
end
|
1058
|
+
if options[:debug]
|
1059
|
+
puts_error http_response.inspect
|
1060
|
+
end
|
1061
|
+
return 1, "Error downloading file"
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
|
976
1065
|
private
|
977
1066
|
|
978
1067
|
def find_virtual_image_by_name_or_id(val)
|
data/lib/morpheus/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.
|
4
|
+
version: 8.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2025-
|
14
|
+
date: 2025-08-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: public_suffix
|