morpheus-cli 5.3.2.3 → 5.4.1
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/Dockerfile +1 -1
- data/lib/morpheus/api/account_users_interface.rb +68 -0
- data/lib/morpheus/api/api_client.rb +75 -8
- data/lib/morpheus/api/audit_interface.rb +9 -0
- data/lib/morpheus/api/clouds_interface.rb +4 -11
- data/lib/morpheus/api/health_interface.rb +37 -3
- data/lib/morpheus/api/instances_interface.rb +39 -5
- data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
- data/lib/morpheus/api/load_balancer_profiles_interface.rb +9 -0
- data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +9 -0
- data/lib/morpheus/api/load_balancers_interface.rb +5 -0
- 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_routers_interface.rb +30 -0
- data/lib/morpheus/api/network_servers_interface.rb +98 -0
- data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
- data/lib/morpheus/api/read_interface.rb +4 -3
- data/lib/morpheus/api/rest_interface.rb +5 -4
- data/lib/morpheus/api/roles_interface.rb +7 -0
- data/lib/morpheus/api/secondary_read_interface.rb +1 -1
- data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
- data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
- data/lib/morpheus/api/storage_servers_interface.rb +9 -0
- data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
- data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
- data/lib/morpheus/api/users_interface.rb +16 -63
- data/lib/morpheus/api/virtual_images_interface.rb +23 -2
- data/lib/morpheus/api/virtual_servers_interface.rb +9 -0
- data/lib/morpheus/cli/cli_command.rb +274 -19
- data/lib/morpheus/cli/cli_registry.rb +56 -2
- 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} +1 -4
- 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} +17 -89
- data/lib/morpheus/cli/{archives_command.rb → commands/archives_command.rb} +0 -6
- data/lib/morpheus/cli/commands/audit.rb +188 -0
- 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} +1 -1
- 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} +170 -138
- data/lib/morpheus/cli/{clouds.rb → commands/clouds.rb} +22 -47
- data/lib/morpheus/cli/{clusters.rb → commands/clusters.rb} +86 -49
- 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} +15 -25
- 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} +473 -150
- data/lib/morpheus/cli/{integrations_command.rb → commands/integrations_command.rb} +0 -0
- data/lib/morpheus/cli/{invoices_command.rb → commands/invoices_command.rb} +118 -134
- 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} +20 -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} +3 -7
- 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/commands/load_balancer_monitors.rb +71 -0
- data/lib/morpheus/cli/commands/load_balancer_pools.rb +91 -0
- data/lib/morpheus/cli/commands/load_balancer_profiles.rb +65 -0
- data/lib/morpheus/cli/{load_balancer_types.rb → commands/load_balancer_types.rb} +9 -8
- data/lib/morpheus/cli/commands/load_balancer_virtual_servers.rb +156 -0
- data/lib/morpheus/cli/commands/load_balancers.rb +176 -0
- 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} +2 -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 +823 -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} +387 -57
- data/lib/morpheus/cli/{network_services_command.rb → commands/network_services_command.rb} +0 -4
- data/lib/morpheus/cli/commands/network_static_routes_command.rb +446 -0
- data/lib/morpheus/cli/commands/network_transport_zones_command.rb +452 -0
- data/lib/morpheus/cli/{networks_command.rb → commands/networks_command.rb} +21 -21
- data/lib/morpheus/cli/commands/open_command.rb +30 -0
- data/lib/morpheus/cli/commands/options.rb +98 -0
- 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} +1 -8
- 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} +7 -7
- 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} +5 -9
- 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} +245 -40
- 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} +4 -105
- 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/commands/storage_server_types.rb +50 -0
- data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
- data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
- data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
- data/lib/morpheus/cli/{subnets_command.rb → commands/subnets_command.rb} +7 -6
- data/lib/morpheus/cli/{tasks.rb → commands/tasks.rb} +25 -6
- 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} +1 -8
- 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} +1 -2
- data/lib/morpheus/cli/{user_settings_command.rb → commands/user_settings_command.rb} +2 -1
- data/lib/morpheus/cli/{user_sources_command.rb → commands/user_sources_command.rb} +1 -2
- data/lib/morpheus/cli/{users.rb → commands/users.rb} +28 -35
- 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} +4 -1
- data/lib/morpheus/cli/commands/{standard/version_command.rb → version_command.rb} +0 -0
- data/lib/morpheus/cli/commands/view.rb +102 -0
- data/lib/morpheus/cli/{virtual_images.rb → commands/virtual_images.rb} +251 -33
- 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/accounts_helper.rb +5 -5
- data/lib/morpheus/cli/mixins/load_balancers_helper.rb +26 -6
- data/lib/morpheus/cli/mixins/logs_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +51 -18
- data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +167 -110
- data/lib/morpheus/cli/mixins/rest_command.rb +268 -94
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +668 -0
- data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
- data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
- data/lib/morpheus/cli/option_parser.rb +25 -17
- data/lib/morpheus/cli/option_types.rb +137 -52
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli.rb +6 -128
- data/lib/morpheus/ext/string.rb +29 -6
- data/lib/morpheus/routes.rb +238 -0
- data/lib/morpheus/terminal.rb +5 -6
- data/lib/morpheus/util.rb +6 -1
- data/morpheus-cli.gemspec +1 -1
- metadata +183 -149
- data/lib/morpheus/cli/change_password_command.rb +0 -147
- data/lib/morpheus/cli/library.rb +0 -1
- data/lib/morpheus/cli/load_balancers.rb +0 -245
- data/lib/morpheus/cli/logout.rb +0 -81
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
require 'yaml'
|
|
2
|
-
require 'json'
|
|
3
|
-
require 'fileutils'
|
|
4
1
|
require 'morpheus/logging'
|
|
5
2
|
require 'morpheus/benchmarking'
|
|
6
|
-
require 'morpheus/
|
|
3
|
+
require 'morpheus/terminal'
|
|
7
4
|
require 'morpheus/cli/cli_registry'
|
|
5
|
+
require 'morpheus/cli/option_parser'
|
|
6
|
+
require 'morpheus/cli/option_types'
|
|
8
7
|
require 'morpheus/cli/mixins/print_helper'
|
|
9
8
|
require 'morpheus/cli/credentials'
|
|
9
|
+
#require 'morpheus/cli/commands/shell'
|
|
10
|
+
#require 'morpheus/cli/commands/remote'
|
|
10
11
|
require 'morpheus/api/api_client'
|
|
11
|
-
require 'morpheus/cli/remote'
|
|
12
|
-
require 'morpheus/terminal'
|
|
13
12
|
|
|
14
13
|
module Morpheus
|
|
15
14
|
module Cli
|
|
@@ -215,7 +214,8 @@ module Morpheus
|
|
|
215
214
|
opts.on(arg1, arg2, description) do |val|
|
|
216
215
|
if option_type['type'] == 'checkbox'
|
|
217
216
|
val = (val.to_s != 'false' && val.to_s != 'off')
|
|
218
|
-
|
|
217
|
+
elsif option_type['dataType'] != 'string'
|
|
218
|
+
# 'dataType': 'string' added to cli to avoid auto conversion to JSON
|
|
219
219
|
# attempt to parse JSON, this allows blank arrays for multiSelect like --tenants []
|
|
220
220
|
if (val.to_s[0] == '{' && val.to_s[-1] == '}') || (val.to_s[0] == '[' && val.to_s[-1] == ']')
|
|
221
221
|
begin
|
|
@@ -1011,7 +1011,7 @@ module Morpheus
|
|
|
1011
1011
|
# meh, could deprecate and make subcommand define handle() itself
|
|
1012
1012
|
# if args.count == 0 && default_subcommand
|
|
1013
1013
|
# # p "using default subcommand #{default_subcommand}"
|
|
1014
|
-
# return
|
|
1014
|
+
# return send(default_subcommand, args || [])
|
|
1015
1015
|
# end
|
|
1016
1016
|
subcommand_name = args[0]
|
|
1017
1017
|
if args.empty?
|
|
@@ -1032,7 +1032,7 @@ module Morpheus
|
|
|
1032
1032
|
error_msg = "'#{command_name} #{subcommand_name}' is not a #{prog_name} command.\n#{full_command_usage}"
|
|
1033
1033
|
raise CommandNotFoundError.new(error_msg)
|
|
1034
1034
|
end
|
|
1035
|
-
|
|
1035
|
+
send(cmd_method, args[1..-1])
|
|
1036
1036
|
end
|
|
1037
1037
|
|
|
1038
1038
|
def handle(args)
|
|
@@ -1202,11 +1202,18 @@ module Morpheus
|
|
|
1202
1202
|
# this could go be done in optparse.parse instead perhaps
|
|
1203
1203
|
def verify_args!(opts={})
|
|
1204
1204
|
args = opts[:args] || []
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1205
|
+
count = opts[:count]
|
|
1206
|
+
# simplify output for verify_args!(min:2, max:2) or verify_args!(max:0)
|
|
1207
|
+
if opts[:min] && opts[:max] && opts[:min] == opts[:max]
|
|
1208
|
+
count = opts[:min]
|
|
1209
|
+
elsif opts[:max] == 0
|
|
1210
|
+
count = 0
|
|
1211
|
+
end
|
|
1212
|
+
if count
|
|
1213
|
+
if args.count < count
|
|
1214
|
+
raise_args_error("not enough arguments, expected #{count} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
|
|
1215
|
+
elsif args.count > count
|
|
1216
|
+
raise_args_error("too many arguments, expected #{count} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
|
|
1210
1217
|
end
|
|
1211
1218
|
else
|
|
1212
1219
|
if opts[:min]
|
|
@@ -1223,6 +1230,72 @@ module Morpheus
|
|
|
1223
1230
|
true
|
|
1224
1231
|
end
|
|
1225
1232
|
|
|
1233
|
+
# The default way to build options for the list command
|
|
1234
|
+
# @param [OptionParser] opts
|
|
1235
|
+
# @param [Hash] options
|
|
1236
|
+
# @param [Hash] params
|
|
1237
|
+
def build_list_options(opts, options, params)
|
|
1238
|
+
build_standard_list_options(opts, options)
|
|
1239
|
+
end
|
|
1240
|
+
|
|
1241
|
+
# The default way to parse options for the list command
|
|
1242
|
+
# @param [Array] args
|
|
1243
|
+
# @param [Hash] options
|
|
1244
|
+
# @param [Hash] params
|
|
1245
|
+
def parse_list_options!(args, options, params)
|
|
1246
|
+
if args.count > 0
|
|
1247
|
+
options[:phrase] = args.join(" ")
|
|
1248
|
+
# params['phrase'] = = args.join(" ")
|
|
1249
|
+
end
|
|
1250
|
+
params.merge!(parse_list_options(options))
|
|
1251
|
+
end
|
|
1252
|
+
|
|
1253
|
+
# The default way to build options for the list command
|
|
1254
|
+
# @param [OptionParser] opts
|
|
1255
|
+
# @param [Hash] options
|
|
1256
|
+
# @param [Hash] params
|
|
1257
|
+
def build_get_options(opts, options, params)
|
|
1258
|
+
build_standard_get_options(opts, options)
|
|
1259
|
+
end
|
|
1260
|
+
|
|
1261
|
+
# The default way to parse options for the get command
|
|
1262
|
+
# @param [OptionParser] opts
|
|
1263
|
+
# @param [Hash] options
|
|
1264
|
+
# @param [Hash] params
|
|
1265
|
+
def parse_get_options!(args, options, params)
|
|
1266
|
+
params.merge!(parse_query_options(options))
|
|
1267
|
+
end
|
|
1268
|
+
|
|
1269
|
+
# The default way to parse options for the get command
|
|
1270
|
+
# @param type [string]
|
|
1271
|
+
# @param options [Hash] The command options
|
|
1272
|
+
# @param params [Hash] The query parameters the output is being appended to
|
|
1273
|
+
# @param param_name [String]
|
|
1274
|
+
# @param lookup_ids [Boolean] Also lookup ids to make sure they exist or else error
|
|
1275
|
+
# @return
|
|
1276
|
+
def parse_parameter_as_resource_id!(type, options, params, param_name=nil, lookup_ids=false)
|
|
1277
|
+
# type = type.to_s.singularize
|
|
1278
|
+
if options.key?(type)
|
|
1279
|
+
val = options[type].to_s
|
|
1280
|
+
param_name ||= "#{type.to_s.camelcase}Id"
|
|
1281
|
+
if val
|
|
1282
|
+
if val.to_s !~ /\A\d{1,}\Z/ || lookup_ids
|
|
1283
|
+
record = find_by_name(type, val)
|
|
1284
|
+
if record.nil?
|
|
1285
|
+
# avoid double error render by exiting here, ew
|
|
1286
|
+
exit 1
|
|
1287
|
+
raise_command_error "Storage Server not found for '#{val}'"
|
|
1288
|
+
end
|
|
1289
|
+
params[param_name] = record['id']
|
|
1290
|
+
else
|
|
1291
|
+
params[param_name] = val
|
|
1292
|
+
end
|
|
1293
|
+
return params[param_name]
|
|
1294
|
+
end
|
|
1295
|
+
end
|
|
1296
|
+
return nil
|
|
1297
|
+
end
|
|
1298
|
+
|
|
1226
1299
|
# parse the parameters provided by the common :list options
|
|
1227
1300
|
# this includes the :query options too via parse_query_options().
|
|
1228
1301
|
# returns Hash of params the format {"phrase": => "foobar", "max": 100}
|
|
@@ -1237,7 +1310,11 @@ module Morpheus
|
|
|
1237
1310
|
end
|
|
1238
1311
|
# arbitrary filters
|
|
1239
1312
|
list_params.merge!(parse_query_options(options))
|
|
1240
|
-
|
|
1313
|
+
# ok, any string keys in options can become query parameters, eg. options['name'] = 'foobar'
|
|
1314
|
+
# do it!
|
|
1315
|
+
# options.each do |k, v|
|
|
1316
|
+
# list_params[k] = v
|
|
1317
|
+
# end
|
|
1241
1318
|
return list_params
|
|
1242
1319
|
end
|
|
1243
1320
|
|
|
@@ -1358,7 +1435,7 @@ module Morpheus
|
|
|
1358
1435
|
full_outfile = File.expand_path(options[:outfile])
|
|
1359
1436
|
if output
|
|
1360
1437
|
print_to_file(output, options[:outfile], options[:overwrite])
|
|
1361
|
-
print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)}
|
|
1438
|
+
print "#{cyan}Wrote output to file #{options[:outfile]} (#{format_bytes(File.size(full_outfile))})\n" unless options[:quiet]
|
|
1362
1439
|
else
|
|
1363
1440
|
# uhhh ok lets try this
|
|
1364
1441
|
Morpheus::Logging::DarkPrinter.puts "using experimental feature: --out without a common format like json, yml or csv" if Morpheus::Logging.debug?
|
|
@@ -1366,7 +1443,7 @@ module Morpheus
|
|
|
1366
1443
|
if result && result != 0
|
|
1367
1444
|
return result
|
|
1368
1445
|
end
|
|
1369
|
-
print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)}
|
|
1446
|
+
print "#{cyan}Wrote output to file #{options[:outfile]} (#{format_bytes(File.size(full_outfile))})\n" unless options[:quiet]
|
|
1370
1447
|
return 0, nil
|
|
1371
1448
|
end
|
|
1372
1449
|
else
|
|
@@ -1397,6 +1474,184 @@ module Morpheus
|
|
|
1397
1474
|
|
|
1398
1475
|
alias :render_with_format :render_response
|
|
1399
1476
|
|
|
1477
|
+
# Dynamic find methods to load a record of any type
|
|
1478
|
+
# def find_by_name_or_id(type, val)
|
|
1479
|
+
# interface = instance_variable_get "@#{type}s_interface"
|
|
1480
|
+
# typeCamelCase = type.gsub(/(?:^|_)([a-z])/) do $1.upcase end
|
|
1481
|
+
# typeCamelCase = typeCamelCase[0, 1].downcase + typeCamelCase[1..-1]
|
|
1482
|
+
# (val.to_s =~ /\A\d{1,}\Z/) ? interface.get(val.to_i)[typeCamelCase] : interface.list({'name' => val})["#{typeCamelCase}s"].first
|
|
1483
|
+
# end
|
|
1484
|
+
|
|
1485
|
+
# Find a resource by type and name or id
|
|
1486
|
+
# @param type [String of Symbol] Type of resource formatted as singular, lowerscore with underscores.
|
|
1487
|
+
# @param *id [String or Numeric] ID of resource, multiple arguments may be passed when using a secondary interface where parent_id, id is required.
|
|
1488
|
+
# Example: find_by_name_or_id("instance", "K2")
|
|
1489
|
+
# find_by_name_or_id("storage_volume", 42)
|
|
1490
|
+
# find_by_name_or_id("instance", "My Instance")
|
|
1491
|
+
# find_by_name_or_id("load_balancer_pool", load_balancer_id, id)
|
|
1492
|
+
def find_by_name_or_id(*args)
|
|
1493
|
+
val = args.last
|
|
1494
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
|
1495
|
+
return find_by_id(*args)
|
|
1496
|
+
else
|
|
1497
|
+
return find_by_name(*args)
|
|
1498
|
+
end
|
|
1499
|
+
end
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
# Find a resource by type and id
|
|
1503
|
+
# Usage: find_by_name_or_id("app", 3)
|
|
1504
|
+
def find_by_id(*args)
|
|
1505
|
+
#Morpheus::Logging::DarkPrinter.puts "find_by_id(#{args.join(', ')})" if Morpheus::Logging.debug?
|
|
1506
|
+
# type, ids = args.first, args[1..-1]
|
|
1507
|
+
type, *ids = args
|
|
1508
|
+
type = type.to_s.singularize.underscore
|
|
1509
|
+
# still relying on the command or helper to define these _label and _key methods
|
|
1510
|
+
label = send("#{type}_label")
|
|
1511
|
+
object_key = send("#{type}_object_key")
|
|
1512
|
+
interface_name = "@#{type.pluralize}_interface"
|
|
1513
|
+
interface = instance_variable_get(interface_name)
|
|
1514
|
+
if interface.nil?
|
|
1515
|
+
raise "#{self.class} has not defined interface #{interface_name}"
|
|
1516
|
+
end
|
|
1517
|
+
begin
|
|
1518
|
+
json_response = interface.get(*ids)
|
|
1519
|
+
return json_response[object_key]
|
|
1520
|
+
rescue RestClient::Exception => e
|
|
1521
|
+
if e.response && e.response.code == 404
|
|
1522
|
+
print_red_alert "#{label} not found by id #{ids.last}"
|
|
1523
|
+
return nil
|
|
1524
|
+
else
|
|
1525
|
+
raise e
|
|
1526
|
+
end
|
|
1527
|
+
end
|
|
1528
|
+
end
|
|
1529
|
+
|
|
1530
|
+
# Find a record by type and name
|
|
1531
|
+
# Usage: find_by_name_or_id("network", "Skynet")
|
|
1532
|
+
def find_by_name(*args)
|
|
1533
|
+
#Morpheus::Logging::DarkPrinter.puts "find_by_name(#{args.join(', ')})" if Morpheus::Logging.debug?
|
|
1534
|
+
# type, ids = args.first, args[1..-1]
|
|
1535
|
+
type, *ids = args
|
|
1536
|
+
type = type.to_s.singularize.underscore
|
|
1537
|
+
val = ids.pop
|
|
1538
|
+
params = {}
|
|
1539
|
+
name_property = 'name'
|
|
1540
|
+
if type == 'user'
|
|
1541
|
+
name_property = 'username'
|
|
1542
|
+
params['global'] = 'true'
|
|
1543
|
+
end
|
|
1544
|
+
params[name_property] = val.to_s
|
|
1545
|
+
request_args = ids + [params]
|
|
1546
|
+
request_args.unshift(type)
|
|
1547
|
+
records = find_all(*request_args)
|
|
1548
|
+
# still relying on the command or helper to define these _label and _key methods
|
|
1549
|
+
label = respond_to?("#{type}_label", true) ? send("#{type}_label") : type.titleize
|
|
1550
|
+
if records.empty?
|
|
1551
|
+
print_red_alert "#{label} not found by name '#{val}'"
|
|
1552
|
+
return nil
|
|
1553
|
+
elsif records.size > 1
|
|
1554
|
+
print_red_alert "More than one #{label.downcase} found by #{name_property} '#{val}'"
|
|
1555
|
+
print_error "\n"
|
|
1556
|
+
if type == "user"
|
|
1557
|
+
puts_error as_pretty_table(records, [:id, :username, {"FIRST NAME" => "firstName"}, {"LAST NAME" => "lastName"}, {"TENANT" => lambda {|it| it['account']['name'] rescue ''}}], {color:red})
|
|
1558
|
+
else
|
|
1559
|
+
puts_error as_pretty_table(records, [:id, :name], {color:red})
|
|
1560
|
+
end
|
|
1561
|
+
print_red_alert "Try using ID instead"
|
|
1562
|
+
print_error reset,"\n"
|
|
1563
|
+
return nil
|
|
1564
|
+
else
|
|
1565
|
+
return records[0]
|
|
1566
|
+
end
|
|
1567
|
+
end
|
|
1568
|
+
|
|
1569
|
+
# Load a list of records by type
|
|
1570
|
+
# @example Find an app by id
|
|
1571
|
+
# find_record(:app, 1)
|
|
1572
|
+
# report_types = find_all("reportTypes", {phrase:"amazon"})
|
|
1573
|
+
# pools = find_all("loadBalancerPool", load_balancer_id)
|
|
1574
|
+
# @return Array of records
|
|
1575
|
+
def find_all(*args)
|
|
1576
|
+
#Morpheus::Logging::DarkPrinter.puts "find_all(#{args.join(', ')})" if Morpheus::Logging.debug?
|
|
1577
|
+
type, *request_args = args
|
|
1578
|
+
type = type.to_s.singularize.underscore
|
|
1579
|
+
list_key = respond_to?("#{type}_list_key", true) ? send("#{type}_list_key") : type.camelcase.pluralize
|
|
1580
|
+
json_response = find_all_json(*args)
|
|
1581
|
+
if !json_response.key?(list_key)
|
|
1582
|
+
# maybe just use the first key like this:
|
|
1583
|
+
# list_key = json_response.keys.find { |k| json_response[k].is_a?(Array) }
|
|
1584
|
+
# print_error(json_response) if Morpheus::Logging.debug?
|
|
1585
|
+
raise "API response is missing list property '#{list_key}'"
|
|
1586
|
+
end
|
|
1587
|
+
return json_response[list_key]
|
|
1588
|
+
end
|
|
1589
|
+
|
|
1590
|
+
# Load json response for a list of records by type
|
|
1591
|
+
# @return Hash of JSON data
|
|
1592
|
+
def find_all_json(*args)
|
|
1593
|
+
type, *request_args = args
|
|
1594
|
+
get_interface(type).list(*request_args)
|
|
1595
|
+
end
|
|
1596
|
+
|
|
1597
|
+
alias :find_all_records :find_all
|
|
1598
|
+
alias :find_all_records_json :find_all_json
|
|
1599
|
+
|
|
1600
|
+
# Load a single record (Hash) by type and id and optional parameters
|
|
1601
|
+
# Examples:
|
|
1602
|
+
# apps = find_record(:app)
|
|
1603
|
+
# report_types = find_record("reportTypes", {phrase:"amazon"})
|
|
1604
|
+
# pools = find_record("loadBalancerPool", balancer_id)
|
|
1605
|
+
# @return [Hash] of the object that was found or raises an exception if 404 not found encountered.
|
|
1606
|
+
def find_record(*args)
|
|
1607
|
+
#Morpheus::Logging::DarkPrinter.puts "find_record(#{args.join(', ')})" if Morpheus::Logging.debug?
|
|
1608
|
+
type, *request_args = args
|
|
1609
|
+
type = type.to_s.singularize.underscore
|
|
1610
|
+
object_key = respond_to?("#{type}_object_key", true) ? send("#{type}_object_key") : type.camelcase.singularize
|
|
1611
|
+
json_response = find_record_json(*args)
|
|
1612
|
+
if !json_response.key?(object_key)
|
|
1613
|
+
# maybe just use the first key like this:
|
|
1614
|
+
# object_key = json_response.keys.find { |k| json_response[k].is_a?(Hash) }
|
|
1615
|
+
# print_error(json_response) if Morpheus::Logging.debug?
|
|
1616
|
+
raise "API response is missing object property '#{object_key}'"
|
|
1617
|
+
end
|
|
1618
|
+
return json_response[object_key]
|
|
1619
|
+
end
|
|
1620
|
+
|
|
1621
|
+
# Load list of records by type and (optional) parameters
|
|
1622
|
+
# Examples:
|
|
1623
|
+
# apps = find_record(:app, 1)
|
|
1624
|
+
# report_types = find_record("reportType", 1)
|
|
1625
|
+
# pools = find_all("loadBalancerPool", load_balancer_id)
|
|
1626
|
+
def find_record_json(*args)
|
|
1627
|
+
#Morpheus::Logging::DarkPrinter.puts "find_record_json(#{args.join(', ')})" if Morpheus::Logging.debug?
|
|
1628
|
+
type, *request_args = args
|
|
1629
|
+
get_interface(type).get(*request_args)
|
|
1630
|
+
end
|
|
1631
|
+
|
|
1632
|
+
# Load json response for a list of records by type
|
|
1633
|
+
def get_interface(type)
|
|
1634
|
+
#Morpheus::Logging::DarkPrinter.puts "get_interface(#{type})" if Morpheus::Logging.debug?
|
|
1635
|
+
# todo: can probably just do @api_client ? @api_client.interface(interface_name) : nil
|
|
1636
|
+
type = type.to_s.singularize.underscore
|
|
1637
|
+
interface_name = "@#{type.pluralize}_interface"
|
|
1638
|
+
interface = nil
|
|
1639
|
+
if instance_variable_defined?(interface_name)
|
|
1640
|
+
interface = instance_variable_get(interface_name)
|
|
1641
|
+
if interface.nil?
|
|
1642
|
+
# Fix is to update connect() to do @apps_interface = @api_client.apps
|
|
1643
|
+
raise "API Interface #{interface_name} is nil"
|
|
1644
|
+
end
|
|
1645
|
+
else
|
|
1646
|
+
if @api_client.is_a?(Morpheus::APIClient)
|
|
1647
|
+
interface = @api_client.interface(type.pluralize)
|
|
1648
|
+
else
|
|
1649
|
+
raise "#{self.class} has not initalized @api_client"
|
|
1650
|
+
end
|
|
1651
|
+
end
|
|
1652
|
+
return interface
|
|
1653
|
+
end
|
|
1654
|
+
|
|
1400
1655
|
module ClassMethods
|
|
1401
1656
|
|
|
1402
1657
|
def prog_name
|
|
@@ -1404,14 +1659,14 @@ module Morpheus
|
|
|
1404
1659
|
end
|
|
1405
1660
|
|
|
1406
1661
|
def set_command_name(cmd_name)
|
|
1407
|
-
@command_name = cmd_name
|
|
1662
|
+
@command_name = cmd_name.to_sym
|
|
1408
1663
|
Morpheus::Cli::CliRegistry.add(self, self.command_name)
|
|
1409
1664
|
end
|
|
1410
1665
|
|
|
1411
1666
|
def default_command_name
|
|
1412
1667
|
class_name = self.name.split('::')[-1]
|
|
1413
1668
|
#class_name.sub!(/Command$/, '')
|
|
1414
|
-
Morpheus::Cli::CliRegistry.cli_ize(class_name)
|
|
1669
|
+
Morpheus::Cli::CliRegistry.cli_ize(class_name).to_sym
|
|
1415
1670
|
end
|
|
1416
1671
|
|
|
1417
1672
|
def command_name
|
|
@@ -4,6 +4,7 @@ require 'morpheus/logging'
|
|
|
4
4
|
require 'morpheus/cli/errors'
|
|
5
5
|
require 'morpheus/cli/error_handler'
|
|
6
6
|
require 'morpheus/cli/expression_parser'
|
|
7
|
+
require 'morpheus/ext/string'
|
|
7
8
|
|
|
8
9
|
module Morpheus
|
|
9
10
|
module Cli
|
|
@@ -77,14 +78,26 @@ module Morpheus
|
|
|
77
78
|
|
|
78
79
|
def exec_command(command_name, args)
|
|
79
80
|
#puts "exec_command(#{command_name}, #{args})"
|
|
80
|
-
found_alias_command = instance.get_alias(command_name)
|
|
81
81
|
if has_alias?(command_name)
|
|
82
82
|
exec_alias(command_name, args)
|
|
83
83
|
elsif has_command?(command_name)
|
|
84
84
|
instance.get(command_name).new.handle(args)
|
|
85
85
|
else
|
|
86
86
|
# todo: need to just return error instead of raise
|
|
87
|
-
|
|
87
|
+
msg = "'#{command_name}' is not a morpheus command."
|
|
88
|
+
suggestions = find_command_suggestions(command_name)
|
|
89
|
+
if suggestions && suggestions.size == 1
|
|
90
|
+
msg += "\nThe most similar command is:\n"
|
|
91
|
+
suggestions.first(5).each do |suggestion|
|
|
92
|
+
msg += "\t" + suggestion + "\n"
|
|
93
|
+
end
|
|
94
|
+
elsif suggestions && suggestions.size > 1
|
|
95
|
+
msg += "\nThe most similar commands are:\n"
|
|
96
|
+
suggestions.first(5).each do |suggestion|
|
|
97
|
+
msg += "\t" + suggestion + "\n"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
raise CommandNotFoundError.new(msg)
|
|
88
101
|
end
|
|
89
102
|
end
|
|
90
103
|
|
|
@@ -269,6 +282,47 @@ module Morpheus
|
|
|
269
282
|
return exit_code, err
|
|
270
283
|
end
|
|
271
284
|
|
|
285
|
+
def cached_command_list
|
|
286
|
+
@cached_command_list ||= (all.keys + all_aliases.keys).collect { |it| it.to_s }.sort
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def clear_cached_command_list
|
|
290
|
+
@cached_command_list = nil
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# find suggested commands (or aliases) for a name that was not found
|
|
294
|
+
# First this looks for the plural of the original guess
|
|
295
|
+
# Then pop characters off the end looking for partial matches
|
|
296
|
+
# as long as the guess is at least 3 characters
|
|
297
|
+
def find_command_suggestions(command_name)
|
|
298
|
+
every_command = cached_command_list
|
|
299
|
+
guess = command_name
|
|
300
|
+
suggestions = []
|
|
301
|
+
while suggestions.empty? && guess.size >= 3
|
|
302
|
+
plural_guess = guess.pluralize
|
|
303
|
+
if every_command.include?(guess)
|
|
304
|
+
suggestions << guess
|
|
305
|
+
end
|
|
306
|
+
if every_command.include?(plural_guess)
|
|
307
|
+
suggestions << plural_guess
|
|
308
|
+
end
|
|
309
|
+
# if every_command.include?(guess)
|
|
310
|
+
# suggestions << plural_guess
|
|
311
|
+
# else
|
|
312
|
+
guess_regexp = /^#{Regexp.escape(guess)}/i
|
|
313
|
+
every_command.each do |it|
|
|
314
|
+
if it =~ guess_regexp
|
|
315
|
+
suggestions << it
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
# end
|
|
319
|
+
guess = guess[0..-2]
|
|
320
|
+
end
|
|
321
|
+
suggestions.uniq!
|
|
322
|
+
suggestions.sort! { |x,y| [x.split('-').size, x] <=> [y.split('-').size, y] }
|
|
323
|
+
return suggestions
|
|
324
|
+
end
|
|
325
|
+
|
|
272
326
|
end
|
|
273
327
|
|
|
274
328
|
end
|
|
@@ -75,7 +75,7 @@ class Morpheus::Cli::AccessTokenCommand
|
|
|
75
75
|
"Refresh Token" => lambda {|wallet| wallet['refresh_token'] },
|
|
76
76
|
"Login Date" => lambda {|wallet| format_local_dt(wallet['login_date']) },
|
|
77
77
|
"Expire Date" => lambda {|wallet| wallet['expire_date'] ? format_local_dt(wallet['expire_date']) : "" },
|
|
78
|
-
|
|
78
|
+
"Remote" => lambda {|wallet| display_appliance(@appliance_name, @appliance_url) },
|
|
79
79
|
}
|
|
80
80
|
print cyan
|
|
81
81
|
puts as_description_list(@wallet, description_cols)
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
require 'yaml'
|
|
3
|
-
require 'io/console'
|
|
4
|
-
require 'rest_client'
|
|
5
|
-
require 'optparse'
|
|
6
1
|
require 'morpheus/cli/cli_command'
|
|
7
|
-
require 'morpheus/cli/mixins/accounts_helper'
|
|
8
|
-
require 'morpheus/cli/mixins/infrastructure_helper'
|
|
9
|
-
require 'morpheus/logging'
|
|
10
2
|
|
|
11
3
|
class Morpheus::Cli::AccountGroupsCommand
|
|
12
4
|
include Morpheus::Cli::CliCommand
|
|
File without changes
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
1
|
require 'morpheus/cli/cli_command'
|
|
3
|
-
require 'morpheus/cli/shell'
|
|
4
|
-
require 'json'
|
|
5
2
|
|
|
6
3
|
# This command allows the creation of an alias
|
|
7
4
|
# these aliases are stored in the $MORPHEUS_CLI_HOME/.morpheusrc
|
|
@@ -273,7 +270,7 @@ EOT
|
|
|
273
270
|
out << "\n"
|
|
274
271
|
out << cyan
|
|
275
272
|
out << as_pretty_table(my_aliases, alias_columns, {:border_style => :thin}.merge(options))
|
|
276
|
-
out << format_results_pagination({size
|
|
273
|
+
out << format_results_pagination({'size' => my_aliases.size, 'total' => my_aliases.size.to_i})
|
|
277
274
|
out << reset
|
|
278
275
|
out << "\n"
|
|
279
276
|
end
|
data/lib/morpheus/cli/{appliance_settings_command.rb → commands/appliance_settings_command.rb}
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
# require 'yaml'
|
|
2
|
-
require 'io/console'
|
|
3
|
-
require 'rest_client'
|
|
4
|
-
require 'optparse'
|
|
5
|
-
require 'filesize'
|
|
6
1
|
require 'morpheus/cli/cli_command'
|
|
7
|
-
require 'morpheus/cli/mixins/accounts_helper'
|
|
8
|
-
require 'morpheus/cli/mixins/provisioning_helper'
|
|
9
|
-
require 'morpheus/cli/mixins/processes_helper'
|
|
10
|
-
require 'morpheus/cli/mixins/logs_helper'
|
|
11
2
|
|
|
12
3
|
class Morpheus::Cli::Apps
|
|
13
4
|
include Morpheus::Cli::CliCommand
|
|
@@ -19,9 +10,7 @@ class Morpheus::Cli::Apps
|
|
|
19
10
|
set_command_name :apps
|
|
20
11
|
set_command_description "View and manage apps."
|
|
21
12
|
register_subcommands :list, :count, :get, :view, :add, :update, :remove, :cancel_removal, :add_instance, :remove_instance, :logs, :security_groups, :apply_security_groups, :history
|
|
22
|
-
register_subcommands :
|
|
23
|
-
register_subcommands :apply
|
|
24
|
-
register_subcommands :refresh
|
|
13
|
+
register_subcommands :refresh, :apply
|
|
25
14
|
register_subcommands :stop, :start, :restart
|
|
26
15
|
register_subcommands :wiki, :update_wiki
|
|
27
16
|
#register_subcommands :firewall_disable, :firewall_enable
|
|
@@ -36,7 +25,7 @@ class Morpheus::Cli::Apps
|
|
|
36
25
|
def connect(opts)
|
|
37
26
|
@api_client = establish_remote_appliance_connection(opts)
|
|
38
27
|
@accounts_interface = @api_client.accounts
|
|
39
|
-
@
|
|
28
|
+
@account_users_interface = @api_client.account_users
|
|
40
29
|
@apps_interface = @api_client.apps
|
|
41
30
|
@blueprints_interface = @api_client.blueprints
|
|
42
31
|
@instance_types_interface = @api_client.instance_types
|
|
@@ -438,7 +427,7 @@ class Morpheus::Cli::Apps
|
|
|
438
427
|
instance_prompt_options[:default_cloud] = cloud ? cloud['name'] : nil
|
|
439
428
|
instance_prompt_options[:environment] = selected_environment ? selected_environment['code'] : nil
|
|
440
429
|
instance_prompt_options[:default_security_groups] = scoped_instance_config['securityGroups'] ? scoped_instance_config['securityGroups'] : nil
|
|
441
|
-
|
|
430
|
+
|
|
442
431
|
instance_prompt_options[:no_prompt] = options[:no_prompt]
|
|
443
432
|
#instance_prompt_options[:always_prompt] = options[:no_prompt] != true # options[:always_prompt]
|
|
444
433
|
instance_prompt_options[:options] = scoped_instance_config # meh, actually need to make these default values instead..
|
|
@@ -460,8 +449,9 @@ class Morpheus::Cli::Apps
|
|
|
460
449
|
instance_prompt_options[:locked_fields] = scoped_instance_config['lockedFields']
|
|
461
450
|
instance_prompt_options[:for_app] = true
|
|
462
451
|
# this provisioning helper method handles all (most) of the parsing and prompting
|
|
452
|
+
scoped_instance_config = Marshal.load( Marshal.dump(scoped_instance_config) )
|
|
463
453
|
instance_config_payload = prompt_new_instance(instance_prompt_options)
|
|
464
|
-
|
|
454
|
+
|
|
465
455
|
# strip all empty string and nil
|
|
466
456
|
instance_config_payload.deep_compact!
|
|
467
457
|
# use the blueprint config as the base
|
|
@@ -900,9 +890,7 @@ This is only supported by certain types of apps.
|
|
|
900
890
|
EOT
|
|
901
891
|
end
|
|
902
892
|
optparse.parse!(args)
|
|
903
|
-
|
|
904
|
-
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
|
|
905
|
-
end
|
|
893
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
906
894
|
connect(options)
|
|
907
895
|
|
|
908
896
|
begin
|
|
@@ -927,65 +915,11 @@ EOT
|
|
|
927
915
|
return
|
|
928
916
|
end
|
|
929
917
|
json_response = @apps_interface.refresh(app["id"], params, payload)
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
return get([app['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
|
934
|
-
rescue RestClient::Exception => e
|
|
935
|
-
print_rest_exception(e, options)
|
|
936
|
-
exit 1
|
|
937
|
-
end
|
|
938
|
-
end
|
|
939
|
-
|
|
940
|
-
def prepare_apply(args)
|
|
941
|
-
params, payload, options = {}, {}, {}
|
|
942
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
943
|
-
opts.banner = subcommand_usage("[app] [options]")
|
|
944
|
-
build_standard_update_options(opts, options, [:auto_confirm])
|
|
945
|
-
opts.footer = <<-EOT
|
|
946
|
-
Prepare to apply an app.
|
|
947
|
-
[app] is required. This is the name or id of an app.
|
|
948
|
-
Template parameter values can be applied with -O templateParameter.foo=bar
|
|
949
|
-
This only prints the app configuration that would be applied.
|
|
950
|
-
It does not make any updates.
|
|
951
|
-
This is only supported by certain types of apps.
|
|
952
|
-
EOT
|
|
953
|
-
end
|
|
954
|
-
optparse.parse!(args)
|
|
955
|
-
if args.count != 1
|
|
956
|
-
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
|
|
957
|
-
end
|
|
958
|
-
connect(options)
|
|
959
|
-
|
|
960
|
-
begin
|
|
961
|
-
app = find_app_by_name_or_id(args[0])
|
|
962
|
-
return 1 if app.nil?
|
|
963
|
-
# construct request
|
|
964
|
-
params.merge!(parse_query_options(options))
|
|
965
|
-
payload = {}
|
|
966
|
-
if options[:payload]
|
|
967
|
-
payload = options[:payload]
|
|
968
|
-
payload.deep_merge!(parse_passed_options(options))
|
|
969
|
-
else
|
|
970
|
-
payload.deep_merge!(parse_passed_options(options))
|
|
971
|
-
# raise_command_error "Specify at least one option to update.\n#{optparse}" if payload.empty?
|
|
918
|
+
render_response(json_response, options) do
|
|
919
|
+
print_green_success "Refreshing app #{app['name']}"
|
|
920
|
+
# return _get(app['id'], options)
|
|
972
921
|
end
|
|
973
|
-
|
|
974
|
-
if options[:dry_run]
|
|
975
|
-
print_dry_run @apps_interface.dry.prepare_apply(app["id"], params, payload)
|
|
976
|
-
return
|
|
977
|
-
end
|
|
978
|
-
json_response = @apps_interface.prepare_apply(app["id"], params, payload)
|
|
979
|
-
render_result = render_with_format(json_response, options)
|
|
980
|
-
return 0 if render_result
|
|
981
|
-
# print_green_success "Prepared to apply app: #{app['name']}"
|
|
982
|
-
print_h1 "Prepared App: #{app['name']}"
|
|
983
|
-
app_config = json_response['data']
|
|
984
|
-
# app_config = json_response if app_config.nil?
|
|
985
|
-
puts as_yaml(app_config, options)
|
|
986
|
-
#return get([app['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
|
987
|
-
print "\n", reset
|
|
988
|
-
return 0
|
|
922
|
+
return 0, nil
|
|
989
923
|
rescue RestClient::Exception => e
|
|
990
924
|
print_rest_exception(e, options)
|
|
991
925
|
exit 1
|
|
@@ -1000,17 +934,11 @@ EOT
|
|
|
1000
934
|
opts.footer = <<-EOT
|
|
1001
935
|
Apply an app.
|
|
1002
936
|
[app] is required. This is the name or id of an app.
|
|
1003
|
-
|
|
1004
|
-
This is a way to apply an app with new configuration parameters to an app.
|
|
1005
|
-
This prints the app configuration that would be applied.
|
|
1006
|
-
It does not make any updates.
|
|
1007
|
-
This is only supported by certain types of apps.
|
|
937
|
+
This is only supported by certain types of apps such as terraform.
|
|
1008
938
|
EOT
|
|
1009
939
|
end
|
|
1010
940
|
optparse.parse!(args)
|
|
1011
|
-
|
|
1012
|
-
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
|
|
1013
|
-
end
|
|
941
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
1014
942
|
connect(options)
|
|
1015
943
|
|
|
1016
944
|
begin
|
|
@@ -1035,11 +963,11 @@ EOT
|
|
|
1035
963
|
return
|
|
1036
964
|
end
|
|
1037
965
|
json_response = @apps_interface.apply(app["id"], params, payload)
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
return 0
|
|
966
|
+
render_response(json_response, options) do
|
|
967
|
+
print_green_success "Applying app #{app['name']}"
|
|
968
|
+
# return _get(app['id'], options)
|
|
969
|
+
end
|
|
970
|
+
return 0, nil
|
|
1043
971
|
rescue RestClient::Exception => e
|
|
1044
972
|
print_rest_exception(e, options)
|
|
1045
973
|
exit 1
|