morpheus-cli 3.6.8 → 3.6.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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/account_groups_interface.rb +2 -2
  3. data/lib/morpheus/api/accounts_interface.rb +4 -7
  4. data/lib/morpheus/api/api_client.rb +207 -70
  5. data/lib/morpheus/api/app_templates_interface.rb +7 -28
  6. data/lib/morpheus/api/apps_interface.rb +14 -21
  7. data/lib/morpheus/api/archive_buckets_interface.rb +2 -2
  8. data/lib/morpheus/api/archive_files_interface.rb +6 -6
  9. data/lib/morpheus/api/auth_interface.rb +14 -1
  10. data/lib/morpheus/api/blueprints_interface.rb +9 -16
  11. data/lib/morpheus/api/cloud_datastores_interface.rb +1 -1
  12. data/lib/morpheus/api/cloud_policies_interface.rb +1 -1
  13. data/lib/morpheus/api/clouds_interface.rb +18 -21
  14. data/lib/morpheus/api/cypher_interface.rb +19 -28
  15. data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
  16. data/lib/morpheus/api/group_policies_interface.rb +1 -1
  17. data/lib/morpheus/api/groups_interface.rb +4 -4
  18. data/lib/morpheus/api/image_builder_boot_scripts_interface.rb +1 -1
  19. data/lib/morpheus/api/image_builder_image_builds_interface.rb +2 -2
  20. data/lib/morpheus/api/image_builder_preseed_scripts_interface.rb +1 -1
  21. data/lib/morpheus/api/instances_interface.rb +17 -23
  22. data/lib/morpheus/api/logs_interface.rb +7 -10
  23. data/lib/morpheus/api/network_domains_interface.rb +1 -1
  24. data/lib/morpheus/api/network_groups_interface.rb +1 -1
  25. data/lib/morpheus/api/network_pool_servers_interface.rb +1 -1
  26. data/lib/morpheus/api/network_pools_interface.rb +1 -1
  27. data/lib/morpheus/api/network_proxies_interface.rb +1 -1
  28. data/lib/morpheus/api/network_services_interface.rb +1 -1
  29. data/lib/morpheus/api/networks_interface.rb +1 -1
  30. data/lib/morpheus/api/old_cypher_interface.rb +55 -0
  31. data/lib/morpheus/api/packages_interface.rb +1 -1
  32. data/lib/morpheus/api/policies_interface.rb +1 -1
  33. data/lib/morpheus/api/setup_interface.rb +1 -1
  34. data/lib/morpheus/api/storage_providers_interface.rb +1 -1
  35. data/lib/morpheus/api/whoami_interface.rb +1 -1
  36. data/lib/morpheus/benchmarking.rb +277 -0
  37. data/lib/morpheus/cli.rb +6 -22
  38. data/lib/morpheus/cli/access_token_command.rb +172 -0
  39. data/lib/morpheus/cli/accounts.rb +5 -0
  40. data/lib/morpheus/cli/apps.rb +93 -37
  41. data/lib/morpheus/cli/archives_command.rb +0 -2
  42. data/lib/morpheus/cli/auth_command.rb +112 -0
  43. data/lib/morpheus/cli/blueprints_command.rb +50 -13
  44. data/lib/morpheus/cli/change_password_command.rb +148 -0
  45. data/lib/morpheus/cli/cli_command.rb +173 -49
  46. data/lib/morpheus/cli/clouds.rb +15 -5
  47. data/lib/morpheus/cli/command_error.rb +7 -1
  48. data/lib/morpheus/cli/{alias_command.rb → commands/standard/alias_command.rb} +79 -51
  49. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +399 -0
  50. data/lib/morpheus/cli/commands/standard/coloring_command.rb +60 -0
  51. data/lib/morpheus/cli/{curl_command.rb → commands/standard/curl_command.rb} +0 -7
  52. data/lib/morpheus/cli/commands/standard/debug_command.rb +61 -0
  53. data/lib/morpheus/cli/{echo_command.rb → commands/standard/echo_command.rb} +1 -1
  54. data/lib/morpheus/cli/{edit_profile_command.rb → commands/standard/edit_profile_command.rb} +0 -0
  55. data/lib/morpheus/cli/{edit_rc_command.rb → commands/standard/edit_rc_command.rb} +0 -0
  56. data/lib/morpheus/cli/commands/standard/get_prompt_command.rb +39 -0
  57. data/lib/morpheus/cli/commands/standard/history_command.rb +76 -0
  58. data/lib/morpheus/cli/{log_level_command.rb → commands/standard/log_level_command.rb} +1 -1
  59. data/lib/morpheus/cli/{man_command.rb → commands/standard/man_command.rb} +2 -2
  60. data/lib/morpheus/cli/commands/standard/rm_command.rb +14 -0
  61. data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +54 -0
  62. data/lib/morpheus/cli/{sleep_command.rb → commands/standard/sleep_command.rb} +0 -0
  63. data/lib/morpheus/cli/{source_command.rb → commands/standard/source_command.rb} +0 -0
  64. data/lib/morpheus/cli/{ssl_verification_command.rb → commands/standard/ssl_verification_command.rb} +1 -1
  65. data/lib/morpheus/cli/commands/standard/tee_command.rb +14 -0
  66. data/lib/morpheus/cli/{version_command.rb → commands/standard/version_command.rb} +0 -0
  67. data/lib/morpheus/cli/credentials.rb +276 -87
  68. data/lib/morpheus/cli/cypher_command.rb +333 -214
  69. data/lib/morpheus/cli/error_handler.rb +12 -2
  70. data/lib/morpheus/cli/groups.rb +44 -20
  71. data/lib/morpheus/cli/hosts.rb +39 -16
  72. data/lib/morpheus/cli/instances.rb +114 -62
  73. data/lib/morpheus/cli/login.rb +74 -21
  74. data/lib/morpheus/cli/logout.rb +3 -4
  75. data/lib/morpheus/cli/mixins/accounts_helper.rb +50 -18
  76. data/lib/morpheus/cli/mixins/print_helper.rb +207 -42
  77. data/lib/morpheus/cli/old_cypher_command.rb +414 -0
  78. data/lib/morpheus/cli/option_parser.rb +6 -1
  79. data/lib/morpheus/cli/processes_command.rb +3 -0
  80. data/lib/morpheus/cli/remote.rb +11 -17
  81. data/lib/morpheus/cli/roles.rb +17 -17
  82. data/lib/morpheus/cli/security_groups.rb +47 -17
  83. data/lib/morpheus/cli/shell.rb +139 -79
  84. data/lib/morpheus/cli/tenants_command.rb +353 -0
  85. data/lib/morpheus/cli/users.rb +26 -18
  86. data/lib/morpheus/cli/version.rb +1 -1
  87. data/lib/morpheus/cli/whoami.rb +14 -10
  88. data/lib/morpheus/formatters.rb +4 -4
  89. data/lib/morpheus/logging.rb +16 -8
  90. data/lib/morpheus/terminal.rb +63 -34
  91. metadata +28 -15
  92. data/lib/morpheus/cli/coloring_command.rb +0 -45
  93. data/lib/morpheus/cli/set_prompt_command.rb +0 -51
@@ -48,7 +48,7 @@ class Morpheus::FileCopyRequestInterface < Morpheus::APIClient
48
48
  url = "#{@base_url}/api/file-copy-request/download/#{URI.escape(id)}"
49
49
  headers = { params: params, authorization: "Bearer #{@access_token}" }
50
50
  opts = {method: :get, url: url, headers: headers}
51
- # execute(opts, false)
51
+ # execute(opts, {parse_json: false})
52
52
  if Dir.exists?(outfile)
53
53
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
54
54
  end
@@ -40,7 +40,7 @@ class Morpheus::GroupPoliciesInterface < Morpheus::APIClient
40
40
  def destroy(group_id, id, params={})
41
41
  url = "#{@base_url}/api/groups/#{group_id}/policies/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -20,7 +20,7 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
20
20
  elsif options.is_a?(String)
21
21
  headers[:params]['name'] = options
22
22
  end
23
- opts = {method: :get, url: url, timeout: 30, headers: headers}
23
+ opts = {method: :get, url: url, headers: headers}
24
24
  execute(opts)
25
25
  end
26
26
 
@@ -28,7 +28,7 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
28
28
  url = "#{@base_url}/api/groups"
29
29
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
30
30
  payload = options
31
- opts = {method: :post, url: url, timeout: 30, headers: headers, payload: payload.to_json}
31
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
32
32
  execute(opts)
33
33
  end
34
34
 
@@ -43,7 +43,7 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
43
43
  def destroy(id)
44
44
  url = "#{@base_url}/api/groups/#{id}"
45
45
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
46
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
46
+ opts = {method: :delete, url: url, headers: headers}
47
47
  execute(opts)
48
48
  end
49
49
 
@@ -51,7 +51,7 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
51
51
  url = "#{@base_url}/api/groups/#{id}/update-zones"
52
52
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
53
53
  payload = options
54
- opts = {method: :put, url: url, timeout: 30, headers: headers, payload: payload.to_json}
54
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
55
55
  execute(opts)
56
56
  end
57
57
  end
@@ -40,7 +40,7 @@ class Morpheus::ImageBuilderBootScriptsInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/boot-scripts/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -47,14 +47,14 @@ class Morpheus::ImageBuilderImageBuildsInterface < Morpheus::APIClient
47
47
  def destroy(id, params={})
48
48
  url = "#{@base_url}/api/image-builds/#{id}"
49
49
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
50
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
50
+ opts = {method: :delete, url: url, headers: headers}
51
51
  execute(opts)
52
52
  end
53
53
 
54
54
  def run(id, params={})
55
55
  url = "#{@base_url}/api/image-builds/#{id}/run"
56
56
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
57
- opts = {method: :post, url: url, timeout: 30, headers: headers}
57
+ opts = {method: :post, url: url, headers: headers}
58
58
  execute(opts)
59
59
  end
60
60
 
@@ -40,7 +40,7 @@ class Morpheus::ImageBuilderPreseedScriptsInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/preseed-scripts/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -8,36 +8,34 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
8
8
  @expires_at = expires_at
9
9
  end
10
10
 
11
- def get(options=nil)
11
+ def get(params={})
12
12
  url = "#{@base_url}/api/instances"
13
13
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
14
-
15
- if options.is_a?(Hash)
16
- headers[:params].merge!(options)
17
- elsif options.is_a?(Numeric)
18
- url = "#{@base_url}/api/instances/#{options}"
19
- elsif options.is_a?(String)
20
- headers[:params]['name'] = options
14
+ if params.is_a?(Hash)
15
+ headers[:params].merge!(params)
16
+ elsif params.is_a?(Numeric)
17
+ url = "#{@base_url}/api/instances/#{params}"
18
+ elsif params.is_a?(String)
19
+ headers[:params]['name'] = params
21
20
  end
22
21
  opts = {method: :get, url: url, headers: headers}
23
22
  execute(opts)
24
23
  end
25
24
 
26
- def list(options={})
27
- get(options)
25
+ def list(params={})
26
+ get(params)
28
27
  end
29
28
 
30
- def get_envs(id, options=nil)
29
+ def get_envs(id, params={})
31
30
  url = "#{@base_url}/api/instances/#{id}/envs"
32
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
31
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
33
32
  opts = {method: :get, url: url, headers: headers}
34
33
  execute(opts)
35
34
  end
36
35
 
37
- def create_env(id, options)
36
+ def create_env(id, payload={})
38
37
  url = "#{@base_url}/api/instances/#{id}/envs"
39
38
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
40
- payload = options
41
39
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
42
40
  execute(opts)
43
41
  end
@@ -49,18 +47,16 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
49
47
  execute(opts)
50
48
  end
51
49
 
52
- def create(options)
50
+ def create(payload)
53
51
  url = "#{@base_url}/api/instances"
54
52
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
55
- payload = options
56
53
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
57
54
  execute(opts)
58
55
  end
59
56
 
60
- def update(id, options)
57
+ def update(id, payload)
61
58
  url = "#{@base_url}/api/instances/#{id}"
62
59
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
63
- payload = options
64
60
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
65
61
  execute(opts)
66
62
  end
@@ -180,10 +176,9 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
180
176
  execute(opts)
181
177
  end
182
178
 
183
- def clone(id, options)
179
+ def clone(id, payload)
184
180
  url = "#{@base_url}/api/instances/#{id}/clone"
185
181
  headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
186
- payload = options
187
182
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
188
183
  execute(opts)
189
184
  end
@@ -209,10 +204,9 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
209
204
  execute(opts)
210
205
  end
211
206
 
212
- def apply_security_groups(id, options)
207
+ def apply_security_groups(id, payload)
213
208
  url = "#{@base_url}/api/instances/#{id}/security-groups"
214
209
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
215
- payload = options
216
210
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
217
211
  execute(opts)
218
212
  end
@@ -223,7 +217,7 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
223
217
  execute(opts)
224
218
  end
225
219
 
226
- def service_plans(params)
220
+ def service_plans(params={})
227
221
  url = "#{@base_url}/api/instances/service-plans"
228
222
  headers = { params: params, authorization: "Bearer #{@access_token}" }
229
223
  opts = {method: :get, url: url, headers: headers}
@@ -8,25 +8,22 @@ class Morpheus::LogsInterface < Morpheus::APIClient
8
8
  @expires_at = expires_at
9
9
  end
10
10
 
11
- def container_logs(containers=[], options={})
11
+ def container_logs(containers=[], params={})
12
12
  url = "#{@base_url}/api/logs"
13
- headers = { params: {'containers' => containers}.merge(options), authorization: "Bearer #{@access_token}" }
14
- opts = {method: :get, url: url, headers: headers}
15
- execute(opts)
13
+ headers = { params: {'containers' => containers}.merge(params), authorization: "Bearer #{@access_token}" }
14
+ execute({method: :get, url: url, headers: headers})
16
15
  end
17
16
 
18
- def server_logs(servers=[], options={})
17
+ def server_logs(servers=[], params={})
19
18
  url = "#{@base_url}/api/logs"
20
- headers = { params: {'servers' => servers}.merge(options), authorization: "Bearer #{@access_token}" }
21
- opts = {method: :get, url: url, headers: headers}
22
- execute(opts)
19
+ headers = { params: {'servers' => servers}.merge(params), authorization: "Bearer #{@access_token}" }
20
+ execute({method: :get, url: url, headers: headers})
23
21
  end
24
22
 
25
23
  def stats()
26
24
  url = "#{@base_url}/api/logs/log-stats"
27
25
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
28
- opts = {method: :get, url: url, headers: headers}
29
- execute(opts)
26
+ execute({method: :get, url: url, headers: headers})
30
27
  end
31
28
 
32
29
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkDomainsInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/domains/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkGroupsInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/groups/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkPoolServersInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/pool-servers/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkPoolsInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/pools/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkProxiesInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/proxies/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworkServicesInterface < Morpheus::APIClient
40
40
  # def destroy(id, params={})
41
41
  # url = "#{@base_url}/api/networks/services/#{id}"
42
42
  # headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- # opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ # opts = {method: :delete, url: url, headers: headers}
44
44
  # execute(opts)
45
45
  # end
46
46
 
@@ -40,7 +40,7 @@ class Morpheus::NetworksInterface < Morpheus::APIClient
40
40
  def destroy(id, params={})
41
41
  url = "#{@base_url}/api/networks/#{id}"
42
42
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
43
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
43
+ opts = {method: :delete, url: url, headers: headers}
44
44
  execute(opts)
45
45
  end
46
46
 
@@ -0,0 +1,55 @@
1
+ require 'morpheus/api/api_client'
2
+ require 'uri'
3
+
4
+ class Morpheus::OldCypherInterface < Morpheus::APIClient
5
+ def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
6
+ @access_token = access_token
7
+ @refresh_token = refresh_token
8
+ @base_url = base_url
9
+ @expires_at = expires_at
10
+ end
11
+
12
+ def get(id, params={})
13
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
14
+ url = "#{@base_url}/api/cypher/#{id}"
15
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
16
+ opts = {method: :get, url: url, headers: headers}
17
+ execute(opts)
18
+ end
19
+
20
+ def list(params={})
21
+ url = "#{@base_url}/api/cypher"
22
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
23
+ opts = {method: :get, url: url, headers: headers}
24
+ execute(opts)
25
+ end
26
+
27
+ def create(payload)
28
+ url = "#{@base_url}/api/cypher"
29
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
30
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
31
+ execute(opts)
32
+ end
33
+
34
+ def update(id, payload)
35
+ url = "#{@base_url}/api/cypher/#{id}"
36
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
37
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
38
+ execute(opts)
39
+ end
40
+
41
+ def destroy(id, params={})
42
+ url = "#{@base_url}/api/cypher/#{id}"
43
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
44
+ opts = {method: :delete, url: url, headers: headers}
45
+ execute(opts)
46
+ end
47
+
48
+ def decrypt(id, params={})
49
+ url = "#{@base_url}/api/cypher/#{id}/decrypt"
50
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
51
+ opts = {method: :get, url: url, headers: headers}
52
+ execute(opts)
53
+ end
54
+
55
+ end
@@ -84,7 +84,7 @@ class Morpheus::PackagesInterface < Morpheus::APIClient
84
84
  url = "#{@base_url}/api/packages/export"
85
85
  headers = { params: params, authorization: "Bearer #{@access_token}" }
86
86
  opts = {method: :post, url: url, headers: headers}
87
- # execute(opts, false)
87
+ # execute(opts, {parse_json: false})
88
88
  if Dir.exists?(outfile)
89
89
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
90
90
  end
@@ -41,7 +41,7 @@ class Morpheus::PoliciesInterface < Morpheus::APIClient
41
41
  def destroy(id, params={})
42
42
  url = "#{@base_url}/api/policies/#{id}"
43
43
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
44
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
44
+ opts = {method: :delete, url: url, headers: headers}
45
45
  execute(opts)
46
46
  end
47
47
 
@@ -17,7 +17,7 @@ class Morpheus::SetupInterface < Morpheus::APIClient
17
17
  url = "#{@base_url}/ping"
18
18
  headers = {:params => params }
19
19
  opts = {method: :get, url: url, headers: headers, timeout: timeout}
20
- execute(opts, false)
20
+ execute(opts, {parse_json: false})
21
21
  end
22
22
 
23
23
  def check(params={}, timeout=5)
@@ -41,7 +41,7 @@ class Morpheus::StorageProvidersInterface < Morpheus::APIClient
41
41
  def destroy(id, params={})
42
42
  url = "#{@base_url}/api/storage/buckets/#{id}"
43
43
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
44
- opts = {method: :delete, url: url, timeout: 30, headers: headers}
44
+ opts = {method: :delete, url: url, headers: headers}
45
45
  execute(opts)
46
46
  end
47
47
 
@@ -8,7 +8,7 @@ class Morpheus::WhoamiInterface < Morpheus::APIClient
8
8
  @expires_at = expires_at
9
9
  end
10
10
 
11
- def get()
11
+ def get(params={})
12
12
  url = "#{@base_url}/api/whoami"
13
13
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
14
14
  execute(method: :get, url: url, headers: headers, timeout: 5)
@@ -0,0 +1,277 @@
1
+ require 'securerandom'
2
+ require 'morpheus/logging'
3
+
4
+ # Provides global Benchmarking functionality
5
+ # This provides a store of benchmarking records which can be looked up by name.
6
+ # There is also a global enabled flag that can be used.
7
+ # There is a mixin HasBenchmarking which provides start_benchmark(), stop_benchmark() and with_benchmark()
8
+ #
9
+ module Morpheus::Benchmarking
10
+
11
+ # a global toggle switch for benchmarking
12
+ @@enabled = false
13
+
14
+ def self.enabled?
15
+ @@enabled
16
+ end
17
+
18
+ def self.enabled
19
+ @@enabled
20
+ end
21
+
22
+ def self.enabled=(val)
23
+ @@enabled = !!val
24
+ end
25
+
26
+ # internal Array to store benchmark records for recording
27
+ # todo: garbage cleanup, roll these off to disk probably.
28
+ @@benchmark_record_list = []
29
+ def self.benchmark_record_list
30
+ @@benchmark_record_list
31
+ end
32
+
33
+ # internal Hash to lookup benchmark records by id
34
+ @@benchmark_id_store = {}
35
+ def self.benchmark_id_store
36
+ @@benchmark_id_store
37
+ end
38
+
39
+ # internal Hash to lookup benchmark records by name
40
+ @@benchmark_name_store = {}
41
+ def self.benchmark_name_store
42
+ @@benchmark_name_store
43
+ end
44
+
45
+ # start a new BenchmarkRecord
46
+ # @params opts [String or Hash] String as name like like "my routine" or with a Hash like {name: "my routine"}
47
+ # Just a String for name is fine because there are no other settings of interest at the moment.
48
+ # Optional, a test can be created without a name. A random :id will be available in the response.
49
+ # Examples:
50
+ # Morpheus::Benchmarking.start()
51
+ # Morpheus::Benchmarking.start("my routine")
52
+ # @returns BenchmarkRecord that looks like {id: ID, name:"my routine",start_time:Time}
53
+ def self.start(opts={})
54
+ benchmark_record = BenchmarkRecord.new(opts)
55
+ benchmark_record_list << benchmark_record
56
+ # index name and id
57
+ if benchmark_record.name
58
+ benchmark_name_store[benchmark_record.name.to_s] = benchmark_record
59
+ end
60
+ if benchmark_record.id
61
+ benchmark_id_store[benchmark_record.id.to_s] = benchmark_record
62
+ end
63
+ #benchmark_record.start() # initialize does it
64
+ return benchmark_record
65
+ end
66
+
67
+ # stop a BenchmarkRecord identified by name or options
68
+ # maybe: if opts is nil, the last record is returned
69
+ # @params opts [String or Hash] String as name like like "my routine" or with a Hash like {name: "my routine"} or {id:ID}
70
+ # @returns BenchmarkRecord that looks like {id: ID, name:"my routine",start_time:Time}
71
+ def self.stop(opts, exit_code=0, error=nil)
72
+ benchmark_record = self.lookup(opts)
73
+ if benchmark_record
74
+ benchmark_record.stop(exit_code, error)
75
+ return benchmark_record
76
+ else
77
+ return nil
78
+ end
79
+ end
80
+
81
+ # lookup a BenchmarkRecord identified by name or options, usually just name.
82
+ # @params cmd [String or Hash] Name like "my routine" or with a Hash like {id: ID}
83
+ # @returns BenchmarkRecord that looks like {id: ID, name:"my routine",start_time:Time}
84
+ def self.lookup(opts={})
85
+ benchmark_record = nil
86
+ if opts.nil? || opts.empty?
87
+ benchmark_record = nil
88
+ elsif opts.is_a?(Hash)
89
+ if opts[:id]
90
+ benchmark_record = benchmark_name_store[opts[:id].to_s]
91
+ elsif opts[:name]
92
+ benchmark_record = benchmark_id_store[opts[:name].to_s]
93
+ end
94
+ elsif opts.is_a?(String) || opts.is_a?(Symbol)
95
+ benchmark_record = benchmark_name_store[opts.to_s] || benchmark_id_store[opts.to_s]
96
+ else
97
+ Morpheus::Logging::DarkPrinter.puts "Benchmarking lookup passed a bad lookup argument: #{opts}" if Morpheus::Logging.debug?
98
+ end
99
+ # could to slow traversal of benchmark_record_list here..
100
+ return benchmark_record
101
+ end
102
+
103
+ # get last benchmark started. useful if the name, so `benchmark stop` can work
104
+ # use a unique name or else your record may be overwritten!
105
+ def self.last()
106
+ (@@benchmark_record_list || []).last
107
+ end
108
+
109
+ # Mixin for any class that needs benchmarking
110
+ module HasBenchmarking
111
+
112
+ # true when benchmark is currently running
113
+ # def benchmarking?
114
+ # !!@benchmark_record
115
+ # end
116
+
117
+ # def benchmark_record
118
+ # @benchmark_record
119
+ # end
120
+
121
+ def with_benchmark(opts, &block)
122
+ exit_code, err = 0, nil
123
+ begin
124
+ start_benchmark(opts)
125
+ if block_given?
126
+ result = block.call()
127
+ # exit_code, err = Morpheus::Cli::CliCommand.parse_command_result(result)
128
+ if result.is_a?(Array)
129
+ exit_code = result[0]
130
+ err = result[0]
131
+ elsif result == true || result == nil
132
+ exit_code = 0
133
+ elsif result == false
134
+ exit_code = 1
135
+ else
136
+ exit_code = result
137
+ end
138
+ end
139
+ rescue => ex
140
+ raise ex
141
+ # exit_code = 1
142
+ # err = ex.msg
143
+ ensure
144
+ stop_benchmark(exit_code, err)
145
+ end
146
+ return exit_code, err
147
+ end
148
+
149
+ def start_benchmark(opts)
150
+ @benchmark_record = BenchmarkRecord.new(opts)
151
+ return @benchmark_record
152
+ end
153
+
154
+ # finish the current benchmark and optionally print the time taken.
155
+ def stop_benchmark(exit_code=0, err=nil)
156
+ if @benchmark_record
157
+ @benchmark_record.stop(exit_code, err)
158
+ @last_benchmark_record = @benchmark_record
159
+ @benchmark_record = nil
160
+ return @last_benchmark_record
161
+ else
162
+ return nil
163
+ end
164
+ end
165
+
166
+ end
167
+
168
+ # An internal class for modeling benchmark info on a single run.
169
+ # Examples:
170
+ # BenchmarkRecord.new()
171
+ # BenchmarkRecord.new("my routine")
172
+ # BenchmarkRecord.new({name:"my routine"})
173
+ class BenchmarkRecord
174
+
175
+ attr_reader :id, :name, :command, :start_time, :end_time, :exit_code, :error
176
+
177
+ def initialize(opts={})
178
+ # no info is fine, anonymous benchmark is cool
179
+ if opts.nil? || opts.empty?
180
+ opts = {}
181
+ end
182
+ # support String
183
+ opts = opts.is_a?(Hash) ? opts : {name: opts.to_s}
184
+ @id = opts[:id] || self.object_id
185
+ @name = opts[:name]
186
+ #@command = opts[:command]
187
+ # store the list of commands would be cool... to record adhoc scripts
188
+ # @commands = []
189
+ # @commands << @command if @command
190
+ start()
191
+ end
192
+
193
+ def start()
194
+ if !@start_time
195
+ @start_time = Time.now
196
+ end
197
+ return self
198
+ end
199
+
200
+ def stop(exit_code=0, error=nil)
201
+ if !@end_time
202
+ @end_time = Time.now
203
+ @exit_code = exit_code
204
+ @error = error
205
+ end
206
+ return self
207
+ end
208
+
209
+ def duration
210
+ if @start_time && @end_time
211
+ return @end_time - @start_time
212
+ elsif @start_time
213
+ return Time.now - @start_time
214
+ else
215
+ return 0
216
+ end
217
+ end
218
+
219
+ def msg
220
+ time_str = ""
221
+ seconds = self.duration
222
+ if seconds > 0.002
223
+ seconds = seconds.round(3)
224
+ else
225
+ #seconds = seconds.round(3)
226
+ end
227
+ duration_str = duration
228
+ if @start_time && @end_time
229
+ time_str = "#{seconds} seconds"
230
+ elsif @start_time
231
+ time_str = "#{seconds} seconds (running)"
232
+ else
233
+ time_str = "(unstarted)"
234
+ end
235
+ command_str = "#{@name}" # or "#{@name || @id}"
236
+ exit_str = "#{@exit_code}"
237
+ error_str = "#{@error}" # should inspect and format this
238
+ out = ""
239
+
240
+ if @end_time
241
+ out << "#{command_str.ljust(30, ' ')}"
242
+ else
243
+ out << "#{command_str.ljust(30, ' ')}"
244
+ end
245
+
246
+ # if @end_time
247
+ # out << "finished: #{command_str.ljust(30, ' ')}"
248
+ # else
249
+ # out << "running: #{command_str.ljust(30, ' ')}"
250
+ # end
251
+
252
+ #out = "benchmark: #{command_str.ljust(22, ' ')} time: #{time_str.ljust(9, ' ')} exit: #{exit_str.ljust(2, ' ')}"
253
+ # out = "benchmark: #{command_str.ljust(27, ' ')} time: #{time_str.ljust(9, ' ')} exit: #{exit_str.ljust(2, ' ')}"
254
+ #out = "time: #{time_str.ljust(9, ' ')} exit: #{exit_str.ljust(2, ' ')} exec: #{command_str}"
255
+ # how about a command you can copy and paste?
256
+ # out = "time: #{time_str.ljust(9, ' ')} exit: #{exit_str.ljust(2, ' ')} #{command_str}"
257
+ # out = "time: #{time_str.ljust(9, ' ')} exit: #{exit_str.ljust(4, ' ')} benchmark exec '#{command_str}'"
258
+ if @end_time || @exit_code
259
+ out << "\texit: #{exit_str.ljust(2, ' ')}"
260
+ end
261
+ if @end_time && @exit_code != 0 && @error
262
+ out << "\terror: #{error_str.ljust(12, ' ')}"
263
+ end
264
+
265
+ out << "\t#{time_str.ljust(9, ' ')}"
266
+
267
+
268
+ return out
269
+ end
270
+
271
+ def to_s
272
+ msg
273
+ end
274
+
275
+ end
276
+
277
+ end