morpheus-cli 5.5.2.1 → 5.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Dockerfile +1 -1
- data/README.md +57 -4
- data/Rakefile +9 -0
- data/bin/morpheus +4 -4
- data/lib/morpheus/api/api_client.rb +8 -2
- data/lib/morpheus/api/archive_buckets_interface.rb +1 -1
- data/lib/morpheus/api/archive_files_interface.rb +3 -3
- data/lib/morpheus/api/clients_interface.rb +2 -2
- data/lib/morpheus/api/clusters_interface.rb +8 -1
- data/lib/morpheus/api/containers_interface.rb +29 -16
- data/lib/morpheus/api/custom_instance_types_interface.rb +0 -2
- data/lib/morpheus/api/doc_interface.rb +8 -6
- data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
- data/lib/morpheus/api/health_interface.rb +1 -1
- data/lib/morpheus/api/image_builder_interface.rb +3 -3
- data/lib/morpheus/api/instances_interface.rb +25 -0
- data/lib/morpheus/api/logs_interface.rb +2 -4
- data/lib/morpheus/api/monitoring_interface.rb +6 -6
- data/lib/morpheus/api/packages_interface.rb +1 -1
- data/lib/morpheus/api/reports_interface.rb +1 -1
- data/lib/morpheus/api/servers_interface.rb +9 -1
- data/lib/morpheus/api/storage_providers_interface.rb +2 -2
- data/lib/morpheus/api/virtual_images_interface.rb +1 -1
- data/lib/morpheus/api.rb +2 -0
- data/lib/morpheus/benchmarking.rb +1 -1
- data/lib/morpheus/cli/cli_command.rb +69 -36
- data/lib/morpheus/cli/cli_registry.rb +19 -10
- data/lib/morpheus/cli/commands/access_token_command.rb +1 -1
- data/lib/morpheus/cli/commands/apps.rb +1 -1
- data/lib/morpheus/cli/commands/archives_command.rb +25 -33
- data/lib/morpheus/cli/commands/blueprints_command.rb +10 -21
- data/lib/morpheus/cli/commands/boot_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/cat_command.rb +1 -1
- data/lib/morpheus/cli/commands/catalog_item_types_command.rb +12 -12
- data/lib/morpheus/cli/commands/clouds.rb +3 -3
- data/lib/morpheus/cli/commands/clusters.rb +154 -3
- data/lib/morpheus/cli/commands/containers_command.rb +398 -253
- data/lib/morpheus/cli/commands/deployments.rb +1 -1
- data/lib/morpheus/cli/commands/deploys.rb +9 -9
- data/lib/morpheus/cli/commands/doc.rb +15 -16
- data/lib/morpheus/cli/commands/execution_request_command.rb +2 -2
- data/lib/morpheus/cli/commands/file_copy_request_command.rb +5 -5
- data/lib/morpheus/cli/commands/groups.rb +2 -2
- data/lib/morpheus/cli/commands/health_command.rb +4 -4
- data/lib/morpheus/cli/commands/hosts.rb +43 -5
- data/lib/morpheus/cli/commands/image_builder_command.rb +1 -1
- data/lib/morpheus/cli/commands/instances.rb +419 -148
- data/lib/morpheus/cli/commands/integrations_command.rb +22 -20
- data/lib/morpheus/cli/commands/key_pairs.rb +2 -2
- data/lib/morpheus/cli/commands/library_container_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/library_container_templates_command.rb +2 -2
- data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -3
- data/lib/morpheus/cli/commands/library_spec_templates_command.rb +2 -2
- data/lib/morpheus/cli/commands/login.rb +1 -1
- data/lib/morpheus/cli/commands/man_command.rb +32 -18
- data/lib/morpheus/cli/commands/packages_command.rb +11 -11
- data/lib/morpheus/cli/commands/plugins.rb +1 -1
- data/lib/morpheus/cli/commands/policies_command.rb +4 -4
- data/lib/morpheus/cli/commands/preseed_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/remote.rb +1 -1
- data/lib/morpheus/cli/commands/reports_command.rb +3 -3
- data/lib/morpheus/cli/commands/roles.rb +6 -3
- data/lib/morpheus/cli/commands/security_groups.rb +1 -1
- data/lib/morpheus/cli/commands/shell.rb +40 -62
- data/lib/morpheus/cli/commands/snapshots.rb +3 -5
- data/lib/morpheus/cli/commands/source_command.rb +8 -16
- data/lib/morpheus/cli/commands/storage_providers_command.rb +7 -7
- data/lib/morpheus/cli/commands/tasks.rb +2 -2
- data/lib/morpheus/cli/commands/vdi_pools_command.rb +6 -6
- data/lib/morpheus/cli/commands/view.rb +5 -1
- data/lib/morpheus/cli/commands/whitelabel_settings_command.rb +4 -4
- data/lib/morpheus/cli/commands/whoami.rb +2 -2
- data/lib/morpheus/cli/credentials.rb +30 -8
- data/lib/morpheus/cli/dot_file.rb +8 -15
- data/lib/morpheus/cli/error_handler.rb +16 -0
- data/lib/morpheus/cli/errors.rb +8 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +17 -13
- data/lib/morpheus/cli/mixins/rest_command.rb +18 -18
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +12 -12
- data/lib/morpheus/cli/option_parser.rb +5 -1
- data/lib/morpheus/cli/option_types.rb +59 -12
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli.rb +26 -16
- data/lib/morpheus/ext/rest_client.rb +3 -2
- data/lib/morpheus/formatters.rb +1 -1
- data/lib/morpheus/logging.rb +4 -4
- data/lib/morpheus/morpkg.rb +4 -4
- data/lib/morpheus/rest_client.rb +2 -2
- data/lib/morpheus/routes.rb +2 -2
- data/lib/morpheus/terminal.rb +65 -16
- data/lib/morpheus.rb +1 -1
- data/morpheus-cli.gemspec +1 -0
- data/test/api/containers_interface_test.rb +68 -0
- data/test/api/doc_interface_test.rb +35 -0
- data/test/api/instances_interface_test.rb +22 -0
- data/test/api/whoami_interface_test.rb +14 -0
- data/test/cli/access_token_test.rb +36 -0
- data/test/cli/auth_test.rb +82 -0
- data/test/cli/cli_test.rb +48 -0
- data/test/cli/containers_test.rb +92 -0
- data/test/cli/doc_test.rb +35 -0
- data/test/cli/help_test.rb +25 -0
- data/test/cli/instances_test.rb +36 -0
- data/test/cli/man_test.rb +14 -0
- data/test/cli/remote_test.rb +89 -0
- data/test/cli/roles_test.rb +34 -0
- data/test/cli/shell_test.rb +81 -0
- data/test/cli/version_test.rb +23 -0
- data/test/cli/view_test.rb +55 -0
- data/test/cli/whoami_test.rb +17 -0
- data/test/morpheus_test.rb +16 -0
- data/test/test_case.rb +338 -0
- data/test/test_config.rb +137 -0
- data/test/test_data_helper.rb +97 -0
- metadata +61 -3
|
@@ -760,7 +760,7 @@ EOT
|
|
|
760
760
|
options[:config_file] = val.to_s
|
|
761
761
|
file_content = nil
|
|
762
762
|
full_filename = File.expand_path(options[:config_file])
|
|
763
|
-
if File.
|
|
763
|
+
if File.exist?(full_filename)
|
|
764
764
|
file_content = File.read(full_filename)
|
|
765
765
|
else
|
|
766
766
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -770,7 +770,7 @@ EOT
|
|
|
770
770
|
config_map = parse_result[:data]
|
|
771
771
|
if config_map.nil?
|
|
772
772
|
# todo: bubble up JSON.parse error message
|
|
773
|
-
raise_command_error "Failed to parse config as YAML or JSON. Error: #{parse_result[:
|
|
773
|
+
raise_command_error "Failed to parse config as YAML or JSON. Error: #{parse_result[:error]}"
|
|
774
774
|
#raise_command_error "Failed to parse config as valid YAML or JSON."
|
|
775
775
|
else
|
|
776
776
|
params['config'] = config_map
|
|
@@ -813,7 +813,7 @@ EOT
|
|
|
813
813
|
# config_map = parse_result[:data]
|
|
814
814
|
# if config_map.nil?
|
|
815
815
|
# # todo: bubble up JSON.parse error message
|
|
816
|
-
# raise_command_error "Failed to parse config as YAML or JSON. Error: #{parse_result[:
|
|
816
|
+
# raise_command_error "Failed to parse config as YAML or JSON. Error: #{parse_result[:error]}"
|
|
817
817
|
# #raise_command_error "Failed to parse config as valid YAML or JSON."
|
|
818
818
|
# else
|
|
819
819
|
# params['config'] = config_map
|
|
@@ -1065,26 +1065,28 @@ EOT
|
|
|
1065
1065
|
return 1, "integration inventory not found for #{args[1]}" if integration_inventory.nil?
|
|
1066
1066
|
# construct payload
|
|
1067
1067
|
object_key = integration_inventory_object_key
|
|
1068
|
-
payload =
|
|
1069
|
-
if
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
val.
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1068
|
+
payload = parse_payload(options, object_key)
|
|
1069
|
+
if payload.nil?
|
|
1070
|
+
if options[:tenants]
|
|
1071
|
+
#params['tenants'] = options[:tenants]
|
|
1072
|
+
params['tenants'] = options[:tenants].collect do |val|
|
|
1073
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
|
1074
|
+
val.to_i
|
|
1075
|
+
else
|
|
1076
|
+
# todo: use /api/options/allTenants to avoid permission errors here..
|
|
1077
|
+
record = find_by_name_or_id(:account, val)
|
|
1078
|
+
if record.nil?
|
|
1079
|
+
exit 1 #return 1, "Tenant not found by '#{val}'"
|
|
1080
|
+
else
|
|
1081
|
+
record['id']
|
|
1082
|
+
end
|
|
1081
1083
|
end
|
|
1082
1084
|
end
|
|
1083
1085
|
end
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1086
|
+
payload.deep_merge!({object_key => params})
|
|
1087
|
+
if payload.empty? || payload[object_key].empty?
|
|
1088
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
1089
|
+
end
|
|
1088
1090
|
end
|
|
1089
1091
|
# make request
|
|
1090
1092
|
@integrations_interface.setopts(options)
|
|
@@ -146,7 +146,7 @@ class Morpheus::Cli::KeyPairs
|
|
|
146
146
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
147
147
|
opts.banner = subcommand_usage("[name] [options]")
|
|
148
148
|
opts.on('', '--public-key-file FILENAME', "Public Key File" ) do |filename|
|
|
149
|
-
if File.
|
|
149
|
+
if File.exist?(File.expand_path(filename))
|
|
150
150
|
options['publicKey'] = File.read(File.expand_path(filename))
|
|
151
151
|
options[:options] ||= {}
|
|
152
152
|
options[:options]['publicKey'] = options['publicKey']
|
|
@@ -163,7 +163,7 @@ class Morpheus::Cli::KeyPairs
|
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
opts.on('', '--private-key-file FILENAME', "Private Key File" ) do |filename|
|
|
166
|
-
if File.
|
|
166
|
+
if File.exist?(File.expand_path(filename))
|
|
167
167
|
options['privateKey'] = File.read(File.expand_path(filename))
|
|
168
168
|
options[:options] ||= {}
|
|
169
169
|
options[:options]['privateKey'] = options['privateKey']
|
|
@@ -172,7 +172,7 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
|
|
|
172
172
|
end
|
|
173
173
|
opts.on('--file FILE', "File containing the script. This can be used instead of --script" ) do |filename|
|
|
174
174
|
full_filename = File.expand_path(filename)
|
|
175
|
-
if File.
|
|
175
|
+
if File.exist?(full_filename)
|
|
176
176
|
params['script'] = File.read(full_filename)
|
|
177
177
|
else
|
|
178
178
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -266,7 +266,7 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
|
|
|
266
266
|
end
|
|
267
267
|
opts.on('--file FILE', "File containing the script. This can be used instead of --script" ) do |filename|
|
|
268
268
|
full_filename = File.expand_path(filename)
|
|
269
|
-
if File.
|
|
269
|
+
if File.exist?(full_filename)
|
|
270
270
|
params['script'] = File.read(full_filename)
|
|
271
271
|
else
|
|
272
272
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -195,7 +195,7 @@ class Morpheus::Cli::LibraryContainerTemplatesCommand
|
|
|
195
195
|
end
|
|
196
196
|
opts.on('--file FILE', "File containing the template. This can be used instead of --template" ) do |filename|
|
|
197
197
|
full_filename = File.expand_path(filename)
|
|
198
|
-
if File.
|
|
198
|
+
if File.exist?(full_filename)
|
|
199
199
|
params['template'] = File.read(full_filename)
|
|
200
200
|
else
|
|
201
201
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -312,7 +312,7 @@ class Morpheus::Cli::LibraryContainerTemplatesCommand
|
|
|
312
312
|
end
|
|
313
313
|
opts.on('--file FILE', "File containing the template. This can be used instead of --template" ) do |filename|
|
|
314
314
|
full_filename = File.expand_path(filename)
|
|
315
|
-
if File.
|
|
315
|
+
if File.exist?(full_filename)
|
|
316
316
|
params['template'] = File.read(full_filename)
|
|
317
317
|
else
|
|
318
318
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -306,7 +306,7 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
|
|
|
306
306
|
params.deep_merge!(v_prompt)
|
|
307
307
|
if params['logo']
|
|
308
308
|
filename = File.expand_path(params['logo'])
|
|
309
|
-
if !File.
|
|
309
|
+
if !File.exist?(filename)
|
|
310
310
|
print_red_alert "File not found: #{filename}"
|
|
311
311
|
exit 1
|
|
312
312
|
end
|
|
@@ -523,7 +523,7 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
|
|
|
523
523
|
logo_file = 'null' # clear it
|
|
524
524
|
else
|
|
525
525
|
filename = File.expand_path(filename)
|
|
526
|
-
if !File.
|
|
526
|
+
if !File.exist?(filename)
|
|
527
527
|
print_red_alert "File not found: #{filename}"
|
|
528
528
|
exit 1
|
|
529
529
|
end
|
|
@@ -571,7 +571,7 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
|
|
|
571
571
|
dark_logo_file = 'null' # clear it
|
|
572
572
|
else
|
|
573
573
|
filename = File.expand_path(filename)
|
|
574
|
-
if !File.
|
|
574
|
+
if !File.exist?(filename)
|
|
575
575
|
print_red_alert "File not found: #{filename}"
|
|
576
576
|
exit 1
|
|
577
577
|
end
|
|
@@ -207,7 +207,7 @@ class Morpheus::Cli::LibrarySpecTemplatesCommand
|
|
|
207
207
|
opts.on('--file FILE', "File containing the template. This can be used instead of --content" ) do |filename|
|
|
208
208
|
file_params['sourceType'] = 'local' if file_params['sourceType'].nil?
|
|
209
209
|
full_filename = File.expand_path(filename)
|
|
210
|
-
if File.
|
|
210
|
+
if File.exist?(full_filename)
|
|
211
211
|
file_params['content'] = File.read(full_filename)
|
|
212
212
|
else
|
|
213
213
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -363,7 +363,7 @@ class Morpheus::Cli::LibrarySpecTemplatesCommand
|
|
|
363
363
|
opts.on('--file FILE', "File containing the template. This can be used instead of --content" ) do |filename|
|
|
364
364
|
file_params['sourceType'] = 'local' if file_params['sourceType'].nil?
|
|
365
365
|
full_filename = File.expand_path(filename)
|
|
366
|
-
if File.
|
|
366
|
+
if File.exist?(full_filename)
|
|
367
367
|
file_params['content'] = File.read(full_filename)
|
|
368
368
|
else
|
|
369
369
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -33,7 +33,7 @@ class Morpheus::Cli::Login
|
|
|
33
33
|
end
|
|
34
34
|
opts.on( '--password-file FILE', String, "Password File, read a file containing the password." ) do |val|
|
|
35
35
|
password_file = File.expand_path(val)
|
|
36
|
-
if !File.
|
|
36
|
+
if !File.exist?(password_file) || !File.file?(password_file) # check readable too
|
|
37
37
|
raise ::OptionParser::InvalidOption.new("File not found: #{password_file}")
|
|
38
38
|
end
|
|
39
39
|
password = File.read(password_file) #.to_s.split("\n").first.strip
|
|
@@ -8,12 +8,24 @@ class Morpheus::Cli::ManCommand
|
|
|
8
8
|
# this should be read only anyway...
|
|
9
9
|
@@default_editor = "less" # ENV['EDITOR']
|
|
10
10
|
|
|
11
|
+
def self.man_file_path
|
|
12
|
+
File.join(Morpheus::Cli.home_directory, "CLI-Manual-#{Morpheus::Cli::VERSION}.md")
|
|
13
|
+
end
|
|
14
|
+
|
|
11
15
|
def handle(args)
|
|
12
16
|
options = {}
|
|
13
17
|
regenerate = false
|
|
14
|
-
editor = @@default_editor
|
|
15
18
|
open_as_link = false # true please
|
|
16
19
|
goto_wiki = false
|
|
20
|
+
editor = @@default_editor
|
|
21
|
+
#todo: windows
|
|
22
|
+
if !$stdin.tty?
|
|
23
|
+
editor = "cat"
|
|
24
|
+
end
|
|
25
|
+
# no editor for windows atm
|
|
26
|
+
if Morpheus::Cli.windows?
|
|
27
|
+
open_as_link = true
|
|
28
|
+
end
|
|
17
29
|
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
|
18
30
|
opts.banner = "Usage: morpheus man"
|
|
19
31
|
opts.on('-w','--wiki', "Open the morpheus-cli wiki instead of the local man page") do
|
|
@@ -81,16 +93,16 @@ EOT
|
|
|
81
93
|
print_error "#{red}It is the name of an existing directory.#{reset}\n"
|
|
82
94
|
return 1
|
|
83
95
|
end
|
|
84
|
-
if File.
|
|
96
|
+
if File.exist?(fn) && options[:overwrite] != true
|
|
85
97
|
print_error "#{red}Output file '#{fn}' already exists.#{reset}\n"
|
|
86
98
|
print_error "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
|
87
99
|
return 1
|
|
88
100
|
end
|
|
89
101
|
end
|
|
90
102
|
exit_code, err = 0, nil
|
|
91
|
-
if regenerate || !File.
|
|
103
|
+
if regenerate || !File.exist?(fn)
|
|
92
104
|
#Morpheus::Logging::DarkPrinter.puts "generating manual #{fn} ..." if Morpheus::Logging.debug? && !options[:quiet]
|
|
93
|
-
exit_code, err =
|
|
105
|
+
exit_code, err = generate_manual(options)
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
if options[:quiet]
|
|
@@ -99,7 +111,7 @@ EOT
|
|
|
99
111
|
|
|
100
112
|
Morpheus::Logging::DarkPrinter.puts "opening manual file #{fn}" if Morpheus::Logging.debug? && !options[:quiet]
|
|
101
113
|
|
|
102
|
-
if open_as_link #
|
|
114
|
+
if open_as_link # windows only atm
|
|
103
115
|
link = "file://#{fn}"
|
|
104
116
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
|
105
117
|
system "start #{link}"
|
|
@@ -142,13 +154,9 @@ EOT
|
|
|
142
154
|
return has_it
|
|
143
155
|
end
|
|
144
156
|
|
|
145
|
-
def self.man_file_path
|
|
146
|
-
File.join(Morpheus::Cli.home_directory, "CLI-Manual-#{Morpheus::Cli::VERSION}.md")
|
|
147
|
-
end
|
|
148
|
-
|
|
149
157
|
# def self.save_manual(fn, content)
|
|
150
|
-
# # fn = man_file_path
|
|
151
|
-
# if !Dir.
|
|
158
|
+
# # fn = Morpheus::Cli::ManCommand.man_file_path
|
|
159
|
+
# if !Dir.exist?(File.dirname(fn))
|
|
152
160
|
# FileUtils.mkdir_p(File.dirname(fn))
|
|
153
161
|
# end
|
|
154
162
|
# Morpheus::Logging::DarkPrinter.puts "saving manual to #{fn}" if Morpheus::Logging.debug?
|
|
@@ -156,19 +164,19 @@ EOT
|
|
|
156
164
|
# FileUtils.chmod(0600, fn)
|
|
157
165
|
# end
|
|
158
166
|
|
|
159
|
-
def
|
|
167
|
+
def generate_manual(options={})
|
|
160
168
|
# todo: use pandoc or something else to convert the CLI-Manual.md to a man page
|
|
161
169
|
# and install it, so the os command `man morpheus` will work too.
|
|
162
|
-
fn = man_file_path
|
|
170
|
+
fn = Morpheus::Cli::ManCommand.man_file_path
|
|
163
171
|
if options[:outfile]
|
|
164
172
|
fn = File.expand_path(options[:outfile])
|
|
165
|
-
if File.
|
|
173
|
+
if File.exist?(fn) && options[:overwrite] != true
|
|
166
174
|
print_error "#{red}Output file '#{options[:outfile]}' already exists.#{reset}\n"
|
|
167
175
|
print_error "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
|
168
176
|
return 1, "output file already exists"
|
|
169
177
|
end
|
|
170
178
|
end
|
|
171
|
-
if !Dir.
|
|
179
|
+
if !Dir.exist?(File.dirname(fn))
|
|
172
180
|
FileUtils.mkdir_p(File.dirname(fn))
|
|
173
181
|
end
|
|
174
182
|
Morpheus::Logging::DarkPrinter.puts "generating manual #{fn}" if Morpheus::Logging.debug? && !options[:quiet]
|
|
@@ -202,7 +210,7 @@ EOT
|
|
|
202
210
|
|
|
203
211
|
Use the command `#{prog_name} remote add` to connect to your Morpheus appliance.
|
|
204
212
|
|
|
205
|
-
To learn more, visit https://
|
|
213
|
+
To learn more, visit https://clidocs.morpheusdata.com
|
|
206
214
|
|
|
207
215
|
To learn more about the Morpheus Appliance, visit https://www.morpheusdata.com
|
|
208
216
|
|
|
@@ -254,7 +262,11 @@ EOT
|
|
|
254
262
|
The available commands and their options are documented below.
|
|
255
263
|
ENDTEXT
|
|
256
264
|
|
|
257
|
-
|
|
265
|
+
|
|
266
|
+
#terminal = Morpheus::Terminal.new($stdin, manpage)
|
|
267
|
+
terminal = my_terminal
|
|
268
|
+
terminal.with_stdout(manpage) do
|
|
269
|
+
|
|
258
270
|
Morpheus::Logging::DarkPrinter.puts "appending command help `#{prog_name} --help`" if Morpheus::Logging.debug? && !options[:quiet]
|
|
259
271
|
|
|
260
272
|
manpage.print "\n"
|
|
@@ -406,12 +418,14 @@ echo
|
|
|
406
418
|
```
|
|
407
419
|
|
|
408
420
|
ENDTEXT
|
|
421
|
+
|
|
422
|
+
end # end with_stdout(manpage)
|
|
409
423
|
|
|
410
424
|
ensure
|
|
411
425
|
manpage.close if manpage
|
|
412
426
|
# $stdout = previous_stdout if previous_stdout
|
|
413
427
|
# this is needed to re-establish instance with STDOUT, STDIN
|
|
414
|
-
terminal = Morpheus::Terminal.new()
|
|
428
|
+
#terminal = Morpheus::Terminal.new()
|
|
415
429
|
end
|
|
416
430
|
|
|
417
431
|
return 0, nil
|
|
@@ -386,7 +386,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
386
386
|
puts_error "bad argument: [morpkg-file]\nFile '#{local_file_path}' is invalid.\n#{optparse}"
|
|
387
387
|
return 1
|
|
388
388
|
end
|
|
389
|
-
if !File.
|
|
389
|
+
if !File.exist?(local_file_path)
|
|
390
390
|
print_error Morpheus::Terminal.angry_prompt
|
|
391
391
|
puts_error "bad argument: [morpkg-file]\nFile '#{local_file_path}' was not found.\n"
|
|
392
392
|
return 1
|
|
@@ -545,7 +545,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
545
545
|
end
|
|
546
546
|
end
|
|
547
547
|
outfile = File.expand_path(outfile)
|
|
548
|
-
if Dir.
|
|
548
|
+
if Dir.exist?(outfile)
|
|
549
549
|
puts_error "#{Morpheus::Terminal.angry_prompt}--file is invalid. It is the name of an existing directory: #{outfile}"
|
|
550
550
|
return 1
|
|
551
551
|
end
|
|
@@ -554,7 +554,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
554
554
|
outfile << ".morpkg"
|
|
555
555
|
end
|
|
556
556
|
destination_dir = File.dirname(outfile)
|
|
557
|
-
if !Dir.
|
|
557
|
+
if !Dir.exist?(destination_dir)
|
|
558
558
|
if do_mkdir
|
|
559
559
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
560
560
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -563,7 +563,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
563
563
|
return 1
|
|
564
564
|
end
|
|
565
565
|
end
|
|
566
|
-
if File.
|
|
566
|
+
if File.exist?(outfile)
|
|
567
567
|
if do_overwrite
|
|
568
568
|
# uhh need to be careful wih the passed filepath here..
|
|
569
569
|
# don't delete, just overwrite.
|
|
@@ -598,7 +598,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
598
598
|
|
|
599
599
|
if do_unzip
|
|
600
600
|
package_dir = File.join(File.dirname(outfile), File.basename(outfile).sub(/\.morpkg\Z/, ''))
|
|
601
|
-
if File.
|
|
601
|
+
if File.exist?(package_dir)
|
|
602
602
|
print cyan,"Deleting existing directory #{package_dir}",reset,"\n"
|
|
603
603
|
FileUtils.rm_rf(package_dir)
|
|
604
604
|
end
|
|
@@ -619,7 +619,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
619
619
|
#response_body = (http_response.body.kind_of?(Net::ReadAdapter) ? "" : http_response.body)
|
|
620
620
|
end
|
|
621
621
|
# F it, just remove a bad result
|
|
622
|
-
if File.
|
|
622
|
+
if File.exist?(outfile) && File.file?(outfile)
|
|
623
623
|
Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
|
|
624
624
|
File.delete(outfile)
|
|
625
625
|
end
|
|
@@ -687,7 +687,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
687
687
|
begin
|
|
688
688
|
# validate source
|
|
689
689
|
source_directory = File.expand_path(source_directory)
|
|
690
|
-
if !File.
|
|
690
|
+
if !File.exist?(source_directory)
|
|
691
691
|
puts_error "#{Morpheus::Terminal.angry_prompt}[source] is invalid. Directory not found: #{source_directory}"
|
|
692
692
|
return 1
|
|
693
693
|
end
|
|
@@ -718,7 +718,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
718
718
|
else
|
|
719
719
|
outfile = File.expand_path(outfile)
|
|
720
720
|
end
|
|
721
|
-
if Dir.
|
|
721
|
+
if Dir.exist?(outfile)
|
|
722
722
|
puts_error "#{Morpheus::Terminal.angry_prompt}[target] is invalid. It is the name of an existing directory: #{outfile}"
|
|
723
723
|
return 1
|
|
724
724
|
end
|
|
@@ -727,7 +727,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
727
727
|
outfile << ".morpkg"
|
|
728
728
|
end
|
|
729
729
|
destination_dir = File.dirname(outfile)
|
|
730
|
-
if !Dir.
|
|
730
|
+
if !Dir.exist?(destination_dir)
|
|
731
731
|
if do_mkdir
|
|
732
732
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
733
733
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -736,7 +736,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
736
736
|
return 1
|
|
737
737
|
end
|
|
738
738
|
end
|
|
739
|
-
if File.
|
|
739
|
+
if File.exist?(outfile)
|
|
740
740
|
if do_overwrite
|
|
741
741
|
# uhh need to be careful wih the passed filepath here..
|
|
742
742
|
# don't delete, just overwrite.
|
|
@@ -783,7 +783,7 @@ class Morpheus::Cli::PackagesCommand
|
|
|
783
783
|
end
|
|
784
784
|
end
|
|
785
785
|
# F it, just remove a bad result
|
|
786
|
-
# if File.
|
|
786
|
+
# if File.exist?(outfile) && File.file?(outfile)
|
|
787
787
|
# Morpheus::Logging::DarkPrinter.puts "Deleting bad build file: #{outfile}" if Morpheus::Logging.debug?
|
|
788
788
|
# File.delete(outfile)
|
|
789
789
|
# end
|
|
@@ -30,7 +30,7 @@ EOT
|
|
|
30
30
|
connect(options)
|
|
31
31
|
filename = args[0]
|
|
32
32
|
filename = File.expand_path(filename)
|
|
33
|
-
if !File.
|
|
33
|
+
if !File.exist?(filename)
|
|
34
34
|
raise_command_error "File not found: #{filename}"
|
|
35
35
|
elsif !File.file?(filename)
|
|
36
36
|
raise_command_error "File is a directory: #{filename}"
|
|
@@ -334,7 +334,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
|
334
334
|
options['eachUser'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s.empty?
|
|
335
335
|
end
|
|
336
336
|
|
|
337
|
-
opts.on('-t', '--type ID', "Policy Type Name or ID") do |val|
|
|
337
|
+
opts.on('-t', '--type ID', "Policy Type Name, Code or ID") do |val|
|
|
338
338
|
options['type'] = val
|
|
339
339
|
end
|
|
340
340
|
opts.on('--name VALUE', String, "Name for this policy") do |val|
|
|
@@ -417,7 +417,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
|
417
417
|
print_red_alert "No available policy types found!"
|
|
418
418
|
return 1
|
|
419
419
|
end
|
|
420
|
-
policy_types_dropdown = available_policy_types.collect {|it| {'name' => it['name'], 'value' => it['id']} }
|
|
420
|
+
policy_types_dropdown = available_policy_types.collect {|it| {'name' => it['name'], 'value' => it['code'], 'id' => it['id']} }
|
|
421
421
|
policy_type_id = nil
|
|
422
422
|
policy_type = nil
|
|
423
423
|
if options['type']
|
|
@@ -497,7 +497,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
|
497
497
|
payload['policy']['config'] = options['config']
|
|
498
498
|
elsif options['configFile']
|
|
499
499
|
config_file = File.expand_path(options['configFile'])
|
|
500
|
-
if !File.
|
|
500
|
+
if !File.exist?(config_file) || !File.file?(config_file)
|
|
501
501
|
print_red_alert "File not found: #{config_file}"
|
|
502
502
|
return false
|
|
503
503
|
end
|
|
@@ -637,7 +637,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
|
637
637
|
payload['policy']['config'] = options['config']
|
|
638
638
|
elsif options['configFile']
|
|
639
639
|
config_file = File.expand_path(options['configFile'])
|
|
640
|
-
if !File.
|
|
640
|
+
if !File.exist?(config_file) || !File.file?(config_file)
|
|
641
641
|
print_red_alert "File not found: #{config_file}"
|
|
642
642
|
return false
|
|
643
643
|
end
|
|
@@ -172,7 +172,7 @@ class Morpheus::Cli::PreseedScriptsCommand
|
|
|
172
172
|
params = Morpheus::Cli::OptionTypes.prompt(my_options, options[:options], @api_client, options[:params])
|
|
173
173
|
script_file = params.delete('file')
|
|
174
174
|
if script_file
|
|
175
|
-
if !File.
|
|
175
|
+
if !File.exist?(script_file)
|
|
176
176
|
print_red_alert "File not found: #{script_file}"
|
|
177
177
|
return 1
|
|
178
178
|
end
|
|
@@ -243,7 +243,7 @@ class Morpheus::Cli::PreseedScriptsCommand
|
|
|
243
243
|
# params = Morpheus::Cli::OptionTypes.prompt(my_options, options[:options], @api_client, options[:params])
|
|
244
244
|
script_file = params.delete('file')
|
|
245
245
|
if script_file
|
|
246
|
-
if !File.
|
|
246
|
+
if !File.exist?(script_file)
|
|
247
247
|
print_red_alert "File not found: #{script_file}"
|
|
248
248
|
return 1
|
|
249
249
|
end
|
|
@@ -1512,7 +1512,7 @@ EOT
|
|
|
1512
1512
|
|
|
1513
1513
|
def save_appliances(new_config)
|
|
1514
1514
|
fn = appliances_file_path
|
|
1515
|
-
if !Dir.
|
|
1515
|
+
if !Dir.exist?(File.dirname(fn))
|
|
1516
1516
|
FileUtils.mkdir_p(File.dirname(fn))
|
|
1517
1517
|
end
|
|
1518
1518
|
File.open(fn, 'w') {|f| f.write new_config.to_yaml } #Store
|
|
@@ -396,12 +396,12 @@ class Morpheus::Cli::ReportsCommand
|
|
|
396
396
|
report_format = "csv"
|
|
397
397
|
end
|
|
398
398
|
|
|
399
|
-
if Dir.
|
|
399
|
+
if Dir.exist?(outfile)
|
|
400
400
|
print_red_alert "[file] is invalid. It is the name of an existing directory: #{outfile}"
|
|
401
401
|
return 1
|
|
402
402
|
end
|
|
403
403
|
destination_dir = File.dirname(outfile)
|
|
404
|
-
if !Dir.
|
|
404
|
+
if !Dir.exist?(destination_dir)
|
|
405
405
|
if do_mkdir
|
|
406
406
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
407
407
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -410,7 +410,7 @@ class Morpheus::Cli::ReportsCommand
|
|
|
410
410
|
return 1
|
|
411
411
|
end
|
|
412
412
|
end
|
|
413
|
-
if File.
|
|
413
|
+
if File.exist?(outfile)
|
|
414
414
|
if do_overwrite
|
|
415
415
|
# uhh need to be careful wih the passed filepath here..
|
|
416
416
|
# don't delete, just overwrite.
|
|
@@ -500,7 +500,9 @@ EOT
|
|
|
500
500
|
permission_label = -> (s) {s.split('-').collect{|s| s.capitalize}.join(' ') + ' Permissions'}
|
|
501
501
|
|
|
502
502
|
if category.nil?
|
|
503
|
-
permissions = available_categories.
|
|
503
|
+
permissions = available_categories.reject{|category| role[permission_name.call(category)].nil?}.collect{|category|
|
|
504
|
+
role[permission_name.call(category)].map{|perm| perm.merge({'category' => permission_label.call(category)})}
|
|
505
|
+
}.flatten
|
|
504
506
|
else
|
|
505
507
|
permissions = role[permission_name.call(category)]
|
|
506
508
|
end
|
|
@@ -517,11 +519,12 @@ EOT
|
|
|
517
519
|
end
|
|
518
520
|
|
|
519
521
|
print cyan
|
|
520
|
-
print_h1 "Role: [#{role['role']['id']}
|
|
522
|
+
print_h1 "Role: [#{role['role']['id']}#{(role['role']['owner'].nil? ? ']' : ", #{role['role']['owner']['name']}]")} #{role['role']['authority']}", options
|
|
521
523
|
|
|
522
524
|
(category.nil? ? available_categories : [category]).each do |category|
|
|
523
|
-
print_h2 "#{permission_label.call(category)}", options
|
|
524
525
|
permissions = role[permission_name.call(category)]
|
|
526
|
+
next if permissions.nil?
|
|
527
|
+
print_h2 "#{permission_label.call(category)}", options
|
|
525
528
|
if permissions.size > 0
|
|
526
529
|
rows = permissions.collect do |it|
|
|
527
530
|
{
|
|
@@ -1156,7 +1156,7 @@ class Morpheus::Cli::SecurityGroups
|
|
|
1156
1156
|
|
|
1157
1157
|
def self.save_security_group(new_config)
|
|
1158
1158
|
fn = security_group_file_path
|
|
1159
|
-
if !Dir.
|
|
1159
|
+
if !Dir.exist?(File.dirname(fn))
|
|
1160
1160
|
FileUtils.mkdir_p(File.dirname(fn))
|
|
1161
1161
|
end
|
|
1162
1162
|
File.open(fn, 'w') {|f| f.write new_config.to_yaml } #Store
|