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
@@ -0,0 +1,35 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::Doc
4
+ class MorpheusTest::DocTest < MorpheusTest::TestCase
5
+
6
+ def test_doc_list
7
+ assert_execute("doc list")
8
+ end
9
+
10
+ def test_doc_get
11
+ # using --quiet because the output is massive
12
+ assert_execute("doc get --quiet")
13
+ end
14
+
15
+ def test_doc_get_yaml
16
+ # using --quiet because the output is massive
17
+ assert_execute("doc get --yaml --quiet")
18
+ end
19
+
20
+ # def test_doc_download
21
+ # assert_execute("doc download '/path/to/openapi.json')
22
+ # end
23
+
24
+ # def test_doc_download_yaml
25
+ # assert_execute("doc download '/path/to/openapi.yaml' --yaml")
26
+ # end
27
+
28
+ def test_doc_get_unauthorized
29
+ # authentication is NOT required for this api
30
+ without_authentication do
31
+ assert_success("doc get -q")
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for help command and global --help option
4
+ class MorpheusTest::HelpTest < MorpheusTest::TestCase
5
+
6
+ def requires_authentication
7
+ false
8
+ end
9
+
10
+ def test_help
11
+ assert_execute %(help)
12
+ assert_execute %(-h)
13
+ assert_execute %(--help)
14
+ end
15
+
16
+ def test_subcommand_help
17
+ assert_execute %(remote --help)
18
+ assert_execute %(remote -h)
19
+ assert_execute %(remote use --help)
20
+ assert_execute %(instances list --help)
21
+ assert_execute %(whoami --help)
22
+ assert_execute %(whoami -h)
23
+ end
24
+
25
+ end
@@ -0,0 +1,36 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::Instances
4
+ class MorpheusTest::InstancesTest < MorpheusTest::TestCase
5
+
6
+ def test_instances_list
7
+ assert_execute %(instances list)
8
+ end
9
+
10
+ def test_instances_get
11
+ instance = client.instances.list({})['instances'][0]
12
+ if instance
13
+ assert_execute %(instances get "#{instance['id']}")
14
+ assert_execute %(instances get "#{escape_arg instance['name']}")
15
+ else
16
+ puts "No instance found, unable to execute test `#{__method__}`"
17
+ end
18
+ end
19
+
20
+ # def test_instances_add
21
+ # warn "Skipped test test_instances_add() because it is not implemented"
22
+ # end
23
+
24
+ # def test_instances_update
25
+ # warn "Skipped test test_instances_update() because it is not implemented"
26
+ # end
27
+
28
+ # def test_instances_delete
29
+ # warn "Skipped test test_instances_remove() because it is not implemented"
30
+ # end
31
+
32
+ # todo: many more instance commands to add
33
+
34
+ protected
35
+
36
+ end
@@ -0,0 +1,14 @@
1
+ require 'morpheus_test'
2
+
3
+ class MorpheusTest::ManTest < MorpheusTest::TestCase
4
+
5
+ def test_man
6
+ # need to use -q to avoid interactive right now...
7
+ assert_execute("man -q")
8
+ assert_execute("man -g -q")
9
+ assert_execute("man -q")
10
+ man_file_path = Morpheus::Cli::ManCommand.man_file_path
11
+ assert(File.exist?(man_file_path), "File #{man_file_path} should have been created.")
12
+ end
13
+
14
+ end
@@ -0,0 +1,89 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::Remote
4
+ class MorpheusTest::RemoteTest < MorpheusTest::TestCase
5
+
6
+ def requires_remote
7
+ false
8
+ end
9
+
10
+ def requires_authentication
11
+ false
12
+ end
13
+
14
+ def setup
15
+ super()
16
+ @@test_remote_name ||= "test_remote_#{SecureRandom.hex(10)}"
17
+ end
18
+
19
+ def teardown
20
+ # switch back aftwards
21
+ assert_execute %(remote use "#{escape_arg @config.remote_name}")
22
+ end
23
+
24
+ def test_remote_add
25
+ assert_execute %(remote add "#{@@test_remote_name}" "#{escape_arg @config.url}" --insecure --use -N)
26
+ end
27
+
28
+ def test_remote_list
29
+ assert_execute %(remote list)
30
+ assert_execute %(remote list "#{@@test_remote_name}")
31
+ end
32
+
33
+ def test_remote_get
34
+ assert_execute %(remote get)
35
+ assert_execute %(remote get current)
36
+ assert_execute %(remote get "#{@@test_remote_name}")
37
+ assert_execute %(remote get "#{@@test_remote_name}" --offline)
38
+ end
39
+
40
+ def test_remote_current
41
+ assert_execute %(remote current)
42
+ end
43
+
44
+ def test_remote_version
45
+ assert_execute %(remote version)
46
+ #assert_execute %(remote version "#{@@test_remote_name}")
47
+ end
48
+
49
+ def test_remote_check
50
+ assert_execute %(remote check)
51
+ assert_execute %(remote check "#{@@test_remote_name}")
52
+ end
53
+
54
+ def test_remote_check_all
55
+ assert_execute %(remote check-all)
56
+ end
57
+
58
+ def test_remote_update
59
+ assert_execute %(remote update "#{@@test_remote_name}" --url "#{escape_arg @config.url}" --insecure)
60
+ #assert_execute %(remote update "#{@@test_remote_name}" --name "#{@@test_remote_name}_updated")
61
+ #assert_execute %(remote update "#{@@test_remote_name}_updated" --name "#{@@test_remote_name}")
62
+ end
63
+
64
+ def test_remote_rename
65
+ assert_execute %(remote rename "#{@@test_remote_name}" "#{@@test_remote_name}_renamed" -y)
66
+ assert_execute %(remote rename "#{@@test_remote_name}_renamed" "#{@@test_remote_name}" -y)
67
+ end
68
+
69
+ def test_remote_use
70
+ assert_error %(remote use)
71
+ assert_error %(remote use unknown_remote)
72
+ assert_execute %(remote use "#{@@test_remote_name}")
73
+ assert_execute %(remote use "#{@@test_remote_name}")
74
+ assert_execute %(remote get current)
75
+ assert_execute %(remote unuse)
76
+ assert_error %(remote get current)
77
+ assert_execute %(remote use "#{@@test_remote_name}" -q)
78
+ end
79
+
80
+ def test_remote_remove
81
+ # test remove confirmation reploy of n or no
82
+ with_input(["n", "No"]) do
83
+ assert_error %(remote remove "#{@@test_remote_name}")
84
+ assert_error %(remote remove "#{@@test_remote_name}")
85
+ end
86
+ assert_execute %(remote remove "#{@@test_remote_name}" -y)
87
+ end
88
+
89
+ end
@@ -0,0 +1,34 @@
1
+ require 'morpheus_test'
2
+
3
+ class MorpheusTest::RolesTest < MorpheusTest::TestCase
4
+
5
+ def test_roles_list
6
+ assert_execute %(roles list)
7
+ assert_execute %(roles list "System Admin")
8
+ end
9
+
10
+ def test_roles_get
11
+ assert_execute %(roles get "System Admin")
12
+ assert_execute %(roles get "System Admin" --permissions)
13
+ end
14
+
15
+ def test_roles_list_permissions
16
+ assert_execute %(roles list-permissions "System Admin")
17
+ end
18
+
19
+ # todo: test all the other commands
20
+
21
+ # def test_roles_add
22
+ # assert_execute %(roles add "test_role_#{random_id}" -N)
23
+ # end
24
+
25
+ # def test_roles_update
26
+ # #skip "Test needs to be added"
27
+ # assert_execute %(roles update "test_role_#{random_id}" --description "neat")
28
+ # end
29
+
30
+ # def test_roles_remove
31
+ # assert_execute %(roles remove "test_role_#{random_id}" -y")
32
+ # end
33
+
34
+ end
@@ -0,0 +1,81 @@
1
+ require 'morpheus_test'
2
+
3
+ class MorpheusTest::ShellTest < MorpheusTest::TestCase
4
+
5
+ def requires_remote
6
+ false
7
+ end
8
+
9
+ def requires_authentication
10
+ false
11
+ end
12
+
13
+ # class << self
14
+ # def startup
15
+ # # one time use remote and login at beginning of testsuite, not each method
16
+ # use_remote()
17
+ # login()
18
+ # end
19
+ # end
20
+
21
+ # def test_remote_use
22
+ # # use remote needed for all except test_shell_clean() , todo: exclude paradigm that yet..
23
+ # use_remote()
24
+ # end
25
+
26
+ def test_shell
27
+ with_input "exit" do
28
+ assert_execute "shell"
29
+ end
30
+ end
31
+
32
+ def test_shell_verbose
33
+ login_if_needed()
34
+ with_input "whoami", "exit" do
35
+ assert_execute "shell -V"
36
+ end
37
+ end
38
+
39
+ def test_shell_history
40
+ with_input "history", "exit" do
41
+ assert_execute "shell"
42
+ end
43
+ end
44
+
45
+ def test_shell_sleep
46
+ with_input "echo \"It is time for a rest.\"", "sleep 0.5", "echo \"OK, let's keep testing\"", "exit" do
47
+ assert_execute "shell -V"
48
+ end
49
+ end
50
+
51
+ def test_shell_temporary
52
+ with_input "remote list", "remote current", "echo this is a temporary shell with no history", "history", "exit" do
53
+ assert_execute "shell -Z -V"
54
+ end
55
+ end
56
+
57
+ def test_shell_confirmation
58
+ with_input "access-token refresh", "I'm not sure...", "no", "exit" do
59
+ assert_execute "shell -Z -V"
60
+ end
61
+ end
62
+
63
+ # todo: fix bug where appliances are not restored after clean shell.. so remote use #{@config.remote_name}" starts failing here..
64
+ =begin
65
+ def test_shell_clean
66
+ with_input "echo this is a clean shell with no remotes or history", "remote list", "remote current", "history", "exit" do
67
+ assert_execute "shell -z"
68
+ end
69
+ with_input "echo this is another clean shell", "exit" do
70
+ assert_execute "shell --clean"
71
+ end
72
+ end
73
+
74
+ def test_shell_history_again
75
+ with_input "echo back in test shell again with our remote and history", "remote get #{@config.remote_name}", "history", "exit" do
76
+ assert_execute "shell"
77
+ end
78
+ end
79
+ =end
80
+
81
+ end
@@ -0,0 +1,23 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::VersionCommand
4
+ class MorpheusTest::VersionTest < MorpheusTest::TestCase
5
+
6
+ def requires_authentication
7
+ false
8
+ end
9
+
10
+ def test_version
11
+ assert_execute %(version)
12
+ end
13
+
14
+ def test_version_short
15
+ assert_execute %(version -v)
16
+ assert_execute %(version --short)
17
+ end
18
+
19
+ # def test_version_help
20
+ # assert_execute %(version --help)
21
+ # end
22
+
23
+ end
@@ -0,0 +1,55 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::View class, corresponds to the `view` CLI command
4
+ class MorpheusTest::ViewTest < MorpheusTest::TestCase
5
+
6
+ def teardown
7
+ # todo: close browser after each test
8
+ end
9
+
10
+ # these all pass but it's kind of obnoxious to open so many tabs
11
+
12
+ =begin
13
+ def test_view
14
+ assert_execute %(view)
15
+ end
16
+
17
+ def test_view_login
18
+ assert_execute %(view --login)
19
+ #puts "pausing a moment while logging in with browser"
20
+ #sleep(3)
21
+
22
+ end
23
+
24
+ def test_view_login_short
25
+ assert_execute %(view -l)
26
+ #puts "pausing a moment while logging in with browser"
27
+ #sleep(3)
28
+ end
29
+
30
+ def test_view_clouds
31
+ assert_execute %(view clouds)
32
+ end
33
+
34
+ def test_view_cloud_by_id
35
+ cloud = client.clouds.list({})['zones'][0]
36
+ if cloud
37
+ assert_execute %(view cloud "#{escape_arg cloud['id']}")
38
+ else
39
+ puts "No cloud found, unable to execute test `#{__method__}`"
40
+ end
41
+ end
42
+
43
+ def test_view_instance_by_name
44
+ assert_execute %(view -l)
45
+ instance = client.instances.list({})['instances'][0]
46
+ if instance
47
+ assert_execute %(view instance "#{escape_arg instance['name']}")
48
+ else
49
+ puts "No instance found, unable to execute test `#{__method__}`"
50
+ end
51
+ end
52
+ =end
53
+ protected
54
+
55
+ end
@@ -0,0 +1,17 @@
1
+ require 'morpheus_test'
2
+
3
+ class MorpheusTest::WhoamiTest < MorpheusTest::TestCase
4
+
5
+ def test_whoami
6
+ assert_execute("whoami")
7
+ assert_execute("whoami --name")
8
+ assert_execute("whoami --permissions")
9
+ end
10
+
11
+ def test_whoami_unauthorized
12
+ without_authentication do
13
+ assert_error("whoami", "Expected error while unauthorized")
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'test_case'
3
+ require 'test_data_helper'
4
+
5
+ # setup at_start hook that runs once at the beginning of all tests
6
+ Test::Unit.at_start {
7
+
8
+ }
9
+
10
+ # setup at_exit hook that runs once at the end of all tests
11
+ Test::Unit.at_exit {
12
+ # always logout when all done
13
+ # logout_if_needed()
14
+ # terminal.execute("logout") if is_logged_in()
15
+ Morpheus::Terminal.instance.execute("logout")
16
+ }