morpheus-cli 5.5.2.2 → 5.5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +20 -2
- data/lib/morpheus/api/appliance_settings_interface.rb +15 -0
- 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/cypher_interface.rb +1 -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/guidance_settings_interface.rb +17 -0
- 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/monitoring_settings_interface.rb +25 -0
- data/lib/morpheus/api/network_server_groups_interface.rb +7 -0
- 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 +79 -37
- 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/appliance_settings_command.rb +57 -2
- data/lib/morpheus/cli/commands/apps.rb +1 -1
- data/lib/morpheus/cli/commands/archives_command.rb +25 -33
- data/lib/morpheus/cli/commands/backup_settings_command.rb +1 -1
- 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 +18 -13
- 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/cypher_command.rb +3 -0
- 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/guidance_command.rb +2 -2
- data/lib/morpheus/cli/commands/guidance_settings.rb +148 -0
- 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/log_settings_command.rb +1 -1
- data/lib/morpheus/cli/commands/login.rb +1 -1
- data/lib/morpheus/cli/commands/man_command.rb +32 -18
- data/lib/morpheus/cli/commands/monitoring_settings.rb +228 -0
- data/lib/morpheus/cli/commands/network_server_groups_command.rb +222 -0
- 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/provisioning_settings_command.rb +1 -1
- data/lib/morpheus/cli/commands/remote.rb +1 -1
- data/lib/morpheus/cli/commands/reports_command.rb +13 -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 +5 -5
- 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/provisioning_helper.rb +14 -12
- data/lib/morpheus/cli/mixins/rest_command.rb +23 -19
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +47 -24
- 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/ext/string.rb +6 -4
- 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 +41 -9
- 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 +67 -3
data/lib/morpheus/cli/errors.rb
CHANGED
@@ -14,7 +14,7 @@ module Morpheus::Cli
|
|
14
14
|
|
15
15
|
end
|
16
16
|
|
17
|
-
# An error indicating the command was not
|
17
|
+
# An error indicating the command was not recognized, assigned exit code 127
|
18
18
|
class CommandNotFoundError < CommandError
|
19
19
|
|
20
20
|
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
@@ -40,7 +40,14 @@ module Morpheus::Cli
|
|
40
40
|
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
41
41
|
super(msg, args, optparse, exit_code || 1)
|
42
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# An error indicating the user declined to accept a confirmation prompt, assigned exit code 9
|
46
|
+
class CommandAborted < CommandError
|
43
47
|
|
48
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
49
|
+
super(msg, args, optparse, exit_code || 9)
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
end
|
@@ -144,7 +144,7 @@ module Morpheus::Cli::PrintHelper
|
|
144
144
|
data = {}
|
145
145
|
begin
|
146
146
|
data = JSON.parse(e.response.to_s)
|
147
|
-
rescue
|
147
|
+
rescue
|
148
148
|
# Morpheus::Logging::DarkPrinter.puts "Failed to parse error response as JSON: #{ex}" if Morpheus::Logging.debug?
|
149
149
|
end
|
150
150
|
return data
|
@@ -1329,19 +1329,19 @@ module Morpheus::Cli::PrintHelper
|
|
1329
1329
|
outfile = nil
|
1330
1330
|
begin
|
1331
1331
|
full_filename = File.expand_path(filename)
|
1332
|
-
if File.
|
1332
|
+
if File.exist?(full_filename)
|
1333
1333
|
if !overwrite
|
1334
1334
|
print "#{red}Output file '#{filename}' already exists.#{reset}\n"
|
1335
1335
|
print "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
1336
1336
|
return 1
|
1337
1337
|
end
|
1338
1338
|
end
|
1339
|
-
if Dir.
|
1339
|
+
if Dir.exist?(full_filename)
|
1340
1340
|
print "#{red}Output file '#{filename}' is invalid. It is the name of an existing directory.#{reset}\n"
|
1341
1341
|
return 1
|
1342
1342
|
end
|
1343
1343
|
target_dir = File.dirname(full_filename)
|
1344
|
-
if !Dir.
|
1344
|
+
if !Dir.exist?(target_dir)
|
1345
1345
|
FileUtils.mkdir_p(target_dir)
|
1346
1346
|
end
|
1347
1347
|
outfile = File.open(full_filename, access_mode)
|
@@ -1362,19 +1362,19 @@ module Morpheus::Cli::PrintHelper
|
|
1362
1362
|
outfile = nil
|
1363
1363
|
begin
|
1364
1364
|
full_filename = File.expand_path(filename)
|
1365
|
-
if File.
|
1365
|
+
if File.exist?(full_filename)
|
1366
1366
|
if !overwrite
|
1367
1367
|
print "#{red}Output file '#{filename}' already exists.#{reset}\n"
|
1368
1368
|
print "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
1369
1369
|
return 1
|
1370
1370
|
end
|
1371
1371
|
end
|
1372
|
-
if Dir.
|
1372
|
+
if Dir.exist?(full_filename)
|
1373
1373
|
print "#{red}Output file '#{filename}' is invalid. It is the name of an existing directory.#{reset}\n"
|
1374
1374
|
return 1
|
1375
1375
|
end
|
1376
1376
|
target_dir = File.dirname(full_filename)
|
1377
|
-
if !Dir.
|
1377
|
+
if !Dir.exist?(target_dir)
|
1378
1378
|
FileUtils.mkdir_p(target_dir)
|
1379
1379
|
end
|
1380
1380
|
outfile = File.open(full_filename, access_mode)
|
@@ -1402,13 +1402,17 @@ module Morpheus::Cli::PrintHelper
|
|
1402
1402
|
end
|
1403
1403
|
end
|
1404
1404
|
|
1405
|
-
def format_percent(val, sig_dig=2)
|
1405
|
+
def format_percent(val, sig_dig=2, hide_zero=false)
|
1406
1406
|
if val.nil?
|
1407
1407
|
return ""
|
1408
1408
|
end
|
1409
1409
|
percent_value = val.to_f
|
1410
1410
|
if percent_value == 0
|
1411
|
-
|
1411
|
+
if hide_zero
|
1412
|
+
""
|
1413
|
+
else
|
1414
|
+
return "0%"
|
1415
|
+
end
|
1412
1416
|
else
|
1413
1417
|
return percent_value.round(sig_dig).to_s + "%"
|
1414
1418
|
end
|
@@ -1431,8 +1435,8 @@ module Morpheus::Cli::PrintHelper
|
|
1431
1435
|
|
1432
1436
|
# convert JSON or YAML string to a map
|
1433
1437
|
def parse_json_or_yaml(config, parsers = [:json, :yaml])
|
1434
|
-
rtn = {success: false, data: nil,
|
1435
|
-
|
1438
|
+
rtn = {success: false, data: nil, error: nil}
|
1439
|
+
error = nil
|
1436
1440
|
config = config.strip
|
1437
1441
|
if config[0..2] == "---"
|
1438
1442
|
parsers = [:yaml]
|
@@ -1455,7 +1459,7 @@ module Morpheus::Cli::PrintHelper
|
|
1455
1459
|
rtn[:success] = true
|
1456
1460
|
break
|
1457
1461
|
rescue => ex
|
1458
|
-
rtn[:
|
1462
|
+
rtn[:error] = ex if rtn[:error].nil?
|
1459
1463
|
end
|
1460
1464
|
elsif parser == :json
|
1461
1465
|
begin
|
@@ -1464,7 +1468,7 @@ module Morpheus::Cli::PrintHelper
|
|
1464
1468
|
rtn[:success] = true
|
1465
1469
|
break
|
1466
1470
|
rescue => ex
|
1467
|
-
rtn[:
|
1471
|
+
rtn[:error] = ex if rtn[:error].nil?
|
1468
1472
|
end
|
1469
1473
|
end
|
1470
1474
|
end
|
@@ -1435,7 +1435,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
1435
1435
|
'id' => current_volume['id'].to_i,
|
1436
1436
|
'rootVolume' => false,
|
1437
1437
|
'name' => current_volume['name'],
|
1438
|
-
'size' => current_volume['size']
|
1438
|
+
'size' => current_volume['size'] ? current_volume['size'] : (plan_size || 0),
|
1439
1439
|
'sizeId' => nil,
|
1440
1440
|
'storageType' => (current_volume['type'] || current_volume['storageType']),
|
1441
1441
|
'datastoreId' => current_volume['datastoreId']
|
@@ -2003,9 +2003,10 @@ module Morpheus::Cli::ProvisioningHelper
|
|
2003
2003
|
group_access = nil
|
2004
2004
|
all_plans = nil
|
2005
2005
|
plan_access = nil
|
2006
|
+
permissions = {}
|
2006
2007
|
|
2007
2008
|
# Group Access
|
2008
|
-
|
2009
|
+
unless excludes.include?('groups')
|
2009
2010
|
if !options[:groupAccessAll].nil?
|
2010
2011
|
all_groups = options[:groupAccessAll]
|
2011
2012
|
end
|
@@ -2055,7 +2056,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
2055
2056
|
end
|
2056
2057
|
|
2057
2058
|
# Plan Access
|
2058
|
-
|
2059
|
+
unless excludes.include?('plans')
|
2059
2060
|
if !options[:planAccessAll].nil?
|
2060
2061
|
all_plans = options[:planAccessAll]
|
2061
2062
|
end
|
@@ -2101,13 +2102,14 @@ module Morpheus::Cli::ProvisioningHelper
|
|
2101
2102
|
end
|
2102
2103
|
end
|
2103
2104
|
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2105
|
+
unless excludes.include?('resource')
|
2106
|
+
resource_perms = {}
|
2107
|
+
resource_perms['all'] = all_groups if !all_groups.nil?
|
2108
|
+
resource_perms['sites'] = group_access if !group_access.nil?
|
2109
|
+
resource_perms['allPlans'] = all_plans if !all_plans.nil?
|
2110
|
+
resource_perms['plans'] = plan_access if !plan_access.nil?
|
2111
|
+
permissions['resourcePermissions'] = resource_perms
|
2112
|
+
end
|
2111
2113
|
|
2112
2114
|
available_accounts = get_available_accounts() #.collect {|it| {'name' => it['name'], 'value' => it['id']}}
|
2113
2115
|
accounts = []
|
@@ -2115,7 +2117,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
2115
2117
|
# Prompts for multi tenant
|
2116
2118
|
if available_accounts.count > 1
|
2117
2119
|
visibility = options[:visibility]
|
2118
|
-
|
2120
|
+
unless excludes.include?('visibility')
|
2119
2121
|
if !visibility && !options[:no_prompt]
|
2120
2122
|
visibility = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'visibility', 'fieldLabel' => 'Tenant Permissions Visibility', 'type' => 'select', 'defaultValue' => 'private', 'required' => true, 'selectOptions' => [{'name' => 'Private', 'value' => 'private'},{'name' => 'Public', 'value' => 'public'}]}], options[:options], @api_client, {})['visibility']
|
2121
2123
|
end
|
@@ -2123,7 +2125,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
2123
2125
|
end
|
2124
2126
|
|
2125
2127
|
# Tenants
|
2126
|
-
|
2128
|
+
unless excludes.include?('tenants')
|
2127
2129
|
if !options[:tenants].nil?
|
2128
2130
|
accounts = options[:tenants].collect {|id| id.to_i}
|
2129
2131
|
elsif !options[:no_prompt]
|
@@ -43,7 +43,7 @@ module Morpheus::Cli::RestCommand
|
|
43
43
|
# It is used to derive all other default rest settings key, label, etc.
|
44
44
|
# The default name the command name with underscores `_` instead of dashes `-`.
|
45
45
|
def rest_name
|
46
|
-
@rest_name
|
46
|
+
defined?(@rest_name) ? @rest_name : default_rest_name
|
47
47
|
end
|
48
48
|
|
49
49
|
def default_rest_name
|
@@ -58,7 +58,7 @@ module Morpheus::Cli::RestCommand
|
|
58
58
|
|
59
59
|
# rest_key is the singular name of the resource eg. "neat_thing"
|
60
60
|
def rest_key
|
61
|
-
@rest_key
|
61
|
+
defined?(@rest_key) ? @rest_key : default_rest_key
|
62
62
|
end
|
63
63
|
|
64
64
|
def default_rest_key
|
@@ -73,7 +73,7 @@ module Morpheus::Cli::RestCommand
|
|
73
73
|
|
74
74
|
# rest_arg is a label for the arg in the command usage eg. "thing" gets displayed as [thing]
|
75
75
|
def rest_arg
|
76
|
-
@rest_arg
|
76
|
+
defined?(@rest_arg) ? @rest_arg : default_rest_arg
|
77
77
|
end
|
78
78
|
|
79
79
|
def default_rest_arg
|
@@ -89,7 +89,7 @@ module Morpheus::Cli::RestCommand
|
|
89
89
|
# rest_has_name indicates a resource has a name and can be retrieved by name or id
|
90
90
|
# true by default, set to false for lookups by only id
|
91
91
|
def rest_has_name
|
92
|
-
@rest_has_name
|
92
|
+
defined?(@rest_has_name) ? @rest_has_name : default_rest_has_name
|
93
93
|
end
|
94
94
|
|
95
95
|
def default_rest_has_name
|
@@ -104,7 +104,7 @@ module Morpheus::Cli::RestCommand
|
|
104
104
|
|
105
105
|
# rest_label is the capitalized resource label eg. "Neat Thing"
|
106
106
|
def rest_label
|
107
|
-
@rest_label
|
107
|
+
defined?(@rest_label) ? @rest_label : default_rest_label
|
108
108
|
end
|
109
109
|
|
110
110
|
def default_rest_label
|
@@ -119,7 +119,7 @@ module Morpheus::Cli::RestCommand
|
|
119
119
|
|
120
120
|
# the plural version of the label eg. "Neat Things"
|
121
121
|
def rest_label_plural
|
122
|
-
@rest_label_plural
|
122
|
+
defined?(@rest_label_plural) ? @rest_label_plural : default_rest_label_plural
|
123
123
|
end
|
124
124
|
|
125
125
|
def default_rest_label_plural
|
@@ -135,7 +135,7 @@ module Morpheus::Cli::RestCommand
|
|
135
135
|
|
136
136
|
# rest_interface_name is the interface name for the resource. eg. "neat_things"
|
137
137
|
def rest_interface_name
|
138
|
-
@rest_interface_name
|
138
|
+
defined?(@rest_interface_name) ? @rest_interface_name : default_rest_interface_name
|
139
139
|
end
|
140
140
|
|
141
141
|
def default_rest_interface_name
|
@@ -150,7 +150,7 @@ module Morpheus::Cli::RestCommand
|
|
150
150
|
|
151
151
|
# rest_perms_config enables and configures permissions prompt
|
152
152
|
def rest_perms_config
|
153
|
-
@rest_perms_config
|
153
|
+
defined?(@rest_perms_config) ? @rest_perms_config : {}
|
154
154
|
end
|
155
155
|
|
156
156
|
def rest_perms_config=(v)
|
@@ -161,7 +161,7 @@ module Morpheus::Cli::RestCommand
|
|
161
161
|
|
162
162
|
# rest_option_context_map specifies context mapping during option prompt. default is domain => ''
|
163
163
|
def rest_option_context_map
|
164
|
-
@option_context_map
|
164
|
+
defined?(@option_context_map) ? @option_context_map : {'domain' => ''}
|
165
165
|
end
|
166
166
|
|
167
167
|
def rest_option_context_map=(v)
|
@@ -172,7 +172,7 @@ module Morpheus::Cli::RestCommand
|
|
172
172
|
|
173
173
|
# rest_has_type indicates a resource has a type. default is false
|
174
174
|
def rest_has_type
|
175
|
-
@rest_has_type
|
175
|
+
defined?(@rest_has_type) && @rest_has_type
|
176
176
|
end
|
177
177
|
|
178
178
|
def default_rest_has_type
|
@@ -189,7 +189,7 @@ module Morpheus::Cli::RestCommand
|
|
189
189
|
|
190
190
|
# rest_type_name is the rest_name for the type, only applicable if rest_has_type
|
191
191
|
def rest_type_name
|
192
|
-
@rest_type_name
|
192
|
+
defined?(@rest_type_name) ? @rest_type_name : default_rest_type_name
|
193
193
|
end
|
194
194
|
|
195
195
|
def default_rest_type_name
|
@@ -206,7 +206,7 @@ module Morpheus::Cli::RestCommand
|
|
206
206
|
|
207
207
|
# rest_type_key is the singular name of the resource eg. "neat_thing"
|
208
208
|
def rest_type_key
|
209
|
-
@rest_type_key
|
209
|
+
defined?(@rest_type_key) ? @rest_type_key : default_rest_type_key
|
210
210
|
end
|
211
211
|
|
212
212
|
def default_rest_type_key
|
@@ -220,7 +220,7 @@ module Morpheus::Cli::RestCommand
|
|
220
220
|
alias :set_rest_type_key :rest_type_key=
|
221
221
|
|
222
222
|
def rest_type_arg
|
223
|
-
@rest_type_arg
|
223
|
+
defined?(@rest_type_arg) ? @rest_type_arg : default_rest_type_arg
|
224
224
|
end
|
225
225
|
|
226
226
|
def default_rest_type_arg
|
@@ -236,7 +236,7 @@ module Morpheus::Cli::RestCommand
|
|
236
236
|
|
237
237
|
# rest_type_label is the capitalized resource label eg. "Neat Thing"
|
238
238
|
def rest_type_label
|
239
|
-
@rest_type_label
|
239
|
+
defined?(@rest_type_label) ? @rest_type_label : default_rest_type_label
|
240
240
|
end
|
241
241
|
|
242
242
|
def default_rest_type_label
|
@@ -251,7 +251,7 @@ module Morpheus::Cli::RestCommand
|
|
251
251
|
|
252
252
|
# the plural version of the label eg. "Neat Things"
|
253
253
|
def rest_type_label_plural
|
254
|
-
@rest_type_label_plural
|
254
|
+
defined?(@rest_type_label_plural) ? @rest_type_label_plural : default_rest_type_label_plural
|
255
255
|
end
|
256
256
|
|
257
257
|
def default_rest_type_label_plural
|
@@ -267,7 +267,7 @@ module Morpheus::Cli::RestCommand
|
|
267
267
|
|
268
268
|
# the name of the default interface, matches the rest name eg. "neat_things"
|
269
269
|
def rest_type_interface_name
|
270
|
-
@rest_type_interface_name
|
270
|
+
defined?(@rest_type_interface_name) ? @rest_type_interface_name : default_rest_type_interface_name
|
271
271
|
end
|
272
272
|
|
273
273
|
def default_rest_type_interface_name
|
@@ -720,9 +720,13 @@ EOT
|
|
720
720
|
else
|
721
721
|
perms = prompt_permissions(options.deep_merge(rest_perms_config[:options] || {}), rest_perms_config[:excludes] || [])
|
722
722
|
end
|
723
|
-
|
723
|
+
unless rest_perms_config[:name].nil?
|
724
724
|
perms.transform_keys! {|k| k == 'resourcePermissions' ? rest_perms_config[:name] : k}
|
725
725
|
end
|
726
|
+
unless rest_perms_config[:context].nil?
|
727
|
+
perms_context = {}
|
728
|
+
perms_context[rest_perms_config[:context]] = perms
|
729
|
+
end
|
726
730
|
record_payload.merge!(perms)
|
727
731
|
end
|
728
732
|
payload[rest_object_key] = record_payload
|
@@ -742,7 +746,6 @@ EOT
|
|
742
746
|
end
|
743
747
|
|
744
748
|
def update(args)
|
745
|
-
id = args[0]
|
746
749
|
record_type = nil
|
747
750
|
record_type_id = nil
|
748
751
|
options = {}
|
@@ -762,6 +765,7 @@ EOT
|
|
762
765
|
optparse.parse!(args)
|
763
766
|
verify_args!(args:args, optparse:optparse, count:1)
|
764
767
|
connect(options)
|
768
|
+
id = args[0]
|
765
769
|
record = rest_find_by_name_or_id(id)
|
766
770
|
if record.nil?
|
767
771
|
return 1, "#{rest_name} not found for '#{id}'"
|
@@ -857,7 +861,6 @@ EOT
|
|
857
861
|
end
|
858
862
|
|
859
863
|
def remove(args)
|
860
|
-
id = args[0]
|
861
864
|
params = {}
|
862
865
|
options = {}
|
863
866
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
@@ -872,6 +875,7 @@ EOT
|
|
872
875
|
verify_args!(args:args, optparse:optparse, count:1)
|
873
876
|
connect(options)
|
874
877
|
params.merge!(parse_query_options(options))
|
878
|
+
id = args[0]
|
875
879
|
record = rest_find_by_name_or_id(id)
|
876
880
|
if record.nil?
|
877
881
|
return 1, "#{rest_name} not found for '#{id}'"
|
@@ -33,7 +33,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
33
33
|
|
34
34
|
# rest_parent_name is the rest_name for the parent
|
35
35
|
def rest_parent_name
|
36
|
-
@rest_parent_name
|
36
|
+
defined?(@rest_parent_name) ? @rest_parent_name : default_rest_parent_name
|
37
37
|
end
|
38
38
|
|
39
39
|
def default_rest_parent_name
|
@@ -58,7 +58,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
58
58
|
|
59
59
|
# rest_parent_key is the singular name of the resource eg. "neat_thing"
|
60
60
|
def rest_parent_key
|
61
|
-
@rest_parent_key
|
61
|
+
defined?(@rest_parent_key) ? @rest_parent_key : default_rest_parent_key
|
62
62
|
end
|
63
63
|
|
64
64
|
def default_rest_parent_key
|
@@ -72,7 +72,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
72
72
|
alias :set_rest_parent_key :rest_parent_key=
|
73
73
|
|
74
74
|
def rest_parent_arg
|
75
|
-
@rest_parent_arg
|
75
|
+
defined?(@rest_parent_arg) ? @rest_parent_arg : default_rest_parent_arg
|
76
76
|
end
|
77
77
|
|
78
78
|
def default_rest_parent_arg
|
@@ -86,7 +86,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
86
86
|
alias :set_rest_parent_arg :rest_parent_arg=
|
87
87
|
|
88
88
|
def rest_parent_param
|
89
|
-
@rest_parent_param
|
89
|
+
defined?(@rest_parent_param) ? @rest_parent_param : default_rest_parent_param
|
90
90
|
end
|
91
91
|
|
92
92
|
def default_rest_parent_param
|
@@ -103,7 +103,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
103
103
|
# rest_parent_has_name indicates a resource has a name and can be retrieved by name or id
|
104
104
|
# true by default, set to false for lookups by only id
|
105
105
|
def rest_parent_has_name
|
106
|
-
@rest_parent_has_name
|
106
|
+
defined?(@rest_parent_has_name) ? @rest_parent_has_name : default_rest_parent_has_name
|
107
107
|
end
|
108
108
|
|
109
109
|
def default_rest_parent_has_name
|
@@ -118,7 +118,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
118
118
|
|
119
119
|
# rest_parent_label is the capitalized resource label eg. "Neat Thing"
|
120
120
|
def rest_parent_label
|
121
|
-
@rest_parent_label
|
121
|
+
defined?(@rest_parent_label) ? @rest_parent_label : default_rest_parent_label
|
122
122
|
end
|
123
123
|
|
124
124
|
def default_rest_parent_label
|
@@ -133,7 +133,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
133
133
|
|
134
134
|
# the plural version of the label eg. "Neat Things"
|
135
135
|
def rest_parent_label_plural
|
136
|
-
@rest_parent_label_plural
|
136
|
+
defined?(@rest_parent_label_plural) ? @rest_parent_label_plural : default_rest_parent_label_plural
|
137
137
|
end
|
138
138
|
|
139
139
|
def default_rest_parent_label_plural
|
@@ -149,7 +149,7 @@ module Morpheus::Cli::SecondaryRestCommand
|
|
149
149
|
|
150
150
|
# the name of the default interface, matches the rest name eg. "neat_things"
|
151
151
|
def rest_parent_interface_name
|
152
|
-
@rest_parent_interface_name
|
152
|
+
defined?(@rest_parent_interface_name) ? @rest_parent_interface_name : default_rest_parent_interface_name
|
153
153
|
end
|
154
154
|
|
155
155
|
def default_rest_parent_interface_name
|
@@ -294,7 +294,7 @@ EOT
|
|
294
294
|
if records.nil? || records.empty?
|
295
295
|
print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
|
296
296
|
else
|
297
|
-
print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
|
297
|
+
print as_pretty_table(records, rest_list_column_definitions(options.merge({:parent_record => parent_record})).upcase_keys!, options)
|
298
298
|
print_results_pagination(json_response) if json_response['meta']
|
299
299
|
end
|
300
300
|
print reset,"\n"
|
@@ -318,17 +318,15 @@ EOT
|
|
318
318
|
verify_args!(args:args, optparse:optparse, min:2)
|
319
319
|
connect(options)
|
320
320
|
parse_get_options!(args.count > 1 ? args[1..-1] : [], options, params)
|
321
|
-
|
321
|
+
_get(args[0], args[1..-1].join(" "), params, options)
|
322
|
+
end
|
323
|
+
|
324
|
+
def _get(parent_id, id, params, options)
|
322
325
|
parent_record = rest_parent_find_by_name_or_id(parent_id)
|
323
326
|
if parent_record.nil?
|
324
327
|
return 1, "#{rest_parent_label} not found for '#{parent_id}"
|
325
328
|
end
|
326
329
|
parent_id = parent_record['id']
|
327
|
-
id = args[1..-1].join(" ")
|
328
|
-
_get(parent_id, id, params, options)
|
329
|
-
end
|
330
|
-
|
331
|
-
def _get(parent_id, id, params, options)
|
332
330
|
if id !~ /\A\d{1,}\Z/
|
333
331
|
record = rest_find_by_name_or_id(parent_id, id)
|
334
332
|
if record.nil?
|
@@ -342,7 +340,7 @@ EOT
|
|
342
340
|
return
|
343
341
|
end
|
344
342
|
json_response = rest_interface.get(parent_id, id, params)
|
345
|
-
render_response_for_get(json_response, options)
|
343
|
+
render_response_for_get(json_response, options.merge({:parent_record => parent_record}))
|
346
344
|
return 0, nil
|
347
345
|
end
|
348
346
|
|
@@ -357,14 +355,19 @@ EOT
|
|
357
355
|
print_h2 "Option Types", options
|
358
356
|
print format_option_types_table(record['optionTypes'], options, rest_object_key)
|
359
357
|
end
|
358
|
+
render_response_details_for_get(record, options)
|
360
359
|
print reset,"\n"
|
361
360
|
end
|
362
361
|
end
|
363
362
|
|
363
|
+
def render_response_details_for_get(record, options)
|
364
|
+
# override for custom details
|
365
|
+
end
|
366
|
+
|
364
367
|
def add(args)
|
365
368
|
parent_id, parent_record = nil, nil
|
366
369
|
record_type_id = nil
|
367
|
-
options = {}
|
370
|
+
options = {:options => {:context_map => rest_option_context_map}}
|
368
371
|
option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
|
369
372
|
advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
|
370
373
|
type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
|
@@ -473,7 +476,7 @@ EOT
|
|
473
476
|
end
|
474
477
|
if my_option_types && !my_option_types.empty?
|
475
478
|
# remove redundant fieldContext
|
476
|
-
my_option_types.each do |option_type|
|
479
|
+
my_option_types.each do |option_type|
|
477
480
|
if option_type['fieldContext'] == rest_object_key
|
478
481
|
option_type['fieldContext'] = nil
|
479
482
|
end
|
@@ -491,6 +494,26 @@ EOT
|
|
491
494
|
v_prompt.booleanize! # 'on' => true
|
492
495
|
record_payload.deep_merge!(v_prompt)
|
493
496
|
end
|
497
|
+
if respond_to?("#{rest_key}_add_prompt", true)
|
498
|
+
record_payload = send("#{rest_key}_add_prompt", record_payload, record_type, parent_record, options)
|
499
|
+
end
|
500
|
+
# permissions
|
501
|
+
if rest_perms_config[:enabled]
|
502
|
+
if rest_perms_config[:version] == 2
|
503
|
+
perms = prompt_permissions_v2(options.deep_merge(rest_perms_config[:options] || {}), rest_perms_config[:excludes] || [])
|
504
|
+
else
|
505
|
+
perms = prompt_permissions(options.deep_merge(rest_perms_config[:options] || {}), rest_perms_config[:excludes] || [])
|
506
|
+
end
|
507
|
+
unless rest_perms_config[:name].nil?
|
508
|
+
perms.transform_keys! {|k| k == 'resourcePermissions' ? rest_perms_config[:name] : k}
|
509
|
+
end
|
510
|
+
unless rest_perms_config[:context].nil?
|
511
|
+
perms_context = {}
|
512
|
+
perms_context[rest_perms_config[:context]] = perms
|
513
|
+
perms = perms_context
|
514
|
+
end
|
515
|
+
record_payload.merge!(perms)
|
516
|
+
end
|
494
517
|
payload[rest_object_key] = record_payload
|
495
518
|
end
|
496
519
|
rest_interface.setopts(options)
|
@@ -502,8 +525,8 @@ EOT
|
|
502
525
|
if json_response['success']
|
503
526
|
render_response(json_response, options, rest_object_key) do
|
504
527
|
record = json_response[rest_object_key]
|
505
|
-
print_green_success "Added #{rest_label.downcase} #{record['name'] || record['id']}"
|
506
|
-
return _get(parent_id, record[
|
528
|
+
print_green_success "Added #{rest_label.downcase} #{record.nil? ? json_response['id'] : record['name'] || record['id']}"
|
529
|
+
return _get(parent_id, record.nil? ? json_response['id'] : record['id'], {}, options)
|
507
530
|
end
|
508
531
|
else
|
509
532
|
print red
|
@@ -514,8 +537,6 @@ EOT
|
|
514
537
|
end
|
515
538
|
|
516
539
|
def update(args)
|
517
|
-
parent_id = args[0]
|
518
|
-
id = args[1]
|
519
540
|
record_type = nil
|
520
541
|
record_type_id = nil
|
521
542
|
options = {}
|
@@ -533,6 +554,8 @@ EOT
|
|
533
554
|
optparse.parse!(args)
|
534
555
|
verify_args!(args:args, optparse:optparse, count:2)
|
535
556
|
connect(options)
|
557
|
+
parent_id = args[0]
|
558
|
+
id = args[1]
|
536
559
|
parent_record = rest_parent_find_by_name_or_id(parent_id)
|
537
560
|
if parent_record.nil?
|
538
561
|
return 1, "#{rest_parent_label} not found for '#{parent_id}"
|
@@ -633,8 +656,6 @@ EOT
|
|
633
656
|
end
|
634
657
|
|
635
658
|
def remove(args)
|
636
|
-
parent_id = args[0]
|
637
|
-
id = args[1]
|
638
659
|
params = {}
|
639
660
|
options = {}
|
640
661
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
@@ -649,6 +670,8 @@ EOT
|
|
649
670
|
optparse.parse!(args)
|
650
671
|
verify_args!(args:args, optparse:optparse, count:2)
|
651
672
|
connect(options)
|
673
|
+
parent_id = args[0]
|
674
|
+
id = args[1]
|
652
675
|
parent_record = rest_parent_find_by_name_or_id(parent_id)
|
653
676
|
if parent_record.nil?
|
654
677
|
return 1, "#{rest_parent_label} not found for '#{parent_id}"
|
@@ -43,7 +43,7 @@ module Morpheus
|
|
43
43
|
my_summaries.each do |full_line|
|
44
44
|
opt_description = full_line.to_s.strip
|
45
45
|
if opt_description.start_with?("-")
|
46
|
-
is_hidden = (
|
46
|
+
is_hidden = (hidden_options || []).find { |hidden_switch|
|
47
47
|
if hidden_switch.start_with?("-")
|
48
48
|
opt_description.start_with?("#{hidden_switch} ")
|
49
49
|
else
|
@@ -74,6 +74,10 @@ module Morpheus
|
|
74
74
|
out
|
75
75
|
end
|
76
76
|
|
77
|
+
def hidden_options
|
78
|
+
@hidden_options ||= []
|
79
|
+
end
|
80
|
+
|
77
81
|
def add_hidden_option(opt_name)
|
78
82
|
opt_array = [opt_name].flatten.compact
|
79
83
|
@hidden_options ||= []
|