morpheus-cli 5.3.4 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +14 -1
- data/lib/morpheus/api/health_interface.rb +37 -3
- data/lib/morpheus/api/network_dhcp_relays_interface.rb +36 -0
- data/lib/morpheus/api/network_dhcp_servers_interface.rb +36 -0
- data/lib/morpheus/api/network_edge_clusters_interface.rb +26 -0
- data/lib/morpheus/api/network_servers_interface.rb +68 -12
- data/lib/morpheus/api/roles_interface.rb +7 -0
- data/lib/morpheus/cli/cli_command.rb +7 -8
- data/lib/morpheus/cli/cli_registry.rb +1 -0
- data/lib/morpheus/cli/{access_token_command.rb → commands/access_token_command.rb} +1 -1
- data/lib/morpheus/cli/{account_groups_command.rb → commands/account_groups_command.rb} +0 -8
- data/lib/morpheus/cli/{activity_command.rb → commands/activity_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/alias_command.rb → alias_command.rb} +0 -3
- data/lib/morpheus/cli/{appliance_settings_command.rb → commands/appliance_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{approvals_command.rb → commands/approvals_command.rb} +0 -0
- data/lib/morpheus/cli/{apps.rb → commands/apps.rb} +0 -9
- data/lib/morpheus/cli/{archives_command.rb → commands/archives_command.rb} +0 -6
- data/lib/morpheus/cli/{backup_jobs_command.rb → commands/backup_jobs_command.rb} +0 -0
- data/lib/morpheus/cli/{backup_settings_command.rb → commands/backup_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{backups_command.rb → commands/backups_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/benchmark_command.rb → benchmark_command.rb} +0 -3
- data/lib/morpheus/cli/{blueprints_command.rb → commands/blueprints_command.rb} +0 -0
- data/lib/morpheus/cli/{boot_scripts_command.rb → commands/boot_scripts_command.rb} +0 -3
- data/lib/morpheus/cli/{budgets_command.rb → commands/budgets_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/cat_command.rb → cat_command.rb} +0 -0
- data/lib/morpheus/cli/{catalog_item_types_command.rb → commands/catalog_item_types_command.rb} +0 -0
- data/lib/morpheus/cli/{certificates_command.rb → commands/certificates_command.rb} +0 -0
- data/lib/morpheus/cli/commands/change_password_command.rb +132 -0
- data/lib/morpheus/cli/{cloud_datastores_command.rb → commands/cloud_datastores_command.rb} +0 -4
- data/lib/morpheus/cli/{cloud_folders_command.rb → commands/cloud_folders_command.rb} +0 -4
- data/lib/morpheus/cli/{cloud_resource_pools_command.rb → commands/cloud_resource_pools_command.rb} +0 -4
- data/lib/morpheus/cli/{clouds.rb → commands/clouds.rb} +0 -7
- data/lib/morpheus/cli/{clusters.rb → commands/clusters.rb} +0 -6
- data/lib/morpheus/cli/commands/{standard/coloring_command.rb → coloring_command.rb} +0 -2
- data/lib/morpheus/cli/{containers_command.rb → commands/containers_command.rb} +0 -7
- data/lib/morpheus/cli/commands/{standard/curl_command.rb → curl_command.rb} +0 -3
- data/lib/morpheus/cli/{cypher_command.rb → commands/cypher_command.rb} +0 -1
- data/lib/morpheus/cli/{dashboard_command.rb → commands/dashboard_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/debug_command.rb → debug_command.rb} +0 -1
- data/lib/morpheus/cli/{deploy.rb → commands/deploy.rb} +0 -1
- data/lib/morpheus/cli/{deployments.rb → commands/deployments.rb} +0 -0
- data/lib/morpheus/cli/{deploys.rb → commands/deploys.rb} +0 -1
- data/lib/morpheus/cli/{doc.rb → commands/doc.rb} +1 -1
- data/lib/morpheus/cli/commands/{standard/echo_command.rb → echo_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/edit_profile_command.rb → edit_profile_command.rb} +15 -4
- data/lib/morpheus/cli/commands/{standard/edit_rc_command.rb → edit_rc_command.rb} +19 -3
- data/lib/morpheus/cli/{environments_command.rb → commands/environments_command.rb} +0 -5
- data/lib/morpheus/cli/{execute_schedules_command.rb → commands/execute_schedules_command.rb} +0 -0
- data/lib/morpheus/cli/{execution_request_command.rb → commands/execution_request_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/exit_command.rb → exit_command.rb} +0 -2
- data/lib/morpheus/cli/{file_copy_request_command.rb → commands/file_copy_request_command.rb} +0 -4
- data/lib/morpheus/cli/{forgot_password.rb → commands/forgot_password.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/get_prompt_command.rb → get_prompt_command.rb} +0 -3
- data/lib/morpheus/cli/{groups.rb → commands/groups.rb} +0 -7
- data/lib/morpheus/cli/{guidance_command.rb → commands/guidance_command.rb} +1 -1
- data/lib/morpheus/cli/{health_command.rb → commands/health_command.rb} +104 -19
- data/lib/morpheus/cli/commands/{standard/history_command.rb → history_command.rb} +0 -3
- data/lib/morpheus/cli/{hosts.rb → commands/hosts.rb} +0 -9
- data/lib/morpheus/cli/{image_builder_command.rb → commands/image_builder_command.rb} +2 -8
- data/lib/morpheus/cli/{instance_types.rb → commands/instance_types.rb} +0 -3
- data/lib/morpheus/cli/{instances.rb → commands/instances.rb} +0 -4
- data/lib/morpheus/cli/{integrations_command.rb → commands/integrations_command.rb} +0 -0
- data/lib/morpheus/cli/{invoices_command.rb → commands/invoices_command.rb} +1 -1
- data/lib/morpheus/cli/{jobs_command.rb → commands/jobs_command.rb} +0 -0
- data/lib/morpheus/cli/{key_pairs.rb → commands/key_pairs.rb} +0 -6
- data/lib/morpheus/cli/{library_cluster_layouts_command.rb → commands/library_cluster_layouts_command.rb} +0 -4
- data/lib/morpheus/cli/{library_container_scripts_command.rb → commands/library_container_scripts_command.rb} +0 -0
- data/lib/morpheus/cli/{library_container_templates_command.rb → commands/library_container_templates_command.rb} +0 -1
- data/lib/morpheus/cli/{library_container_types_command.rb → commands/library_container_types_command.rb} +0 -4
- data/lib/morpheus/cli/{library_instance_types_command.rb → commands/library_instance_types_command.rb} +0 -4
- data/lib/morpheus/cli/{library_layouts_command.rb → commands/library_layouts_command.rb} +0 -4
- data/lib/morpheus/cli/{library_option_lists_command.rb → commands/library_option_lists_command.rb} +0 -4
- data/lib/morpheus/cli/{library_option_types_command.rb → commands/library_option_types_command.rb} +0 -4
- data/lib/morpheus/cli/{library_spec_templates_command.rb → commands/library_spec_templates_command.rb} +0 -1
- data/lib/morpheus/cli/{library_upgrades_command.rb → commands/library_upgrades_command.rb} +0 -4
- data/lib/morpheus/cli/{license.rb → commands/license.rb} +0 -3
- data/lib/morpheus/cli/{load_balancer_pools.rb → commands/load_balancer_pools.rb} +0 -0
- data/lib/morpheus/cli/{load_balancer_types.rb → commands/load_balancer_types.rb} +0 -4
- data/lib/morpheus/cli/{load_balancer_virtual_servers.rb → commands/load_balancer_virtual_servers.rb} +0 -0
- data/lib/morpheus/cli/{load_balancers.rb → commands/load_balancers.rb} +0 -1
- data/lib/morpheus/cli/commands/{standard/log_level_command.rb → log_level_command.rb} +0 -3
- data/lib/morpheus/cli/{log_settings_command.rb → commands/log_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{login.rb → commands/login.rb} +0 -5
- data/lib/morpheus/cli/commands/logout.rb +63 -0
- data/lib/morpheus/cli/{logs_command.rb → commands/logs_command.rb} +0 -3
- data/lib/morpheus/cli/commands/{standard/man_command.rb → man_command.rb} +0 -2
- data/lib/morpheus/cli/{monitoring_alerts_command.rb → commands/monitoring_alerts_command.rb} +0 -7
- data/lib/morpheus/cli/{monitoring_apps_command.rb → commands/monitoring_apps_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_checks_command.rb → commands/monitoring_checks_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_contacts_command.rb → commands/monitoring_contacts_command.rb} +0 -7
- data/lib/morpheus/cli/{monitoring_groups_command.rb → commands/monitoring_groups_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_incidents_command.rb → commands/monitoring_incidents_command.rb} +0 -1
- data/lib/morpheus/cli/commands/network_dhcp_relays_command.rb +416 -0
- data/lib/morpheus/cli/commands/network_dhcp_servers_command.rb +407 -0
- data/lib/morpheus/cli/{network_domains_command.rb → commands/network_domains_command.rb} +0 -4
- data/lib/morpheus/cli/commands/network_edge_clusters_command.rb +329 -0
- data/lib/morpheus/cli/commands/network_firewalls_command.rb +806 -0
- data/lib/morpheus/cli/{network_groups_command.rb → commands/network_groups_command.rb} +0 -4
- data/lib/morpheus/cli/{network_pool_servers_command.rb → commands/network_pool_servers_command.rb} +0 -4
- data/lib/morpheus/cli/{network_pools_command.rb → commands/network_pools_command.rb} +0 -4
- data/lib/morpheus/cli/{network_proxies_command.rb → commands/network_proxies_command.rb} +0 -4
- data/lib/morpheus/cli/{network_routers_command.rb → commands/network_routers_command.rb} +0 -5
- data/lib/morpheus/cli/{network_services_command.rb → commands/network_services_command.rb} +0 -4
- data/lib/morpheus/cli/{network_scopes_command.rb → commands/network_transport_zones_command.rb} +102 -92
- data/lib/morpheus/cli/{networks_command.rb → commands/networks_command.rb} +18 -18
- data/lib/morpheus/cli/{packages_command.rb → commands/packages_command.rb} +0 -2
- data/lib/morpheus/cli/{ping.rb → commands/ping.rb} +0 -7
- data/lib/morpheus/cli/{policies_command.rb → commands/policies_command.rb} +0 -7
- data/lib/morpheus/cli/{power_schedules_command.rb → commands/power_schedules_command.rb} +0 -0
- data/lib/morpheus/cli/{preseed_scripts_command.rb → commands/preseed_scripts_command.rb} +0 -3
- data/lib/morpheus/cli/{price_sets_command.rb → commands/price_sets_command.rb} +0 -0
- data/lib/morpheus/cli/{prices_command.rb → commands/prices_command.rb} +0 -0
- data/lib/morpheus/cli/{processes_command.rb → commands/processes_command.rb} +0 -1
- data/lib/morpheus/cli/{projects_command.rb → commands/projects_command.rb} +0 -0
- data/lib/morpheus/cli/{provisioning_licenses_command.rb → commands/provisioning_licenses_command.rb} +0 -0
- data/lib/morpheus/cli/{provisioning_settings_command.rb → commands/provisioning_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{recent_activity_command.rb → commands/recent_activity_command.rb} +0 -0
- data/lib/morpheus/cli/{remote.rb → commands/remote.rb} +1 -7
- data/lib/morpheus/cli/{reports_command.rb → commands/reports_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/rm_command.rb → rm_command.rb} +0 -0
- data/lib/morpheus/cli/{roles.rb → commands/roles.rb} +244 -39
- data/lib/morpheus/cli/{search_command.rb → commands/search_command.rb} +0 -0
- data/lib/morpheus/cli/{security_group_rules.rb → commands/security_group_rules.rb} +0 -5
- data/lib/morpheus/cli/{security_groups.rb → commands/security_groups.rb} +0 -6
- data/lib/morpheus/cli/{service_catalog_command.rb → commands/service_catalog_command.rb} +0 -0
- data/lib/morpheus/cli/{service_plans_command.rb → commands/service_plans_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/set_prompt_command.rb → set_prompt_command.rb} +0 -3
- data/lib/morpheus/cli/{setup.rb → commands/setup.rb} +0 -0
- data/lib/morpheus/cli/{shell.rb → commands/shell.rb} +2 -103
- data/lib/morpheus/cli/commands/{standard/sleep_command.rb → sleep_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/source_command.rb → source_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/ssl_verification_command.rb → ssl_verification_command.rb} +0 -3
- data/lib/morpheus/cli/{storage_providers_command.rb → commands/storage_providers_command.rb} +0 -4
- data/lib/morpheus/cli/{subnets_command.rb → commands/subnets_command.rb} +0 -4
- data/lib/morpheus/cli/{tasks.rb → commands/tasks.rb} +0 -4
- data/lib/morpheus/cli/commands/{standard/tee_command.rb → tee_command.rb} +0 -0
- data/lib/morpheus/cli/{tenants_command.rb → commands/tenants_command.rb} +0 -7
- data/lib/morpheus/cli/commands/{standard/update_command.rb → update_command.rb} +0 -1
- data/lib/morpheus/cli/{usage_command.rb → commands/usage_command.rb} +0 -0
- data/lib/morpheus/cli/{user_groups_command.rb → commands/user_groups_command.rb} +0 -1
- data/lib/morpheus/cli/{user_settings_command.rb → commands/user_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{user_sources_command.rb → commands/user_sources_command.rb} +0 -1
- data/lib/morpheus/cli/{users.rb → commands/users.rb} +0 -7
- data/lib/morpheus/cli/{vdi_allocations_command.rb → commands/vdi_allocations_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_apps_command.rb → commands/vdi_apps_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_command.rb → commands/vdi_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_gateways_command.rb → commands/vdi_gateways_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_pools_command.rb → commands/vdi_pools_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/version_command.rb → version_command.rb} +0 -0
- data/lib/morpheus/cli/{virtual_images.rb → commands/virtual_images.rb} +0 -4
- data/lib/morpheus/cli/{whitelabel_settings_command.rb → commands/whitelabel_settings_command.rb} +0 -1
- data/lib/morpheus/cli/{whoami.rb → commands/whoami.rb} +0 -4
- data/lib/morpheus/cli/{wiki_command.rb → commands/wiki_command.rb} +0 -5
- data/lib/morpheus/cli/{workflows.rb → commands/workflows.rb} +0 -3
- data/lib/morpheus/cli/mixins/logs_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +1 -0
- data/lib/morpheus/cli/mixins/rest_command.rb +103 -17
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +105 -18
- data/lib/morpheus/cli/option_types.rb +56 -19
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli.rb +4 -135
- data/lib/morpheus/terminal.rb +5 -6
- metadata +150 -144
- data/lib/morpheus/cli/change_password_command.rb +0 -147
- data/lib/morpheus/cli/library.rb +0 -1
- data/lib/morpheus/cli/logout.rb +0 -81
File without changes
|
@@ -1,11 +1,4 @@
|
|
1
|
-
# require 'yaml'
|
2
|
-
require 'io/console'
|
3
|
-
require 'rest_client'
|
4
|
-
require 'optparse'
|
5
1
|
require 'morpheus/cli/cli_command'
|
6
|
-
require 'morpheus/cli/option_types'
|
7
|
-
require 'morpheus/cli/mixins/accounts_helper'
|
8
|
-
require 'json'
|
9
2
|
|
10
3
|
class Morpheus::Cli::TenantsCommand
|
11
4
|
include Morpheus::Cli::CliCommand
|
File without changes
|
File without changes
|
@@ -1,11 +1,4 @@
|
|
1
|
-
# require 'yaml'
|
2
|
-
require 'io/console'
|
3
|
-
require 'rest_client'
|
4
|
-
require 'optparse'
|
5
1
|
require 'morpheus/cli/cli_command'
|
6
|
-
require 'morpheus/cli/option_types'
|
7
|
-
require 'morpheus/cli/mixins/accounts_helper'
|
8
|
-
require 'json'
|
9
2
|
|
10
3
|
class Morpheus::Cli::Users
|
11
4
|
include Morpheus::Cli::CliCommand
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -39,7 +39,7 @@ module Morpheus::Cli::RestCommand
|
|
39
39
|
|
40
40
|
module ClassMethods
|
41
41
|
|
42
|
-
# rest_name is the plural name of the
|
42
|
+
# rest_name is the plural name of the resource eg. NeatThings would be "neat_things"
|
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
|
@@ -504,20 +504,22 @@ EOT
|
|
504
504
|
end
|
505
505
|
|
506
506
|
def add(args)
|
507
|
+
record_type = nil
|
507
508
|
record_type_id = nil
|
508
509
|
options = {}
|
509
510
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
511
|
+
opts.banner = subcommand_usage("[#{rest_arg}]")
|
510
512
|
if rest_has_type
|
511
|
-
opts.banner = subcommand_usage("[#{rest_arg}] -t TYPE")
|
512
513
|
opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
|
513
514
|
record_type_id = val
|
514
515
|
end
|
515
|
-
else
|
516
|
-
opts.banner = subcommand_usage("[#{rest_arg}]")
|
517
516
|
end
|
518
|
-
|
519
|
-
|
520
|
-
|
517
|
+
if self.class.method_defined?("add_#{rest_key}_option_types")
|
518
|
+
build_option_type_options(opts, options, self.send("add_#{rest_key}_option_types"))
|
519
|
+
end
|
520
|
+
if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
|
521
|
+
build_option_type_options(opts, options, self.send("add_#{rest_key}_advanced_option_types"))
|
522
|
+
end
|
521
523
|
build_standard_add_options(opts, options)
|
522
524
|
opts.footer = <<-EOT
|
523
525
|
Create a new #{rest_label.downcase}.
|
@@ -532,14 +534,15 @@ EOT
|
|
532
534
|
record_name = args[0]
|
533
535
|
end
|
534
536
|
verify_args!(args:args, optparse:optparse, min:0, max: 1)
|
535
|
-
|
537
|
+
connect(options)
|
538
|
+
# load or prompt for type
|
536
539
|
if rest_has_type
|
537
540
|
if record_type_id.nil?
|
538
|
-
raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
541
|
+
#raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
542
|
+
type_list = rest_type_interface.list({max:10000})[rest_type_list_key]
|
543
|
+
type_dropdown_options = type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
|
544
|
+
record_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => rest_type_label, 'type' => 'select', 'selectOptions' => type_dropdown_options, 'required' => true}], options[:options], @api_client)['type']
|
539
545
|
end
|
540
|
-
end
|
541
|
-
connect(options)
|
542
|
-
if rest_has_type
|
543
546
|
record_type = rest_type_find_by_name_or_id(record_type_id)
|
544
547
|
if record_type.nil?
|
545
548
|
raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
|
@@ -557,11 +560,21 @@ EOT
|
|
557
560
|
options[:options]['name'] = record_name # injected for prompt
|
558
561
|
end
|
559
562
|
if rest_has_type && record_type
|
560
|
-
#
|
563
|
+
# inject type to options for prompting
|
561
564
|
record_payload['type'] = record_type['code']
|
562
|
-
options[:options]['type'] = record_type['code']
|
565
|
+
options[:options]['type'] = record_type['code']
|
566
|
+
# initialize params for loading optionSource data
|
567
|
+
options[:params] ||= {}
|
568
|
+
options[:params]['type'] = record_type['code']
|
563
569
|
end
|
564
570
|
record_payload.deep_merge!(passed_options)
|
571
|
+
if self.class.method_defined?("add_#{rest_key}_option_types")
|
572
|
+
add_option_types = self.send("add_#{rest_key}_option_types")
|
573
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_option_types, options[:options], @api_client, options[:params])
|
574
|
+
v_prompt.deep_compact!
|
575
|
+
v_prompt.booleanize! # 'on' => true
|
576
|
+
record_payload.deep_merge!(v_prompt)
|
577
|
+
end
|
565
578
|
# options by type
|
566
579
|
my_option_types = record_type ? record_type['optionTypes'] : nil
|
567
580
|
if my_option_types && !my_option_types.empty?
|
@@ -576,6 +589,14 @@ EOT
|
|
576
589
|
v_prompt.booleanize! # 'on' => true
|
577
590
|
record_payload.deep_merge!(v_prompt)
|
578
591
|
end
|
592
|
+
# advanced options (uses no_prompt)
|
593
|
+
if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
|
594
|
+
add_advanced_option_types = self.send("add_#{rest_key}_advanced_option_types")
|
595
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(add_advanced_option_types, options[:options], @api_client, options[:params])
|
596
|
+
v_prompt.deep_compact!
|
597
|
+
v_prompt.booleanize! # 'on' => true
|
598
|
+
record_payload.deep_merge!(v_prompt)
|
599
|
+
end
|
579
600
|
payload[rest_object_key] = record_payload
|
580
601
|
end
|
581
602
|
rest_interface.setopts(options)
|
@@ -594,11 +615,17 @@ EOT
|
|
594
615
|
|
595
616
|
def update(args)
|
596
617
|
id = args[0]
|
618
|
+
record_type = nil
|
619
|
+
record_type_id = nil
|
597
620
|
options = {}
|
598
|
-
params = {}
|
599
|
-
account_name = nil
|
600
621
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
601
622
|
opts.banner = subcommand_usage("[#{rest_arg}] [options]")
|
623
|
+
if self.class.method_defined?("update_#{rest_key}_option_types")
|
624
|
+
build_option_type_options(opts, options, self.send("update_#{rest_key}_option_types"))
|
625
|
+
end
|
626
|
+
if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
|
627
|
+
build_option_type_options(opts, options, self.send("update_#{rest_key}_advanced_option_types"))
|
628
|
+
end
|
602
629
|
build_standard_update_options(opts, options)
|
603
630
|
opts.footer = <<-EOT
|
604
631
|
Update an existing #{rest_label.downcase}.
|
@@ -609,13 +636,72 @@ EOT
|
|
609
636
|
verify_args!(args:args, optparse:optparse, count:1)
|
610
637
|
connect(options)
|
611
638
|
record = rest_find_by_name_or_id(id)
|
639
|
+
if record.nil?
|
640
|
+
return 1, "#{rest_name} not found for '#{id}'"
|
641
|
+
end
|
642
|
+
# load type so we can prompt for those option types
|
643
|
+
if rest_has_type
|
644
|
+
record_type_id = record['type']['id']
|
645
|
+
record_type = rest_type_find_by_name_or_id(record_type_id)
|
646
|
+
if record_type.nil?
|
647
|
+
raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
|
648
|
+
end
|
649
|
+
end
|
612
650
|
passed_options = parse_passed_options(options)
|
613
|
-
payload =
|
651
|
+
payload = {}
|
614
652
|
if options[:payload]
|
615
653
|
payload = options[:payload]
|
616
654
|
payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
|
617
655
|
else
|
618
656
|
record_payload = passed_options
|
657
|
+
if rest_has_type && record_type
|
658
|
+
# inject type to options for prompting
|
659
|
+
# record_payload['type'] = record_type['code']
|
660
|
+
# options[:options]['type'] = record_type['code']
|
661
|
+
# initialize params for loading optionSource data
|
662
|
+
options[:params] ||= {}
|
663
|
+
options[:params]['type'] = record_type['code']
|
664
|
+
end
|
665
|
+
# update options without prompting by default
|
666
|
+
if self.class.method_defined?("update_#{rest_key}_option_types")
|
667
|
+
update_option_types = self.send("update_#{rest_key}_option_types")
|
668
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_option_types, options[:options], @api_client, options[:params])
|
669
|
+
v_prompt.deep_compact!
|
670
|
+
v_prompt.booleanize! # 'on' => true
|
671
|
+
record_payload.deep_merge!(v_prompt)
|
672
|
+
end
|
673
|
+
# options by type
|
674
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
675
|
+
if my_option_types && !my_option_types.empty?
|
676
|
+
# remove redundant fieldContext
|
677
|
+
# make them optional for updates
|
678
|
+
# todo: use current value as default instead of just making things optioanl
|
679
|
+
# maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
|
680
|
+
my_option_types.each do |option_type|
|
681
|
+
if option_type['fieldContext'] == rest_object_key
|
682
|
+
option_type['fieldContext'] = nil
|
683
|
+
end
|
684
|
+
option_type.delete('required')
|
685
|
+
option_type.delete('defaultValue')
|
686
|
+
end
|
687
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, options[:params])
|
688
|
+
v_prompt.deep_compact!
|
689
|
+
v_prompt.booleanize! # 'on' => true
|
690
|
+
record_payload.deep_merge!(v_prompt)
|
691
|
+
end
|
692
|
+
# advanced options
|
693
|
+
if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
|
694
|
+
update_advanced_option_types = self.send("update_#{rest_key}_advanced_option_types")
|
695
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_advanced_option_types, options[:options], @api_client, options[:params])
|
696
|
+
v_prompt.deep_compact!
|
697
|
+
v_prompt.booleanize! # 'on' => true
|
698
|
+
record_payload.deep_merge!(v_prompt)
|
699
|
+
end
|
700
|
+
# remove empty config, compact could hanlde this
|
701
|
+
if record_payload['config'] && record_payload['config'].empty?
|
702
|
+
record_payload.delete('config')
|
703
|
+
end
|
704
|
+
# prevent updating with empty payload
|
619
705
|
if record_payload.empty?
|
620
706
|
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
621
707
|
end
|
@@ -303,16 +303,16 @@ EOT
|
|
303
303
|
options = {}
|
304
304
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
305
305
|
if rest_has_type
|
306
|
-
opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}] -t TYPE")
|
307
306
|
opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
|
308
307
|
record_type_id = val
|
309
308
|
end
|
310
|
-
else
|
311
|
-
opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}]")
|
312
309
|
end
|
313
|
-
|
314
|
-
|
315
|
-
|
310
|
+
if self.class.method_defined?("add_#{rest_key}_option_types")
|
311
|
+
build_option_type_options(opts, options, self.send("add_#{rest_key}_option_types"))
|
312
|
+
end
|
313
|
+
if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
|
314
|
+
build_option_type_options(opts, options, self.send("add_#{rest_key}_advanced_option_types"))
|
315
|
+
end
|
316
316
|
build_standard_add_options(opts, options)
|
317
317
|
opts.footer = <<-EOT
|
318
318
|
Create a new #{rest_label.downcase}.
|
@@ -329,24 +329,27 @@ EOT
|
|
329
329
|
if args[1] # && rest_has_name
|
330
330
|
record_name = args[1]
|
331
331
|
end
|
332
|
-
|
332
|
+
connect(options)
|
333
|
+
# load parent record
|
334
|
+
# todo: prompt instead of error
|
335
|
+
parent_record = rest_parent_find_by_name_or_id(parent_id)
|
336
|
+
if parent_record.nil?
|
337
|
+
raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
|
338
|
+
end
|
339
|
+
parent_id = parent_record['id']
|
340
|
+
# load or prompt for type
|
333
341
|
if rest_has_type
|
334
342
|
if record_type_id.nil?
|
335
|
-
raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
343
|
+
#raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
344
|
+
type_list = rest_type_interface.list({max:10000})[rest_type_list_key]
|
345
|
+
type_dropdown_options = type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
|
346
|
+
record_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => rest_type_label, 'type' => 'select', 'selectOptions' => type_dropdown_options, 'required' => true}], options[:options], @api_client)['type']
|
336
347
|
end
|
337
|
-
end
|
338
|
-
connect(options)
|
339
|
-
if rest_has_type
|
340
348
|
record_type = rest_type_find_by_name_or_id(record_type_id)
|
341
349
|
if record_type.nil?
|
342
350
|
raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
|
343
351
|
end
|
344
352
|
end
|
345
|
-
parent_record = rest_parent_find_by_name_or_id(parent_id)
|
346
|
-
if parent_record.nil?
|
347
|
-
raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
|
348
|
-
end
|
349
|
-
parent_id = parent_record['id']
|
350
353
|
passed_options = parse_passed_options(options)
|
351
354
|
payload = {}
|
352
355
|
if options[:payload]
|
@@ -362,8 +365,18 @@ EOT
|
|
362
365
|
# record_payload['type'] = {'code' => record_type['code']}
|
363
366
|
record_payload['type'] = record_type['code']
|
364
367
|
options[:options]['type'] = record_type['code'] # injected for prompt
|
368
|
+
# initialize params for loading optionSource data
|
369
|
+
options[:params] ||= {}
|
370
|
+
options[:params]['type'] = record_type['code']
|
365
371
|
end
|
366
372
|
record_payload.deep_merge!(passed_options)
|
373
|
+
if self.class.method_defined?("add_#{rest_key}_option_types")
|
374
|
+
add_option_types = self.send("add_#{rest_key}_option_types")
|
375
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_option_types, options[:options], @api_client, options[:params])
|
376
|
+
v_prompt.deep_compact!
|
377
|
+
v_prompt.booleanize! # 'on' => true
|
378
|
+
record_payload.deep_merge!(v_prompt)
|
379
|
+
end
|
367
380
|
# options by type
|
368
381
|
my_option_types = record_type ? record_type['optionTypes'] : nil
|
369
382
|
if my_option_types && !my_option_types.empty?
|
@@ -378,6 +391,14 @@ EOT
|
|
378
391
|
v_prompt.booleanize! # 'on' => true
|
379
392
|
record_payload.deep_merge!(v_prompt)
|
380
393
|
end
|
394
|
+
# advanced options (uses no_prompt)
|
395
|
+
if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
|
396
|
+
add_advanced_option_types = self.send("add_#{rest_key}_advanced_option_types")
|
397
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(add_advanced_option_types, options[:options], @api_client, options[:params])
|
398
|
+
v_prompt.deep_compact!
|
399
|
+
v_prompt.booleanize! # 'on' => true
|
400
|
+
record_payload.deep_merge!(v_prompt)
|
401
|
+
end
|
381
402
|
payload[rest_object_key] = record_payload
|
382
403
|
end
|
383
404
|
rest_interface.setopts(options)
|
@@ -397,11 +418,18 @@ EOT
|
|
397
418
|
def update(args)
|
398
419
|
parent_id = args[0]
|
399
420
|
id = args[1]
|
421
|
+
record_type = nil
|
422
|
+
record_type_id = nil
|
400
423
|
options = {}
|
401
424
|
params = {}
|
402
|
-
account_name = nil
|
403
425
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
404
426
|
opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}] [options]")
|
427
|
+
if self.class.method_defined?("update_#{rest_key}_option_types")
|
428
|
+
build_option_type_options(opts, options, self.send("update_#{rest_key}_option_types"))
|
429
|
+
end
|
430
|
+
if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
|
431
|
+
build_option_type_options(opts, options, self.send("update_#{rest_key}_advanced_option_types"))
|
432
|
+
end
|
405
433
|
build_standard_update_options(opts, options)
|
406
434
|
opts.footer = <<-EOT
|
407
435
|
Update an existing #{rest_label.downcase}.
|
@@ -418,13 +446,72 @@ EOT
|
|
418
446
|
parent_id = parent_record['id']
|
419
447
|
connect(options)
|
420
448
|
record = rest_find_by_name_or_id(id)
|
449
|
+
if record.nil?
|
450
|
+
return 1, "#{rest_name} not found for '#{id}'"
|
451
|
+
end
|
452
|
+
# load type so we can prompt for those option types
|
453
|
+
if rest_has_type
|
454
|
+
record_type_id = record['type']['id']
|
455
|
+
record_type = rest_type_find_by_name_or_id(record_type_id)
|
456
|
+
if record_type.nil?
|
457
|
+
raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
|
458
|
+
end
|
459
|
+
end
|
421
460
|
passed_options = parse_passed_options(options)
|
422
|
-
payload =
|
461
|
+
payload = {}
|
423
462
|
if options[:payload]
|
424
463
|
payload = options[:payload]
|
425
464
|
payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
|
426
465
|
else
|
427
466
|
record_payload = passed_options
|
467
|
+
if rest_has_type && record_type
|
468
|
+
# inject type to options for prompting
|
469
|
+
# record_payload['type'] = record_type['code']
|
470
|
+
# options[:options]['type'] = record_type['code']
|
471
|
+
# initialize params for loading optionSource data
|
472
|
+
options[:params] ||= {}
|
473
|
+
options[:params]['type'] = record_type['code']
|
474
|
+
end
|
475
|
+
# update options without prompting by default
|
476
|
+
if self.class.method_defined?("update_#{rest_key}_option_types")
|
477
|
+
update_option_types = self.send("update_#{rest_key}_option_types")
|
478
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_option_types, options[:options], @api_client, options[:params])
|
479
|
+
v_prompt.deep_compact!
|
480
|
+
v_prompt.booleanize! # 'on' => true
|
481
|
+
record_payload.deep_merge!(v_prompt)
|
482
|
+
end
|
483
|
+
# options by type
|
484
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
485
|
+
if my_option_types && !my_option_types.empty?
|
486
|
+
# remove redundant fieldContext
|
487
|
+
# make them optional for updates
|
488
|
+
# todo: use current value as default instead of just making things optioanl
|
489
|
+
# maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
|
490
|
+
my_option_types.each do |option_type|
|
491
|
+
if option_type['fieldContext'] == rest_object_key
|
492
|
+
option_type['fieldContext'] = nil
|
493
|
+
end
|
494
|
+
option_type.delete('required')
|
495
|
+
option_type.delete('defaultValue')
|
496
|
+
end
|
497
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, options[:params])
|
498
|
+
v_prompt.deep_compact!
|
499
|
+
v_prompt.booleanize! # 'on' => true
|
500
|
+
record_payload.deep_merge!(v_prompt)
|
501
|
+
end
|
502
|
+
# advanced options
|
503
|
+
if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
|
504
|
+
update_advanced_option_types = self.send("update_#{rest_key}_advanced_option_types")
|
505
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_advanced_option_types, options[:options], @api_client, options[:params])
|
506
|
+
v_prompt.deep_compact!
|
507
|
+
v_prompt.booleanize! # 'on' => true
|
508
|
+
record_payload.deep_merge!(v_prompt)
|
509
|
+
end
|
510
|
+
# remove empty config, compact could hanlde this
|
511
|
+
if record_payload['config'] && record_payload['config'].empty?
|
512
|
+
record_payload.delete('config')
|
513
|
+
end
|
514
|
+
# prevent updating with empty payload
|
428
515
|
if record_payload.empty?
|
429
516
|
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
430
517
|
end
|