morpheus-cli 5.5.2.1 → 5.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Dockerfile +1 -1
  4. data/README.md +57 -4
  5. data/Rakefile +9 -0
  6. data/bin/morpheus +4 -4
  7. data/lib/morpheus/api/api_client.rb +8 -2
  8. data/lib/morpheus/api/archive_buckets_interface.rb +1 -1
  9. data/lib/morpheus/api/archive_files_interface.rb +3 -3
  10. data/lib/morpheus/api/clients_interface.rb +2 -2
  11. data/lib/morpheus/api/clusters_interface.rb +8 -1
  12. data/lib/morpheus/api/containers_interface.rb +29 -16
  13. data/lib/morpheus/api/custom_instance_types_interface.rb +0 -2
  14. data/lib/morpheus/api/doc_interface.rb +8 -6
  15. data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
  16. data/lib/morpheus/api/health_interface.rb +1 -1
  17. data/lib/morpheus/api/image_builder_interface.rb +3 -3
  18. data/lib/morpheus/api/instances_interface.rb +25 -0
  19. data/lib/morpheus/api/logs_interface.rb +2 -4
  20. data/lib/morpheus/api/monitoring_interface.rb +6 -6
  21. data/lib/morpheus/api/packages_interface.rb +1 -1
  22. data/lib/morpheus/api/reports_interface.rb +1 -1
  23. data/lib/morpheus/api/servers_interface.rb +9 -1
  24. data/lib/morpheus/api/storage_providers_interface.rb +2 -2
  25. data/lib/morpheus/api/virtual_images_interface.rb +1 -1
  26. data/lib/morpheus/api.rb +2 -0
  27. data/lib/morpheus/benchmarking.rb +1 -1
  28. data/lib/morpheus/cli/cli_command.rb +69 -36
  29. data/lib/morpheus/cli/cli_registry.rb +19 -10
  30. data/lib/morpheus/cli/commands/access_token_command.rb +1 -1
  31. data/lib/morpheus/cli/commands/apps.rb +1 -1
  32. data/lib/morpheus/cli/commands/archives_command.rb +25 -33
  33. data/lib/morpheus/cli/commands/blueprints_command.rb +10 -21
  34. data/lib/morpheus/cli/commands/boot_scripts_command.rb +2 -2
  35. data/lib/morpheus/cli/commands/cat_command.rb +1 -1
  36. data/lib/morpheus/cli/commands/catalog_item_types_command.rb +12 -12
  37. data/lib/morpheus/cli/commands/clouds.rb +3 -3
  38. data/lib/morpheus/cli/commands/clusters.rb +154 -3
  39. data/lib/morpheus/cli/commands/containers_command.rb +398 -253
  40. data/lib/morpheus/cli/commands/deployments.rb +1 -1
  41. data/lib/morpheus/cli/commands/deploys.rb +9 -9
  42. data/lib/morpheus/cli/commands/doc.rb +15 -16
  43. data/lib/morpheus/cli/commands/execution_request_command.rb +2 -2
  44. data/lib/morpheus/cli/commands/file_copy_request_command.rb +5 -5
  45. data/lib/morpheus/cli/commands/groups.rb +2 -2
  46. data/lib/morpheus/cli/commands/health_command.rb +4 -4
  47. data/lib/morpheus/cli/commands/hosts.rb +43 -5
  48. data/lib/morpheus/cli/commands/image_builder_command.rb +1 -1
  49. data/lib/morpheus/cli/commands/instances.rb +419 -148
  50. data/lib/morpheus/cli/commands/integrations_command.rb +22 -20
  51. data/lib/morpheus/cli/commands/key_pairs.rb +2 -2
  52. data/lib/morpheus/cli/commands/library_container_scripts_command.rb +2 -2
  53. data/lib/morpheus/cli/commands/library_container_templates_command.rb +2 -2
  54. data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -3
  55. data/lib/morpheus/cli/commands/library_spec_templates_command.rb +2 -2
  56. data/lib/morpheus/cli/commands/login.rb +1 -1
  57. data/lib/morpheus/cli/commands/man_command.rb +32 -18
  58. data/lib/morpheus/cli/commands/packages_command.rb +11 -11
  59. data/lib/morpheus/cli/commands/plugins.rb +1 -1
  60. data/lib/morpheus/cli/commands/policies_command.rb +4 -4
  61. data/lib/morpheus/cli/commands/preseed_scripts_command.rb +2 -2
  62. data/lib/morpheus/cli/commands/remote.rb +1 -1
  63. data/lib/morpheus/cli/commands/reports_command.rb +3 -3
  64. data/lib/morpheus/cli/commands/roles.rb +6 -3
  65. data/lib/morpheus/cli/commands/security_groups.rb +1 -1
  66. data/lib/morpheus/cli/commands/shell.rb +40 -62
  67. data/lib/morpheus/cli/commands/snapshots.rb +3 -5
  68. data/lib/morpheus/cli/commands/source_command.rb +8 -16
  69. data/lib/morpheus/cli/commands/storage_providers_command.rb +7 -7
  70. data/lib/morpheus/cli/commands/tasks.rb +2 -2
  71. data/lib/morpheus/cli/commands/vdi_pools_command.rb +6 -6
  72. data/lib/morpheus/cli/commands/view.rb +5 -1
  73. data/lib/morpheus/cli/commands/whitelabel_settings_command.rb +4 -4
  74. data/lib/morpheus/cli/commands/whoami.rb +2 -2
  75. data/lib/morpheus/cli/credentials.rb +30 -8
  76. data/lib/morpheus/cli/dot_file.rb +8 -15
  77. data/lib/morpheus/cli/error_handler.rb +16 -0
  78. data/lib/morpheus/cli/errors.rb +8 -1
  79. data/lib/morpheus/cli/mixins/print_helper.rb +17 -13
  80. data/lib/morpheus/cli/mixins/rest_command.rb +18 -18
  81. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +12 -12
  82. data/lib/morpheus/cli/option_parser.rb +5 -1
  83. data/lib/morpheus/cli/option_types.rb +59 -12
  84. data/lib/morpheus/cli/version.rb +1 -1
  85. data/lib/morpheus/cli.rb +26 -16
  86. data/lib/morpheus/ext/rest_client.rb +3 -2
  87. data/lib/morpheus/formatters.rb +1 -1
  88. data/lib/morpheus/logging.rb +4 -4
  89. data/lib/morpheus/morpkg.rb +4 -4
  90. data/lib/morpheus/rest_client.rb +2 -2
  91. data/lib/morpheus/routes.rb +2 -2
  92. data/lib/morpheus/terminal.rb +65 -16
  93. data/lib/morpheus.rb +1 -1
  94. data/morpheus-cli.gemspec +1 -0
  95. data/test/api/containers_interface_test.rb +68 -0
  96. data/test/api/doc_interface_test.rb +35 -0
  97. data/test/api/instances_interface_test.rb +22 -0
  98. data/test/api/whoami_interface_test.rb +14 -0
  99. data/test/cli/access_token_test.rb +36 -0
  100. data/test/cli/auth_test.rb +82 -0
  101. data/test/cli/cli_test.rb +48 -0
  102. data/test/cli/containers_test.rb +92 -0
  103. data/test/cli/doc_test.rb +35 -0
  104. data/test/cli/help_test.rb +25 -0
  105. data/test/cli/instances_test.rb +36 -0
  106. data/test/cli/man_test.rb +14 -0
  107. data/test/cli/remote_test.rb +89 -0
  108. data/test/cli/roles_test.rb +34 -0
  109. data/test/cli/shell_test.rb +81 -0
  110. data/test/cli/version_test.rb +23 -0
  111. data/test/cli/view_test.rb +55 -0
  112. data/test/cli/whoami_test.rb +17 -0
  113. data/test/morpheus_test.rb +16 -0
  114. data/test/test_case.rb +338 -0
  115. data/test/test_config.rb +137 -0
  116. data/test/test_data_helper.rb +97 -0
  117. metadata +61 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daf8c90febcbbae18fffbd020d9e9c0ba18fc99f12d9d51cf5a631e72a469b01
4
- data.tar.gz: 322f650e4cd9500706e9b55953e9ca2050c52b3442f45c634a3bde71408f3410
3
+ metadata.gz: 52fcaca1c4feaa6a3b07b3ed8772a6765cac55ccbac1b8d79eba9525a859829a
4
+ data.tar.gz: 868ccdde25b11e328c5c275ed61374922f5a287a5d662e5d3901c0218c863808
5
5
  SHA512:
6
- metadata.gz: 8b814666d55c2e34c14ae59f8adb6f1eb11ef762250c4d666594cc6cc90c0b781499f1345c13cf18b31faf637ca27c41943f2aa1592b9c977bd82ffc52ba9e96
7
- data.tar.gz: b63386cecaf56429f275affe452f803b7d8c285e30c3556023f2afbccb5fcd24e17f373506ab2a02069beb37cf1b4dfab533865e99ce62928fd66f99d8aa0793
6
+ metadata.gz: 1bff4307ff46a0940add6895b3fa16ac23da050e60ddc9d200d3c1d196eb29d1a3aa82025f203abb12b9f1950dd9fe7e7bf082bc13c797c91494bcf5092990ed
7
+ data.tar.gz: 874cfa21f6d6af7360c13dc504a453f3f7fb1539120c0b91af13a640727b6a19418b7c80912eb18b22dff4b4c94f8dea6f4372ba382ec7153c8936481de1131c
data/.gitignore CHANGED
@@ -21,4 +21,5 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .DS_Store
24
- .idea
24
+ .idea
25
+ test_config.yaml
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.7.5
2
2
 
3
- RUN gem install morpheus-cli -v 5.5.2.1
3
+ RUN gem install morpheus-cli -v 5.5.3
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
data/README.md CHANGED
@@ -13,15 +13,21 @@ This library is a Ruby gem that provides a command line interface for interactin
13
13
 
14
14
  Install it using rubygems
15
15
 
16
- $ gem install morpheus-cli
16
+ ```shell
17
+ gem install morpheus-cli
18
+ ```
17
19
 
18
20
  Or add this line to your application's Gemfile:
19
21
 
20
- gem 'morpheus-cli'
22
+ ```ruby
23
+ gem 'morpheus-cli'
24
+ ```
21
25
 
22
26
  And then execute:
23
27
 
24
- $ bundle install
28
+ ```shell
29
+ bundle install
30
+ ```
25
31
 
26
32
  ## Usage
27
33
 
@@ -29,7 +35,7 @@ And then execute:
29
35
 
30
36
  This gem installs the [morpheus](https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual) binary for running commands in your terminal shell.
31
37
 
32
- ```sh
38
+ ```shell
33
39
  morpheus remote add
34
40
  morpheus instances list
35
41
  ```
@@ -39,3 +45,50 @@ morpheus instances list
39
45
  If you are interested in interfacing with the Morpheus appliance in ruby directly, you can use [Morpheus::APIClient](https://github.com/gomorpheus/morpheus-cli/wiki/APIClient) or [Morpheus::Terminal](https://github.com/gomorpheus/morpheus-cli/wiki/Terminal).
40
46
 
41
47
  For more detailed usage information, visit the [Morpheus CLI Wiki](https://github.com/gomorpheus/morpheus-cli/wiki).
48
+
49
+
50
+ ## Development
51
+
52
+ New API interfaces get added under the library directory: `lib/morpheus/api/`.
53
+ New CLI commands get added under the library directory: `lib/morpheus/cli/commands/`.
54
+
55
+ While developing, you can quickly reload your code changes in a morpheus shell while developing:
56
+
57
+ ```shell
58
+ morpheus shell
59
+ ```
60
+
61
+ Then to reload changes without restarting the morpheus shell (and the ruby process), use:
62
+
63
+ ```shell
64
+ reload
65
+ ```
66
+
67
+ Don't forget to add unit tests for your new commands under the directory: `test/`.
68
+
69
+ ## Testing
70
+
71
+ To run the CLI unit tests, first create a `test_config.yaml` and then run `rake test`.
72
+
73
+ ### Prepare Test Environment
74
+
75
+ Create a `test_config.yaml` like this:
76
+
77
+ ```shell
78
+ touch test_config.yaml
79
+ ```
80
+
81
+ Enter your test environment url and credentials in `test_config.yaml` like so:
82
+
83
+ ```yaml
84
+ url: 'http://localhost:8080'
85
+ username: testrunner
86
+ password: 'SecretPassword123$'
87
+ ```
88
+
89
+ ### Run Tests
90
+
91
+ ```shell
92
+ rake test
93
+ ```
94
+
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ #task :default => :test
2
11
 
data/bin/morpheus CHANGED
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
- require 'morpheus/terminal'
2
+ require 'morpheus'
3
3
 
4
4
  # arguments
5
5
  args = ARGV
6
6
 
7
7
  # input pipe
8
8
  # append piped data as arguments
9
- if !STDIN.tty?
10
- pipe_data = STDIN.read
9
+ if !$stdin.tty?
10
+ pipe_data = $stdin.read
11
11
  if pipe_data
12
12
  args += pipe_data.split
13
13
  end
14
14
  end
15
15
 
16
16
  # output pipe
17
- # if !STDOUT.tty?
17
+ # if !$stdout.tty?
18
18
 
19
19
  # end
20
20
 
@@ -9,7 +9,6 @@ class Morpheus::APIClient
9
9
 
10
10
  CLIENT_ID = 'morph-cli' unless defined?(CLIENT_ID)
11
11
 
12
- attr_accessor :client_id
13
12
  # Initialize a new APIClient
14
13
  # client = APIClient.new(url:"https://morpheus.yourcompany.com", verify_ssl:false)
15
14
  # This old method signature is being deprecated:
@@ -40,9 +39,11 @@ class Morpheus::APIClient
40
39
  end
41
40
  @base_url = @base_url.chomp("/")
42
41
  # todo: validate URI
42
+ @expires_at = nil
43
43
  if expires_in != nil
44
44
  @expires_at = Time.now + expires_in
45
45
  end
46
+ @dry_run = false
46
47
  set_ssl_verification_enabled(verify_ssl)
47
48
  setopts(options)
48
49
  end
@@ -956,7 +957,12 @@ class Morpheus::APIClient
956
957
  protected
957
958
 
958
959
  def validate_id!(id, param_name='id')
959
- raise "#{self.class} passed a blank #{param_name}!" if id.to_s.strip.empty?
960
+ if !(id.is_a?(String) || id.is_a?(Integer))
961
+ raise "#{self.class} passed an invalid #{param_name}! Expected String or Integer and got (#{id.class}) #{id.inspect}"
962
+ elsif id.to_s.strip.empty?
963
+ raise "#{self.class} passed a blank #{param_name}!"
964
+ end
965
+ return true
960
966
  end
961
967
 
962
968
  end
@@ -83,7 +83,7 @@ class Morpheus::ArchiveBucketsInterface < Morpheus::APIClient
83
83
  headers = { params: params, authorization: "Bearer #{@access_token}" }
84
84
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
85
85
  # execute(opts, {parse_json:false})
86
- if Dir.exists?(outfile)
86
+ if Dir.exist?(outfile)
87
87
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
88
88
  end
89
89
  # if @verify_ssl == false
@@ -24,7 +24,7 @@ class Morpheus::ArchiveFilesInterface < Morpheus::APIClient
24
24
  headers = { params: params, authorization: "Bearer #{@access_token}" }
25
25
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
26
26
  # execute(opts, {parse_json: false})
27
- if Dir.exists?(outfile)
27
+ if Dir.exist?(outfile)
28
28
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
29
29
  end
30
30
  # if @verify_ssl == false
@@ -53,7 +53,7 @@ class Morpheus::ArchiveFilesInterface < Morpheus::APIClient
53
53
  headers = { params: params, authorization: "Bearer #{@access_token}" }
54
54
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
55
55
  # execute(opts, {parse_json: false})
56
- if Dir.exists?(outfile)
56
+ if Dir.exist?(outfile)
57
57
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
58
58
  end
59
59
  # if @verify_ssl == false
@@ -83,7 +83,7 @@ class Morpheus::ArchiveFilesInterface < Morpheus::APIClient
83
83
  headers = { params: params, authorization: "Bearer #{@access_token}" }
84
84
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
85
85
  # execute(opts, {parse_json: false})
86
- if Dir.exists?(outfile)
86
+ if Dir.exist?(outfile)
87
87
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
88
88
  end
89
89
  # if @verify_ssl == false
@@ -10,14 +10,14 @@ class Morpheus::ClientsInterface < Morpheus::APIClient
10
10
  end
11
11
 
12
12
  def get(id, params={})
13
- raise "#{self.class}.get() passed a blank name!" if id.to_s == ''
13
+ raise "#{self.class}.get() passed a blank name!" if id.to_s == ''
14
14
  url = "#{@base_url}/api/clients/#{id}"
15
15
  headers = { params: params, authorization: "Bearer #{@access_token}" }
16
16
  opts = {method: :get, url: url, headers: headers}
17
17
  execute(opts)
18
18
  end
19
19
 
20
- def create(payload)
20
+ def create(payload)
21
21
  url = "#{@base_url}/api/clients"
22
22
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
23
23
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
@@ -113,7 +113,7 @@ class Morpheus::ClustersInterface < Morpheus::APIClient
113
113
  url = "#{base_path}/#{id}/upgrade-cluster"
114
114
  headers = { params: params, authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
115
115
  execute(method: :post, url: url, headers: headers)
116
- end
116
+ end
117
117
 
118
118
  def list_services(id, params={})
119
119
  url = "#{base_path}/#{id}/services"
@@ -306,4 +306,11 @@ class Morpheus::ClustersInterface < Morpheus::APIClient
306
306
  execute(opts)
307
307
  end
308
308
 
309
+
310
+ def apply_template(id, payload={})
311
+ url = "#{@base_url}/api/clusters/#{id}/apply-template"
312
+
313
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
314
+ execute(method: :post, url: url, headers: headers, payload: payload.to_json)
315
+ end
309
316
  end
@@ -4,18 +4,21 @@ require 'morpheus/api/api_client'
4
4
  # All of the PUT methods support passing an array of IDs.
5
5
  class Morpheus::ContainersInterface < Morpheus::APIClient
6
6
 
7
+ def base_path
8
+ "/api/containers"
9
+ end
7
10
  # not used atm.. index api needs some work, we should implement it
8
11
  # so it just paginates all containers.
9
12
  # right now you can to pass params as {:ids => [1,2,3]}
10
13
  def list(params={})
11
- url = "#{@base_url}/api/containers"
14
+ url = "#{base_path}"
12
15
  headers = { params: params, authorization: "Bearer #{@access_token}" }
13
16
  opts = {method: :get, url: url, headers: headers}
14
17
  execute(opts)
15
18
  end
16
19
 
17
20
  def get(container_id)
18
- url = "#{@base_url}/api/containers/#{container_id}"
21
+ url = "#{base_path}/#{container_id}"
19
22
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
20
23
  opts = {method: :get, url: url, headers: headers}
21
24
  execute(opts)
@@ -24,10 +27,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
24
27
  def stop(container_id, payload={})
25
28
  url, params = "", {}
26
29
  if container_id.is_a?(Array)
27
- url = "#{@base_url}/api/containers/stop"
30
+ url = "#{base_path}/stop"
28
31
  params = {ids: container_id}
29
32
  else
30
- url = "#{@base_url}/api/containers/#{container_id}/stop"
33
+ url = "#{base_path}/#{container_id}/stop"
31
34
  params = {}
32
35
  end
33
36
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -38,10 +41,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
38
41
  def start(container_id, payload={})
39
42
  url, params = "", {}
40
43
  if container_id.is_a?(Array)
41
- url = "#{@base_url}/api/containers/start"
44
+ url = "#{base_path}/start"
42
45
  params = {ids: container_id}
43
46
  else
44
- url = "#{@base_url}/api/containers/#{container_id}/start"
47
+ url = "#{base_path}/#{container_id}/start"
45
48
  params = {}
46
49
  end
47
50
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -52,10 +55,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
52
55
  def restart(container_id, payload={})
53
56
  url, params = "", {}
54
57
  if container_id.is_a?(Array)
55
- url = "#{@base_url}/api/containers/restart"
58
+ url = "#{base_path}/restart"
56
59
  params = {ids: container_id}
57
60
  else
58
- url = "#{@base_url}/api/containers/#{container_id}/restart"
61
+ url = "#{base_path}/#{container_id}/restart"
59
62
  params = {}
60
63
  end
61
64
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -66,10 +69,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
66
69
  def suspend(container_id, payload={})
67
70
  url, params = "", {}
68
71
  if container_id.is_a?(Array)
69
- url = "#{@base_url}/api/containers/suspend"
72
+ url = "#{base_path}/suspend"
70
73
  params = {ids: container_id}
71
74
  else
72
- url = "#{@base_url}/api/containers/#{container_id}/suspend"
75
+ url = "#{base_path}/#{container_id}/suspend"
73
76
  params = {}
74
77
  end
75
78
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -80,10 +83,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
80
83
  def eject(container_id, payload={})
81
84
  url, params = "", {}
82
85
  if container_id.is_a?(Array)
83
- url = "#{@base_url}/api/containers/eject"
86
+ url = "#{base_path}/eject"
84
87
  params = {ids: container_id}
85
88
  else
86
- url = "#{@base_url}/api/containers/#{container_id}/eject"
89
+ url = "#{base_path}/#{container_id}/eject"
87
90
  params = {}
88
91
  end
89
92
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -94,10 +97,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
94
97
  def available_actions(container_id)
95
98
  url, params = "", {}
96
99
  if container_id.is_a?(Array)
97
- url = "#{@base_url}/api/containers/actions"
100
+ url = "#{base_path}/actions"
98
101
  params = {ids: container_id}
99
102
  else
100
- url = "#{@base_url}/api/containers/#{container_id}/actions"
103
+ url = "#{base_path}/#{container_id}/actions"
101
104
  params = {}
102
105
  end
103
106
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -108,10 +111,10 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
108
111
  def action(container_id, action_code, payload={})
109
112
  url, params = "", {}
110
113
  if container_id.is_a?(Array)
111
- url = "#{@base_url}/api/containers/action"
114
+ url = "#{base_path}/action"
112
115
  params = {ids: container_id, code: action_code}
113
116
  else
114
- url = "#{@base_url}/api/containers/#{container_id}/action"
117
+ url = "#{base_path}/#{container_id}/action"
115
118
  params = {code: action_code}
116
119
  end
117
120
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -119,4 +122,14 @@ class Morpheus::ContainersInterface < Morpheus::APIClient
119
122
  execute(opts)
120
123
  end
121
124
 
125
+ def import(container_id, payload={}, headers={})
126
+ validate_id!(container_id)
127
+ execute(method: :put, url: "#{base_path}/#{container_id}/import", payload: payload, headers: headers)
128
+ end
129
+
130
+ def clone_image(container_id, payload={}, headers={})
131
+ validate_id!(container_id)
132
+ execute(method: :put, url: "#{base_path}/#{container_id}/clone-image", payload: payload, headers: headers)
133
+ end
134
+
122
135
  end
@@ -73,7 +73,6 @@ class Morpheus::CustomInstanceTypesInterface < Morpheus::APIClient
73
73
  def destroy_version(instance_type_id, id)
74
74
  url = "#{@base_url}/api/custom-instance-types/#{instance_type_id}/versions/#{id}"
75
75
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}
76
- payload = options
77
76
  execute(method: :delete, url: url, headers: headers)
78
77
  end
79
78
 
@@ -94,7 +93,6 @@ class Morpheus::CustomInstanceTypesInterface < Morpheus::APIClient
94
93
  def destroy_upgrade(instance_type_id, id)
95
94
  url = "#{@base_url}/api/custom-instance-types/#{instance_type_id}/upgrades/#{id}"
96
95
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json'}
97
- payload = options
98
96
  execute(method: :delete, url: url, headers: headers)
99
97
  end
100
98
 
@@ -13,9 +13,8 @@ class Morpheus::DocInterface < Morpheus::APIClient
13
13
  execute(method: :get, url: url, headers: headers)
14
14
  end
15
15
 
16
- def swagger(params={})
17
- url = "/api/doc/swagger"
18
- # prefer /swagger.yml instead of /swagger?format=yml
16
+ def openapi(params={})
17
+ url = "/api/doc/openapi"
19
18
  fmt = params.delete('format')
20
19
  if fmt
21
20
  url = url + "." + fmt
@@ -25,10 +24,11 @@ class Morpheus::DocInterface < Morpheus::APIClient
25
24
  execute(method: :get, url: url, headers: headers, timeout: 172800, parse_json: !is_yaml)
26
25
  end
27
26
 
28
- def download_swagger(outfile, params={})
27
+ alias :swagger :openapi
28
+
29
+ def download_openapi(outfile, params={})
29
30
  # note that RestClient.execute still requires the full path with base_url
30
- url = "#{@base_url}/api/doc/swagger"
31
- # prefer /swagger.yml instead of /swagger?format=yml
31
+ url = "#{@base_url}/api/doc/openapi"
32
32
  fmt = params.delete('format')
33
33
  if fmt
34
34
  url = url + "." + fmt
@@ -54,4 +54,6 @@ class Morpheus::DocInterface < Morpheus::APIClient
54
54
  http_response
55
55
  end
56
56
 
57
+ alias :swagger :download_openapi
58
+
57
59
  end
@@ -42,7 +42,7 @@ class Morpheus::FileCopyRequestInterface < Morpheus::APIClient
42
42
  headers = { params: params, authorization: "Bearer #{@access_token}" }
43
43
  opts = {method: :get, url: url, headers: headers}
44
44
  # execute(opts, {parse_json: false})
45
- if Dir.exists?(outfile)
45
+ if Dir.exist?(outfile)
46
46
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
47
47
  end
48
48
  # if @verify_ssl == false
@@ -68,7 +68,7 @@ class Morpheus::HealthInterface < Morpheus::APIClient
68
68
  headers = { params: params, authorization: "Bearer #{@access_token}" }
69
69
  opts = {method: :get, url: url, headers: headers}
70
70
  # execute(opts, {parse_json: false})
71
- if Dir.exists?(outfile)
71
+ if Dir.exist?(outfile)
72
72
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
73
73
  end
74
74
  # if @verify_ssl == false
@@ -1,7 +1,7 @@
1
1
  require 'morpheus/api/api_client'
2
- require 'morpheus/api/image_builder_image_builds_interface'
3
- require 'morpheus/api/image_builder_preseed_scripts_interface'
4
- require 'morpheus/api/image_builder_boot_scripts_interface'
2
+ # require 'morpheus/api/image_builder_image_builds_interface'
3
+ # require 'morpheus/api/image_builder_preseed_scripts_interface'
4
+ # require 'morpheus/api/image_builder_boot_scripts_interface'
5
5
 
6
6
  class Morpheus::ImageBuilderInterface < Morpheus::APIClient
7
7
 
@@ -318,6 +318,31 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
318
318
  execute(opts)
319
319
  end
320
320
 
321
+ def list_schedules(id, params={}, headers={})
322
+ validate_id!(id)
323
+ execute(method: :get, url: "#{base_path}/#{id}/schedules", params: params, headers: headers)
324
+ end
325
+
326
+ def get_schedule(id, schedule_id, params={}, headers={})
327
+ validate_id!(id) && validate_id!(schedule_id, 'schedule_id')
328
+ execute(method: :get, url: "#{base_path}/#{id}/schedules/#{schedule_id}", params: params, headers: headers)
329
+ end
330
+
331
+ def create_schedule(id, payload, params={}, headers={})
332
+ validate_id!(id)
333
+ execute(method: :post, url: "#{base_path}/#{id}/schedules", params: params, payload: payload, headers: headers)
334
+ end
335
+
336
+ def update_schedule(id, schedule_id, payload, params={}, headers={})
337
+ validate_id!(id) && validate_id!(schedule_id, 'schedule_id')
338
+ execute(method: :put, url: "#{base_path}/#{id}/schedules/#{schedule_id}", params: params, payload: payload, headers: headers)
339
+ end
340
+
341
+ def destroy_schedule(id, schedule_id, params = {}, headers={})
342
+ validate_id!(id) && validate_id!(schedule_id, 'schedule_id')
343
+ execute(method: :delete, url: "#{base_path}/#{id}/schedules/#{schedule_id}", params: params, headers: headers)
344
+ end
345
+
321
346
  def update_load_balancer(id, payload)
322
347
  url = "#{@base_url}/api/instances/#{id}/load-balancer"
323
348
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -4,7 +4,6 @@ class Morpheus::LogsInterface < Morpheus::APIClient
4
4
 
5
5
  def list(params={})
6
6
  url = "#{@base_url}/api/logs"
7
- # old versions expected containers[]
8
7
  headers = { params: params, authorization: "Bearer #{@access_token}" }
9
8
  execute({method: :get, url: url, headers: headers})
10
9
  end
@@ -12,14 +11,13 @@ class Morpheus::LogsInterface < Morpheus::APIClient
12
11
  def container_logs(containers=[], params={})
13
12
  url = "#{@base_url}/api/logs"
14
13
  # old versions expected containers[]
15
- headers = { params: {'containers' => containers, 'containers[]' => containers}.merge(params), authorization: "Bearer #{@access_token}" }
14
+ headers = { params: {'containers' => containers}.merge(params), authorization: "Bearer #{@access_token}" }
16
15
  execute({method: :get, url: url, headers: headers})
17
16
  end
18
17
 
19
18
  def server_logs(servers=[], params={})
20
19
  url = "#{@base_url}/api/logs"
21
- # old versions expected containers[]
22
- headers = { params: {'servers' => servers, 'servers[]' => servers}.merge(params), authorization: "Bearer #{@access_token}" }
20
+ headers = { params: {'servers' => servers}.merge(params), authorization: "Bearer #{@access_token}" }
23
21
  execute({method: :get, url: url, headers: headers})
24
22
  end
25
23
 
@@ -1,10 +1,10 @@
1
1
  require 'morpheus/api/api_client'
2
- require 'morpheus/api/monitoring_checks_interface'
3
- require 'morpheus/api/monitoring_groups_interface'
4
- require 'morpheus/api/monitoring_apps_interface'
5
- require 'morpheus/api/monitoring_incidents_interface'
6
- require 'morpheus/api/monitoring_contacts_interface'
7
- require 'morpheus/api/monitoring_alerts_interface'
2
+ # require 'morpheus/api/monitoring_checks_interface'
3
+ # require 'morpheus/api/monitoring_groups_interface'
4
+ # require 'morpheus/api/monitoring_apps_interface'
5
+ # require 'morpheus/api/monitoring_incidents_interface'
6
+ # require 'morpheus/api/monitoring_contacts_interface'
7
+ # require 'morpheus/api/monitoring_alerts_interface'
8
8
 
9
9
  class Morpheus::MonitoringInterface < Morpheus::APIClient
10
10
 
@@ -79,7 +79,7 @@ class Morpheus::PackagesInterface < Morpheus::APIClient
79
79
  headers = { params: params, authorization: "Bearer #{@access_token}" }
80
80
  opts = {method: :post, url: url, headers: headers}
81
81
  # execute(opts, {parse_json: false})
82
- if Dir.exists?(outfile)
82
+ if Dir.exist?(outfile)
83
83
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
84
84
  end
85
85
  # if @verify_ssl == false
@@ -44,7 +44,7 @@ class Morpheus::ReportsInterface < Morpheus::APIClient
44
44
  headers = { params: params, authorization: "Bearer #{@access_token}" }
45
45
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
46
46
  # execute(opts, {parse_json: false})
47
- if Dir.exists?(outfile)
47
+ if Dir.exist?(outfile)
48
48
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
49
49
  end
50
50
  # if @verify_ssl == false
@@ -55,6 +55,14 @@ class Morpheus::ServersInterface < Morpheus::APIClient
55
55
  execute(opts)
56
56
  end
57
57
 
58
+ def restart(serverId,payload = {}, params = {})
59
+ url = "#{@base_url}/api/servers/#{serverId}/restart"
60
+
61
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
62
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
63
+ execute(opts)
64
+ end
65
+
58
66
  def make_managed(serverId,payload = {})
59
67
  url = "#{@base_url}/api/servers/#{serverId}/install-agent"
60
68
  #url = "#{@base_url}/api/servers/#{serverId}/make-managed" # added in 4.1
@@ -176,7 +184,7 @@ class Morpheus::ServersInterface < Morpheus::APIClient
176
184
  execute(opts)
177
185
  end
178
186
 
179
- def update_network_label(network_id, server_id, payload)
187
+ def update_network_label(network_id, server_id, payload)
180
188
  url = "#{@base_url}/api/servers/#{server_id}/networkInterfaces/#{network_id}"
181
189
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
182
190
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
@@ -96,7 +96,7 @@ class Morpheus::StorageProvidersInterface < Morpheus::APIClient
96
96
  headers = { params: params, authorization: "Bearer #{@access_token}" }
97
97
  opts = {method: :get, url: url, headers: headers}
98
98
  # execute(opts, false)
99
- if Dir.exists?(outfile)
99
+ if Dir.exist?(outfile)
100
100
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
101
101
  end
102
102
  # if @verify_ssl == false
@@ -125,7 +125,7 @@ class Morpheus::StorageProvidersInterface < Morpheus::APIClient
125
125
  headers = { params: params, authorization: "Bearer #{@access_token}" }
126
126
  opts = {method: :get, url: url, headers: headers}
127
127
  # execute(opts, false)
128
- if Dir.exists?(outfile)
128
+ if Dir.exist?(outfile)
129
129
  raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
130
130
  end
131
131
  # if @verify_ssl == false
@@ -81,7 +81,7 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
81
81
  # opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
82
82
  end
83
83
 
84
- start_time = Time.now
84
+ # start_time = Time.now
85
85
  query_params = headers.delete(:params) || {}
86
86
  file_size = image_file.size
87
87
  if File.blockdev?(image_file)
data/lib/morpheus/api.rb CHANGED
@@ -7,4 +7,6 @@ require 'morpheus/formatters'
7
7
 
8
8
  # load interfaces
9
9
  require 'morpheus/api/api_client.rb'
10
+ require 'morpheus/api/rest_interface.rb'
11
+ require 'morpheus/api/read_interface.rb'
10
12
  Dir[File.dirname(__FILE__) + "/api/**/*.rb"].each {|file| require file }
@@ -145,7 +145,7 @@ module Morpheus::Benchmarking
145
145
 
146
146
  # finish the current benchmark and optionally print the time taken.
147
147
  def stop_benchmark(exit_code=0, err=nil)
148
- if @benchmark_record
148
+ if defined?(@benchmark_record) && @benchmark_record
149
149
  @benchmark_record.stop(exit_code, err)
150
150
  @last_benchmark_record = @benchmark_record
151
151
  @benchmark_record = nil