morpheus-cli 3.4.1.4 → 3.4.1.5

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
- SHA1:
3
- metadata.gz: e36f51274524a0ee48ba3f6c51e224d29bc42118
4
- data.tar.gz: dadbf3df8aa4ff8fd29d28ffc1b3407d22e2d02b
2
+ SHA256:
3
+ metadata.gz: 1733b5ed349e532113b94d11eea6d9f5f04c1e3b7395077192225a7c017dcc95
4
+ data.tar.gz: ae7c082eb787c6c2a360e571589bd804bedd482a2cccc0046d830c0f4692d15e
5
5
  SHA512:
6
- metadata.gz: 9e526f9adc5da2b3cadd57ea97ffa63ad89052383e8e0ecbe373edf6dd948503d078a0c302186365af8e07c1f769fdbf1b7c24dd441f0024ff97c4cad1de66fb
7
- data.tar.gz: 1ccc01cfd9fbc9a5785b41dc5ce294cc3b0b27a9e3e875777aa60db2f68d64594f3a6371154ecfce61bdc6b3c4db144271caeecb262b50864ac21086b2155e00
6
+ metadata.gz: 18e3085b2ebd404ad6b5b0094866fc129034c5e975ad652e42f3f175bba87bdf2793eb208fac00bbfefb317ca252498d67afbbfaee51655dbf126cd6289b63d6
7
+ data.tar.gz: 7a0aa9d880ad260ca43f1596db41d1b4997ced25818772aca2f7cdfd1490039878af574b1d340aeab6955e78e682dec1bce7c13dcfec9baae6d24da7f5c7fa53
@@ -1,4 +1,7 @@
1
1
  require 'morpheus/api/api_client'
2
+ require 'http'
3
+ require 'zlib'
4
+ require 'forwardable'
2
5
 
3
6
  class Morpheus::VirtualImagesInterface < Morpheus::APIClient
4
7
  def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
@@ -65,14 +68,87 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
65
68
  # execute(method: :post, url: url, headers: headers, payload: payload)
66
69
  # end
67
70
 
71
+ # wrapper class for input stream so that HTTP doesn't blow up when using it
72
+ # ie. calling size() and rewind()
73
+ class BodyIO
74
+ extend Forwardable
75
+
76
+ def initialize(io)
77
+ @io = io
78
+ end
79
+
80
+ def size
81
+ 0
82
+ end
83
+
84
+ def rewind
85
+ nil
86
+ end
87
+
88
+ def_delegators :@io, :read, :readpartial, :write
89
+
90
+ end
91
+
68
92
  # no multipart
69
- def upload(id, image_file, filename=nil)
93
+ def upload(id, image_file, filename=nil, do_gzip=false)
70
94
  filename = filename || File.basename(image_file)
71
95
  url = "#{@base_url}/api/virtual-images/#{id}/upload"
72
96
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
73
97
  headers[:params][:filename] = filename
74
98
  payload = image_file
75
- execute(method: :post, url: url, headers: headers, payload: payload, timeout: 36000)
99
+ #execute(method: :post, url: url, headers: headers, payload: payload, timeout: 36000)
100
+
101
+ # Using http.rb instead of RestClient
102
+ # todo: execute() should support :driver
103
+
104
+
105
+ http_opts = {}
106
+ if @verify_ssl == false
107
+ ctx = OpenSSL::SSL::SSLContext.new
108
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
109
+ http_opts[:ssl_context] = ctx
110
+ # opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
111
+ end
112
+
113
+ start_time = Time.now
114
+ query_params = headers.delete(:params) || {}
115
+ if do_gzip
116
+ # http = http.use(:auto_deflate)
117
+ headers['Content-Encoding'] = 'gzip'
118
+ headers['Content-Type'] = 'application/gzip'
119
+ headers['Content-Length'] = image_file.size
120
+ #headers['Transfer-Encoding'] = 'Chunked'
121
+ query_params['extractedContentLength'] = image_file.size
122
+ if @dry_run
123
+ return {method: :post, url: url, headers: headers, params: query_params, payload: payload}
124
+ end
125
+ http = HTTP.headers(headers)
126
+ http_opts[:params] = query_params
127
+
128
+ rd, wr = IO.pipe
129
+ Thread.new {
130
+ gz = Zlib::GzipWriter.new(wr)
131
+ File.open(payload) do |fp|
132
+ while chunk = fp.read(10 * 1024 * 1024) do
133
+ gz.write chunk
134
+ end
135
+ end
136
+ gz.close
137
+ }
138
+ http_opts[:body] = BodyIO.new(rd)
139
+ response = http.post(url, http_opts)
140
+ else
141
+ if @dry_run
142
+ return {method: :post, url: url, headers: headers, params: query_params, payload: payload}
143
+ end
144
+ http = HTTP.headers(headers)
145
+ http_opts[:params] = query_params
146
+ http_opts[:body] = payload
147
+ response = http.post(url, http_opts)
148
+ end
149
+ # puts "Took #{Time.now.to_i - start_time.to_i}"
150
+ # return response
151
+ return JSON.parse(response.body.to_s)
76
152
  end
77
153
 
78
154
  def upload_by_url(id, file_url, filename=nil)
@@ -103,7 +103,7 @@ module Morpheus::Cli::PrintHelper
103
103
  url = "#{url}?#{query_string}"
104
104
  end
105
105
  request_string = "#{http_method.to_s.upcase} #{url}".strip
106
- payload = opts[:payload]
106
+ payload = opts[:payload] || opts[:body]
107
107
  if command_string
108
108
  print_h1 "DRY RUN > #{command_string}"
109
109
  else
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "3.4.1.4"
4
+ VERSION = "3.4.1.5"
5
5
  end
6
6
  end
@@ -458,6 +458,7 @@ class Morpheus::Cli::VirtualImages
458
458
  def add_file(args)
459
459
  file_url = nil
460
460
  file_name = nil
461
+ do_gzip = false
461
462
  options = {}
462
463
  optparse = Morpheus::Cli::OptionParser.new do |opts|
463
464
  opts.banner = subcommand_usage("[name] [filepath]")
@@ -467,6 +468,9 @@ class Morpheus::Cli::VirtualImages
467
468
  opts.on( '-U', '--url URL', "Image File URL. This can be used instead of [filepath]" ) do |val|
468
469
  file_url = val
469
470
  end
471
+ opts.on( nil, '--gzip', "Compress uploaded file" ) do
472
+ do_gzip = true
473
+ end
470
474
  build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
471
475
  opts.footer = "Upload a virtual image file." + "\n" +
472
476
  "[name] is required. This is the name or id of a virtual image." + "\n" +
@@ -511,13 +515,13 @@ class Morpheus::Cli::VirtualImages
511
515
  else
512
516
  image_file = File.new(filepath, 'rb')
513
517
  if options[:dry_run]
514
- print_dry_run @virtual_images_interface.dry.upload(image['id'], image_file, file_name)
518
+ print_dry_run @virtual_images_interface.dry.upload(image['id'], image_file, file_name, do_gzip)
515
519
  return
516
520
  end
517
521
  unless options[:quiet]
518
522
  print cyan, "Uploading file #{filepath} ...", reset, "\n"
519
523
  end
520
- json_response = @virtual_images_interface.upload(image['id'], image_file, file_name)
524
+ json_response = @virtual_images_interface.upload(image['id'], image_file, file_name, do_gzip)
521
525
  if options[:json]
522
526
  print JSON.pretty_generate(json_response)
523
527
  elsif !options[:quiet]
data/morpheus-cli.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '>= 2.3' # according to http.rb doc
21
22
  spec.add_development_dependency "bundler", "~> 1.6"
22
23
  spec.add_development_dependency "rake"
23
24
  spec.add_dependency 'term-ansicolor', '~> 1.3.0'
@@ -26,4 +27,5 @@ Gem::Specification.new do |spec|
26
27
  spec.add_dependency "filesize"
27
28
  spec.add_dependency 'mime-types'
28
29
  spec.add_dependency "table_print"
30
+ spec.add_dependency "http"
29
31
  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: 3.4.1.4
4
+ version: 3.4.1.5
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: 2018-07-11 00:00:00.000000000 Z
14
+ date: 2018-07-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -125,6 +125,20 @@ dependencies:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
+ - !ruby/object:Gem::Dependency
129
+ name: http
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
128
142
  description: Infrastructure agnostic cloud application management & orchestration
129
143
  CLI for Morpheus. Easily manage and orchestrate VMS on private or public infrastructure
130
144
  and containerized architectures.
@@ -321,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
335
  requirements:
322
336
  - - ">="
323
337
  - !ruby/object:Gem::Version
324
- version: '0'
338
+ version: '2.3'
325
339
  required_rubygems_version: !ruby/object:Gem::Requirement
326
340
  requirements:
327
341
  - - ">="
@@ -329,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
329
343
  version: '0'
330
344
  requirements: []
331
345
  rubyforge_project:
332
- rubygems_version: 2.4.8
346
+ rubygems_version: 2.7.6
333
347
  signing_key:
334
348
  specification_version: 4
335
349
  summary: Provides CLI Interface to the Morpheus Public/Private Cloud Appliance