morpheus-cli 8.0.8 → 8.0.9.1

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: df49518b39388f8a75824156a31bff7fb8abcf4545a9f5af29bf6eab4eab6a79
4
- data.tar.gz: c82269904d1de5f01a487ebad5bd6ac2dd110a0c2e2b183142dfb42828c5edec
3
+ metadata.gz: 11090de632f0ba25e07141f1e169cbe0d626aafb4180cf472711c0f4a97c9799
4
+ data.tar.gz: 256e3748b3805cf0490ca9d0d6acc8c255743b535de5ab46159f1cb11169c012
5
5
  SHA512:
6
- metadata.gz: b64913eef407dd0180526e67095182b89517fa2863ee8bce319ba77fb1c1ca25d0898299ebebd6072dc9fcbd19a77f8d3f4fef3298563e24bd37121fb8ae6c75
7
- data.tar.gz: 6569d731faabe620597d94d20f78ffde2b5599934cd2b5bdb7153e86ce6cbd8359b83e0ff97a61d1d8ff6b8c4c8c6fc809a82e72ef39da5514859800e8388e2a
6
+ metadata.gz: f265f198cba356cfbda69235e80e6cd95b2261dcc2482ec08603ed463067af56c6acef8a7989aa079a78d8937bd33d5d5734e15956688bf656022b69b0f75298
7
+ data.tar.gz: 0db70e3343c6851efaeaaf487c86b92b6a652550bc713e78b435c3ff377e0d7244ae5eb6bfe96348ee22cd1251aedf3e2156d3196ac9137b826242ec160f2bec
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.7.5
2
2
 
3
- RUN gem install morpheus-cli -v 8.0.8
3
+ RUN gem install morpheus-cli -v 8.0.9.1
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -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
- execution_id = json_response['executionId']
1527
- if !options[:no_refresh] && execution_id
1528
- wait_for_execution_request(json_response['executionId'], options.merge({waiting_status:['new', 'pending', 'executing']}))
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, :convert, :types => :virtual_image_types
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)
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "8.0.8"
4
+ VERSION = "8.0.9.1"
5
5
  end
6
6
  end
data/morpheus-cli.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "filesize"
30
30
  spec.add_dependency 'mime-types'
31
31
  spec.add_dependency "http"
32
- spec.add_dependency "rubyzip"
32
+ spec.add_dependency "rubyzip", '~> 2.3.2'
33
33
  spec.add_dependency "money"
34
34
  spec.add_dependency "test-unit"
35
35
  end
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.8
4
+ version: 8.0.9.1
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-07-23 00:00:00.000000000 Z
14
+ date: 2025-08-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: public_suffix
@@ -157,16 +157,16 @@ dependencies:
157
157
  name: rubyzip
158
158
  requirement: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - ">="
160
+ - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: '0'
162
+ version: 2.3.2
163
163
  type: :runtime
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - ">="
167
+ - - "~>"
168
168
  - !ruby/object:Gem::Version
169
- version: '0'
169
+ version: 2.3.2
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: money
172
172
  requirement: !ruby/object:Gem::Requirement