morpheus-cli 5.3.0.3 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/README.md +1 -3
  4. data/lib/morpheus/api/api_client.rb +48 -14
  5. data/lib/morpheus/api/certificate_types_interface.rb +14 -0
  6. data/lib/morpheus/api/certificates_interface.rb +9 -0
  7. data/lib/morpheus/api/integration_types_interface.rb +14 -0
  8. data/lib/morpheus/api/integrations_interface.rb +7 -22
  9. data/lib/morpheus/api/network_services_interface.rb +14 -0
  10. data/lib/morpheus/api/read_interface.rb +23 -0
  11. data/lib/morpheus/api/rest_interface.rb +12 -10
  12. data/lib/morpheus/api/roles_interface.rb +7 -0
  13. data/lib/morpheus/api/servers_interface.rb +7 -0
  14. data/lib/morpheus/api/user_settings_interface.rb +38 -18
  15. data/lib/morpheus/api/vdi_allocations_interface.rb +9 -0
  16. data/lib/morpheus/api/vdi_apps_interface.rb +9 -0
  17. data/lib/morpheus/api/vdi_gateways_interface.rb +9 -0
  18. data/lib/morpheus/api/vdi_interface.rb +28 -0
  19. data/lib/morpheus/api/vdi_pools_interface.rb +19 -0
  20. data/lib/morpheus/cli.rb +9 -2
  21. data/lib/morpheus/cli/apps.rb +59 -75
  22. data/lib/morpheus/cli/catalog_item_types_command.rb +13 -13
  23. data/lib/morpheus/cli/certificates_command.rb +575 -0
  24. data/lib/morpheus/cli/cli_command.rb +61 -6
  25. data/lib/morpheus/cli/clouds.rb +1 -0
  26. data/lib/morpheus/cli/clusters.rb +1 -1
  27. data/lib/morpheus/cli/commands/standard/man_command.rb +4 -5
  28. data/lib/morpheus/cli/hosts.rb +245 -224
  29. data/lib/morpheus/cli/instances.rb +150 -167
  30. data/lib/morpheus/cli/integrations_command.rb +588 -41
  31. data/lib/morpheus/cli/login.rb +7 -0
  32. data/lib/morpheus/cli/mixins/print_helper.rb +33 -18
  33. data/lib/morpheus/cli/mixins/provisioning_helper.rb +3 -3
  34. data/lib/morpheus/cli/mixins/vdi_helper.rb +246 -0
  35. data/lib/morpheus/cli/network_routers_command.rb +22 -9
  36. data/lib/morpheus/cli/networks_command.rb +2 -2
  37. data/lib/morpheus/cli/option_types.rb +34 -33
  38. data/lib/morpheus/cli/remote.rb +1 -1
  39. data/lib/morpheus/cli/reports_command.rb +4 -1
  40. data/lib/morpheus/cli/roles.rb +215 -55
  41. data/lib/morpheus/cli/subnets_command.rb +11 -2
  42. data/lib/morpheus/cli/user_settings_command.rb +268 -57
  43. data/lib/morpheus/cli/vdi_allocations_command.rb +159 -0
  44. data/lib/morpheus/cli/vdi_apps_command.rb +317 -0
  45. data/lib/morpheus/cli/vdi_command.rb +359 -0
  46. data/lib/morpheus/cli/vdi_gateways_command.rb +290 -0
  47. data/lib/morpheus/cli/vdi_pools_command.rb +571 -0
  48. data/lib/morpheus/cli/version.rb +1 -1
  49. data/lib/morpheus/rest_client.rb +30 -0
  50. data/lib/morpheus/terminal.rb +15 -7
  51. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 537ea8ecb044cb316ca3c7610ff9d48d2cfdea448c37c2ce171d797143b9d5bb
4
- data.tar.gz: e80110f66f9a28496f507bebc117fb7aa74f770f33f8aadb9078bf331b4099f7
3
+ metadata.gz: 5ef633b92f3026067d66ea71995c2d7d2655579b07a200f083dccead54b371bb
4
+ data.tar.gz: 7fd5dedc5f5aa6a9c9a071f47639e9fa3f9a86a2a777e737d1a8581dfb195e86
5
5
  SHA512:
6
- metadata.gz: 0fff28a9b02ccbff264efa449fd56455316af3263c990cc15f37eae658f45c44e47f5138c33428744d0b687850fa7a710f9fe7193ca753da82057c5570da1ab0
7
- data.tar.gz: 7738424a32347e6e51970a7b4542accf527057f1634f4a798ec8e98cf0a908c92b5a14a0fda217dd2f94f2666c0d588f9935d5a0f2ab71b7dc78daa04b97563f
6
+ metadata.gz: 5e23c9f9a34bf2efa4f3d5c4299045fa800b04789abec9553daa134e4db271e274840b50627ac6131a1f4f38e14bda05e630dd4d47bb36dce0d001ef2bbed368
7
+ data.tar.gz: 3f55908e5d7f440a041de2ad74c8e0019123b04ed32fecaa6e3dfb14ae41e9b86c7b7a298e060d0c2ffb74db82349b80be08ac4e0a750453bed4ca66dbd640a9
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 5.3.0.3
3
+ RUN gem install morpheus-cli -v 5.3.1
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
data/README.md CHANGED
@@ -23,8 +23,6 @@ And then execute:
23
23
 
24
24
  $ bundle install
25
25
 
26
-
27
-
28
26
  ## Usage
29
27
 
30
28
  ### morpheus command
@@ -32,7 +30,7 @@ And then execute:
32
30
  This gem installs the [morpheus](https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual) binary for running commands in your terminal shell.
33
31
 
34
32
  ```sh
35
- morpheus remote add demo https://demo.mymorpheus.com
33
+ morpheus remote add
36
34
  morpheus instances list
37
35
  ```
38
36
 
@@ -146,6 +146,7 @@ class Morpheus::APIClient
146
146
  # :headers - Extra headers to add. This expects a Hash like {'Content-Type' => 'application/json'}.
147
147
  # :timeout - A custom timeout in seconds for api requests. The default is 30. todo: separate timeout options
148
148
  def execute(opts, options={})
149
+ # Morpheus::Logging::DarkPrinter.puts "Morpheus::RestClient.execute(#{opts})" if Morpheus::Logging.debug?
149
150
  # ok, always prepend @base_url, let the caller specify it exactly or leave it off.
150
151
  # this allows the Interface definition be lazy and not specify the base_url in every call to execute()
151
152
  # it will be used though...
@@ -174,7 +175,7 @@ class Morpheus::APIClient
174
175
  # apply default headers
175
176
  opts[:headers] ||= {}
176
177
 
177
- is_multipart = (opts[:payload].is_a?(Hash) && opts[:payload][:multipart])
178
+ is_multipart = (opts[:payload].is_a?(Hash) && opts[:payload][:multipart] == true)
178
179
 
179
180
  # Authorization: apply our access token
180
181
  if authorization_required?
@@ -187,15 +188,20 @@ class Morpheus::APIClient
187
188
  end
188
189
  end
189
190
 
190
- # Content-Type default is application/json
191
- if opts[:headers]['Content-Type'].nil? && opts[:payload] && is_multipart == false
192
- opts[:headers]['Content-Type'] = (default_content_type || 'application/json')
193
- end
191
+ # POST and PUT requests default Content-Type is application/json
192
+ # set Content-Type or pass :form_data => true if you want application/x-www-form-urlencoded
193
+ # or use opts[:payload][:multipart] = true if you need multipart/form-data
194
+ if opts[:method] == :post || opts[:method] == :put
195
+ if opts[:headers]['Content-Type'].nil? && opts[:payload] && is_multipart != true && opts[:form_data] != true
196
+ opts[:headers]['Content-Type'] = (default_content_type || 'application/json')
197
+ end
194
198
 
195
- # this could be nice too..
196
- # if opts[:headers]['Content-Type'] == 'application/json' && opts[:payload].is_a?(Hash)
197
- # opts[:payload] = opts[:payload].to_json
198
- # end
199
+ # Auto encode payload as JSON, just to be nice
200
+ if opts[:headers]['Content-Type'] == 'application/json' && !opts[:payload].is_a?(String)
201
+ opts[:payload] = opts[:payload].to_json
202
+ end
203
+
204
+ end
199
205
 
200
206
  # always use custom timeout eg. from --timeout option
201
207
  # or use default_timeout for GET requests only.
@@ -431,7 +437,11 @@ class Morpheus::APIClient
431
437
  end
432
438
 
433
439
  def integrations
434
- Morpheus::IntegrationsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
440
+ Morpheus::IntegrationsInterface.new(common_interface_options).setopts(@options)
441
+ end
442
+
443
+ def integration_types
444
+ Morpheus::IntegrationTypesInterface.new(common_interface_options).setopts(@options)
435
445
  end
436
446
 
437
447
  def jobs
@@ -534,12 +544,16 @@ class Morpheus::APIClient
534
544
  Morpheus::KeyPairsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
535
545
  end
536
546
 
537
- def license
538
- Morpheus::LicenseInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
547
+ def certificates
548
+ Morpheus::CertificatesInterface.new(common_interface_options).setopts(@options)
539
549
  end
540
550
 
541
- def custom_instance_types
542
- Morpheus::CustomInstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
551
+ def certificate_types
552
+ Morpheus::CertificateTypesInterface.new(common_interface_options).setopts(@options)
553
+ end
554
+
555
+ def license
556
+ Morpheus::LicenseInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
543
557
  end
544
558
 
545
559
  def option_types
@@ -787,6 +801,26 @@ class Morpheus::APIClient
787
801
  def billing
788
802
  Morpheus::BillingInterface.new(common_interface_options).setopts(@options)
789
803
  end
804
+
805
+ def vdi
806
+ Morpheus::VdiInterface.new(common_interface_options).setopts(@options)
807
+ end
808
+
809
+ def vdi_pools
810
+ Morpheus::VdiPoolsInterface.new(common_interface_options).setopts(@options)
811
+ end
812
+
813
+ def vdi_allocations
814
+ Morpheus::VdiAllocationsInterface.new(common_interface_options).setopts(@options)
815
+ end
816
+
817
+ def vdi_apps
818
+ Morpheus::VdiAppsInterface.new(common_interface_options).setopts(@options)
819
+ end
820
+
821
+ def vdi_gateways
822
+ Morpheus::VdiGatewaysInterface.new(common_interface_options).setopts(@options)
823
+ end
790
824
 
791
825
  # add new interfaces here
792
826
 
@@ -0,0 +1,14 @@
1
+ require 'morpheus/api/rest_interface'
2
+
3
+ class Morpheus::CertificateTypesInterface < Morpheus::RestInterface
4
+
5
+ def base_path
6
+ "/api/certificate-types"
7
+ end
8
+
9
+ def option_types(id, params={}, headers={})
10
+ validate_id!(id)
11
+ execute(method: :get, url: "#{base_path}/#{id}/option-types", params: params, headers: headers)
12
+ end
13
+
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/rest_interface'
2
+
3
+ class Morpheus::CertificatesInterface < Morpheus::RestInterface
4
+
5
+ def base_path
6
+ "/api/certificates"
7
+ end
8
+
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'morpheus/api/read_interface'
2
+
3
+ class Morpheus::IntegrationTypesInterface < Morpheus::ReadInterface
4
+
5
+ def base_path
6
+ "/api/integration-types"
7
+ end
8
+
9
+ def option_types(id, params={}, headers={})
10
+ validate_id!(id)
11
+ execute(method: :get, url: "#{base_path}/#{id}/option-types", params: params, headers: headers)
12
+ end
13
+
14
+ end
@@ -1,29 +1,14 @@
1
- require 'morpheus/api/api_client'
1
+ require 'morpheus/api/rest_interface'
2
2
 
3
- class Morpheus::IntegrationsInterface < Morpheus::APIClient
4
- def initialize(access_token, refresh_token,expires_at = nil, base_url=nil, api='integrations')
5
- @access_token = access_token
6
- @refresh_token = refresh_token
7
- @base_url = base_url
8
- @api_url = "#{base_url}/api/#{api}"
9
- @expires_at = expires_at
10
- end
3
+ class Morpheus::IntegrationsInterface < Morpheus::RestInterface
11
4
 
12
- def list(params={})
13
- url = @api_url
14
- headers = { params: params, authorization: "Bearer #{@access_token}" }
15
- execute(method: :get, url: url, headers: headers)
5
+ def base_path
6
+ "/api/integrations"
16
7
  end
17
8
 
18
- def get(id, params={})
19
- url = "#{@api_url}/#{id}"
20
- headers = { params: params, authorization: "Bearer #{@access_token}" }
21
- execute(method: :get, url: url, headers: headers)
9
+ def refresh(id, params={}, payload={}, headers={})
10
+ validate_id!(id)
11
+ execute(method: :post, url: "#{base_path}/#{id}/refresh", params: params, payload: payload, headers: headers)
22
12
  end
23
13
 
24
- def update(payload, params={})
25
- url = @api_url
26
- headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
27
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
28
- end
29
14
  end
@@ -23,6 +23,20 @@ class Morpheus::NetworkServicesInterface < Morpheus::APIClient
23
23
  execute(opts)
24
24
  end
25
25
 
26
+ def get(params={})
27
+ url = "#{@base_url}/api/networks/services"
28
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
29
+
30
+ if params.is_a?(Hash)
31
+ headers[:params].merge!(params)
32
+ elsif params.is_a?(Numeric)
33
+ url = "#{url}/#{params}"
34
+ elsif params.is_a?(String)
35
+ headers[:params]['name'] = params
36
+ end
37
+ execute(method: :get, url: url, headers: headers)
38
+ end
39
+
26
40
  # def create(payload)
27
41
  # url = "#{@base_url}/api/networks/services"
28
42
  # headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -0,0 +1,23 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ # Interface class to be subclassed by interfaces that are read-only
4
+ # and only provide list() and get() methods, not full CRUD
5
+ # Subclasses must override the base_path method
6
+ class Morpheus::ReadInterface < Morpheus::APIClient
7
+
8
+ # subclasses should override in your interface
9
+ # Example: "/api/thing-types"
10
+ def base_path
11
+ raise "#{self.class} has not defined base_path!"
12
+ end
13
+
14
+ def list(params={}, headers={})
15
+ execute(method: :get, url: "#{base_path}", params: params, headers: headers)
16
+ end
17
+
18
+ def get(id, params={}, headers={})
19
+ validate_id!(id)
20
+ execute(method: :get, url: "#{base_path}/#{id}", params: params, headers: headers)
21
+ end
22
+
23
+ end
@@ -1,5 +1,7 @@
1
1
  require 'morpheus/api/api_client'
2
2
 
3
+ # Interface class to be subclassed by interfaces that provide CRUD endpoints
4
+ # Subclasses must override the base_path method
3
5
  class Morpheus::RestInterface < Morpheus::APIClient
4
6
 
5
7
  # subclasses should override in your interface
@@ -8,27 +10,27 @@ class Morpheus::RestInterface < Morpheus::APIClient
8
10
  raise "#{self.class} has not defined base_path!"
9
11
  end
10
12
 
11
- def list(params={})
12
- execute(method: :get, url: "#{base_path}", params: params)
13
+ def list(params={}, headers={})
14
+ execute(method: :get, url: "#{base_path}", params: params, headers: headers)
13
15
  end
14
16
 
15
- def get(id, params={})
17
+ def get(id, params={}, headers={})
16
18
  validate_id!(id)
17
- execute(method: :get, url: "#{base_path}/#{id}", params: params)
19
+ execute(method: :get, url: "#{base_path}/#{id}", params: params, headers: headers)
18
20
  end
19
21
 
20
- def create(payload, params={})
21
- execute(method: :post, url: "#{base_path}", params: params, payload: payload.to_json)
22
+ def create(payload, params={}, headers={})
23
+ execute(method: :post, url: "#{base_path}", params: params, payload: payload, headers: headers)
22
24
  end
23
25
 
24
- def update(id, payload, params={})
26
+ def update(id, payload, params={}, headers={})
25
27
  validate_id!(id)
26
- execute(method: :put, url: "#{base_path}/#{id}", params: params, payload: payload.to_json)
28
+ execute(method: :put, url: "#{base_path}/#{id}", params: params, payload: payload, headers: headers)
27
29
  end
28
30
 
29
- def destroy(id, params = {})
31
+ def destroy(id, params = {}, headers={})
30
32
  validate_id!(id)
31
- execute(method: :delete, url: "#{base_path}/#{id}", params: params)
33
+ execute(method: :delete, url: "#{base_path}/#{id}", params: params, headers: headers)
32
34
  end
33
35
 
34
36
  end
@@ -91,6 +91,13 @@ class Morpheus::RolesInterface < Morpheus::APIClient
91
91
  execute(method: :put, url: url, headers: headers, payload: payload.to_json)
92
92
  end
93
93
 
94
+ def update_vdi_pool(account_id, id, options)
95
+ url = build_url(account_id, id) + "/update-vdi-pool"
96
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
97
+ payload = options
98
+ execute(method: :put, url: url, headers: headers, payload: payload.to_json)
99
+ end
100
+
94
101
  private
95
102
 
96
103
  def build_url(account_id=nil, role_id=nil)
@@ -183,4 +183,11 @@ class Morpheus::ServersInterface < Morpheus::APIClient
183
183
  execute(opts)
184
184
  end
185
185
 
186
+ def software_sync(id, payload={}, params={})
187
+ url = "#{@base_url}/api/servers/#{id}/software/sync"
188
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
189
+ opts = {method: :put, url: url, headers: headers}
190
+ execute(opts)
191
+ end
192
+
186
193
  end
@@ -2,31 +2,29 @@ require 'morpheus/api/api_client'
2
2
 
3
3
  class Morpheus::UserSettingsInterface < Morpheus::APIClient
4
4
 
5
- def get(params={})
6
- url = "#{@base_url}/api/user-settings"
7
- headers = { :params => params, authorization: "Bearer #{@access_token}"}
8
- opts = {method: :get, url: url, headers: headers}
9
- execute(opts)
5
+ def base_path
6
+ "/api/user-settings"
10
7
  end
11
8
 
12
- def update(params, payload)
13
- url = "#{@base_url}/api/user-settings"
14
- headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}
15
- opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
16
- execute(opts)
9
+ def get(params={}, headers={})
10
+ execute(method: :get, url: "#{base_path}", params: params, headers: headers)
17
11
  end
18
12
 
19
- # NOT json, download file as attachment
13
+ def update(payload, params={}, headers={})
14
+ execute(method: :put, url: "#{base_path}", params: params, payload: payload, headers: headers)
15
+ end
16
+
17
+ # download file as attachment
20
18
  def download_avatar(params, outfile)
21
- url = "#{@base_url}/api/user-settings/avatar"
19
+ url = "#{base_path}/avatar"
22
20
  headers = { :params => params, :authorization => "Bearer #{@access_token}"}
23
21
  opts = {method: :get, url: url, headers: headers, payload: payload}
24
22
  execute(opts)
25
23
  end
26
24
 
27
- # NOT json, multipart file upload
25
+ # multipart file upload
28
26
  def update_avatar(avatar_file, params={})
29
- url = "#{@base_url}/api/user-settings/avatar"
27
+ url = "#{base_path}/avatar"
30
28
  headers = { :params => params, :authorization => "Bearer #{@access_token}"}
31
29
  payload = {}
32
30
  #payload['user'] ||= {}
@@ -38,7 +36,29 @@ class Morpheus::UserSettingsInterface < Morpheus::APIClient
38
36
  end
39
37
 
40
38
  def remove_avatar(params={})
41
- url = "#{@base_url}/api/user-settings/avatar"
39
+ url = "#{base_path}/avatar"
40
+ headers = { :params => params, :authorization => "Bearer #{@access_token}"}
41
+ # POST empty payload will do
42
+ payload = {}
43
+ opts = {method: :delete, url: url, headers: headers, payload: payload}
44
+ execute(opts)
45
+ end
46
+
47
+ # multipart file upload
48
+ def update_desktop_background(desktop_background_file, params={})
49
+ url = "#{base_path}/desktop-background"
50
+ headers = { :params => params, :authorization => "Bearer #{@access_token}"}
51
+ payload = {}
52
+ #payload['user'] ||= {}
53
+ #payload['user']['desktopBackground'] = desktop_background_file
54
+ payload['user.desktopBackground'] = desktop_background_file
55
+ payload[:multipart] = true
56
+ opts = {method: :post, url: url, headers: headers, payload: payload}
57
+ execute(opts)
58
+ end
59
+
60
+ def remove_desktop_background(params={})
61
+ url = "#{base_path}/desktop-background"
42
62
  headers = { :params => params, :authorization => "Bearer #{@access_token}"}
43
63
  # POST empty payload will do
44
64
  payload = {}
@@ -47,21 +67,21 @@ class Morpheus::UserSettingsInterface < Morpheus::APIClient
47
67
  end
48
68
 
49
69
  def regenerate_access_token(params, payload={})
50
- url = "#{@base_url}/api/user-settings/regenerate-access-token"
70
+ url = "#{base_path}/regenerate-access-token"
51
71
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}
52
72
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
53
73
  execute(opts)
54
74
  end
55
75
 
56
76
  def clear_access_token(params, payload={})
57
- url = "#{@base_url}/api/user-settings/clear-access-token"
77
+ url = "#{base_path}/clear-access-token"
58
78
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}
59
79
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
60
80
  execute(opts)
61
81
  end
62
82
 
63
83
  def available_clients(params={})
64
- url = "#{@base_url}/api/user-settings/api-clients"
84
+ url = "#{base_path}/api-clients"
65
85
  headers = { :params => params, authorization: "Bearer #{@access_token}"}
66
86
  opts = {method: :get, url: url, headers: headers}
67
87
  execute(opts)
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/read_interface'
2
+
3
+ class Morpheus::VdiAllocationsInterface < Morpheus::ReadInterface
4
+
5
+ def base_path
6
+ "/api/vdi-allocations"
7
+ end
8
+
9
+ end