morpheus-cli 5.3.4 → 5.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/account_users_interface.rb +68 -0
  4. data/lib/morpheus/api/api_client.rb +69 -11
  5. data/lib/morpheus/api/audit_interface.rb +9 -0
  6. data/lib/morpheus/api/catalog_item_types_interface.rb +20 -0
  7. data/lib/morpheus/api/health_interface.rb +37 -3
  8. data/lib/morpheus/api/instances_interface.rb +49 -0
  9. data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
  10. data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
  11. data/lib/morpheus/api/load_balancer_profiles_interface.rb +4 -5
  12. data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +13 -4
  13. data/lib/morpheus/api/load_balancers_interface.rb +5 -0
  14. data/lib/morpheus/api/network_dhcp_relays_interface.rb +36 -0
  15. data/lib/morpheus/api/network_dhcp_servers_interface.rb +36 -0
  16. data/lib/morpheus/api/network_edge_clusters_interface.rb +26 -0
  17. data/lib/morpheus/api/network_routers_interface.rb +9 -0
  18. data/lib/morpheus/api/network_servers_interface.rb +68 -12
  19. data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
  20. data/lib/morpheus/api/ping_interface.rb +2 -0
  21. data/lib/morpheus/api/read_interface.rb +4 -3
  22. data/lib/morpheus/api/rest_interface.rb +3 -3
  23. data/lib/morpheus/api/roles_interface.rb +7 -0
  24. data/lib/morpheus/api/secondary_read_interface.rb +1 -1
  25. data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
  26. data/lib/morpheus/api/setup_interface.rb +4 -0
  27. data/lib/morpheus/api/snapshots_interface.rb +19 -0
  28. data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
  29. data/lib/morpheus/api/storage_servers_interface.rb +9 -0
  30. data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
  31. data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
  32. data/lib/morpheus/api/users_interface.rb +16 -63
  33. data/lib/morpheus/cli/cli_command.rb +260 -13
  34. data/lib/morpheus/cli/cli_registry.rb +2 -1
  35. data/lib/morpheus/cli/{access_token_command.rb → commands/access_token_command.rb} +1 -1
  36. data/lib/morpheus/cli/{account_groups_command.rb → commands/account_groups_command.rb} +0 -8
  37. data/lib/morpheus/cli/{activity_command.rb → commands/activity_command.rb} +0 -0
  38. data/lib/morpheus/cli/commands/{standard/alias_command.rb → alias_command.rb} +1 -4
  39. data/lib/morpheus/cli/{appliance_settings_command.rb → commands/appliance_settings_command.rb} +0 -0
  40. data/lib/morpheus/cli/{approvals_command.rb → commands/approvals_command.rb} +0 -0
  41. data/lib/morpheus/cli/{apps.rb → commands/apps.rb} +14 -87
  42. data/lib/morpheus/cli/{archives_command.rb → commands/archives_command.rb} +0 -6
  43. data/lib/morpheus/cli/commands/audit.rb +188 -0
  44. data/lib/morpheus/cli/{backup_jobs_command.rb → commands/backup_jobs_command.rb} +0 -0
  45. data/lib/morpheus/cli/{backup_settings_command.rb → commands/backup_settings_command.rb} +0 -0
  46. data/lib/morpheus/cli/{backups_command.rb → commands/backups_command.rb} +0 -0
  47. data/lib/morpheus/cli/commands/{standard/benchmark_command.rb → benchmark_command.rb} +0 -3
  48. data/lib/morpheus/cli/{blueprints_command.rb → commands/blueprints_command.rb} +1 -1
  49. data/lib/morpheus/cli/{boot_scripts_command.rb → commands/boot_scripts_command.rb} +0 -3
  50. data/lib/morpheus/cli/{budgets_command.rb → commands/budgets_command.rb} +0 -0
  51. data/lib/morpheus/cli/commands/{standard/cat_command.rb → cat_command.rb} +0 -0
  52. data/lib/morpheus/cli/{catalog_item_types_command.rb → commands/catalog_item_types_command.rb} +88 -0
  53. data/lib/morpheus/cli/{certificates_command.rb → commands/certificates_command.rb} +0 -0
  54. data/lib/morpheus/cli/commands/change_password_command.rb +132 -0
  55. data/lib/morpheus/cli/{cloud_datastores_command.rb → commands/cloud_datastores_command.rb} +0 -4
  56. data/lib/morpheus/cli/{cloud_folders_command.rb → commands/cloud_folders_command.rb} +0 -4
  57. data/lib/morpheus/cli/{cloud_resource_pools_command.rb → commands/cloud_resource_pools_command.rb} +0 -4
  58. data/lib/morpheus/cli/{clouds.rb → commands/clouds.rb} +0 -7
  59. data/lib/morpheus/cli/{clusters.rb → commands/clusters.rb} +96 -64
  60. data/lib/morpheus/cli/commands/{standard/coloring_command.rb → coloring_command.rb} +0 -2
  61. data/lib/morpheus/cli/{containers_command.rb → commands/containers_command.rb} +0 -7
  62. data/lib/morpheus/cli/commands/{standard/curl_command.rb → curl_command.rb} +0 -3
  63. data/lib/morpheus/cli/{cypher_command.rb → commands/cypher_command.rb} +0 -1
  64. data/lib/morpheus/cli/{dashboard_command.rb → commands/dashboard_command.rb} +0 -2
  65. data/lib/morpheus/cli/commands/{standard/debug_command.rb → debug_command.rb} +0 -1
  66. data/lib/morpheus/cli/{deploy.rb → commands/deploy.rb} +0 -1
  67. data/lib/morpheus/cli/{deployments.rb → commands/deployments.rb} +0 -0
  68. data/lib/morpheus/cli/{deploys.rb → commands/deploys.rb} +0 -1
  69. data/lib/morpheus/cli/{doc.rb → commands/doc.rb} +1 -1
  70. data/lib/morpheus/cli/commands/{standard/echo_command.rb → echo_command.rb} +0 -2
  71. data/lib/morpheus/cli/commands/{standard/edit_profile_command.rb → edit_profile_command.rb} +15 -4
  72. data/lib/morpheus/cli/commands/{standard/edit_rc_command.rb → edit_rc_command.rb} +19 -3
  73. data/lib/morpheus/cli/{environments_command.rb → commands/environments_command.rb} +0 -5
  74. data/lib/morpheus/cli/{execute_schedules_command.rb → commands/execute_schedules_command.rb} +0 -0
  75. data/lib/morpheus/cli/{execution_request_command.rb → commands/execution_request_command.rb} +0 -2
  76. data/lib/morpheus/cli/commands/{standard/exit_command.rb → exit_command.rb} +0 -2
  77. data/lib/morpheus/cli/{file_copy_request_command.rb → commands/file_copy_request_command.rb} +0 -4
  78. data/lib/morpheus/cli/{forgot_password.rb → commands/forgot_password.rb} +0 -0
  79. data/lib/morpheus/cli/commands/{standard/get_prompt_command.rb → get_prompt_command.rb} +0 -3
  80. data/lib/morpheus/cli/{groups.rb → commands/groups.rb} +0 -7
  81. data/lib/morpheus/cli/{guidance_command.rb → commands/guidance_command.rb} +1 -1
  82. data/lib/morpheus/cli/{health_command.rb → commands/health_command.rb} +104 -19
  83. data/lib/morpheus/cli/commands/{standard/history_command.rb → history_command.rb} +0 -3
  84. data/lib/morpheus/cli/{hosts.rb → commands/hosts.rb} +27 -24
  85. data/lib/morpheus/cli/{image_builder_command.rb → commands/image_builder_command.rb} +6 -16
  86. data/lib/morpheus/cli/{instance_types.rb → commands/instance_types.rb} +0 -3
  87. data/lib/morpheus/cli/{instances.rb → commands/instances.rb} +359 -7
  88. data/lib/morpheus/cli/{integrations_command.rb → commands/integrations_command.rb} +1 -12
  89. data/lib/morpheus/cli/{invoices_command.rb → commands/invoices_command.rb} +1 -1
  90. data/lib/morpheus/cli/{jobs_command.rb → commands/jobs_command.rb} +0 -0
  91. data/lib/morpheus/cli/{key_pairs.rb → commands/key_pairs.rb} +0 -6
  92. data/lib/morpheus/cli/{library_cluster_layouts_command.rb → commands/library_cluster_layouts_command.rb} +0 -4
  93. data/lib/morpheus/cli/{library_container_scripts_command.rb → commands/library_container_scripts_command.rb} +0 -0
  94. data/lib/morpheus/cli/{library_container_templates_command.rb → commands/library_container_templates_command.rb} +0 -1
  95. data/lib/morpheus/cli/{library_container_types_command.rb → commands/library_container_types_command.rb} +0 -4
  96. data/lib/morpheus/cli/{library_instance_types_command.rb → commands/library_instance_types_command.rb} +3 -4
  97. data/lib/morpheus/cli/{library_layouts_command.rb → commands/library_layouts_command.rb} +0 -4
  98. data/lib/morpheus/cli/{library_option_lists_command.rb → commands/library_option_lists_command.rb} +0 -4
  99. data/lib/morpheus/cli/{library_option_types_command.rb → commands/library_option_types_command.rb} +0 -4
  100. data/lib/morpheus/cli/{library_spec_templates_command.rb → commands/library_spec_templates_command.rb} +0 -1
  101. data/lib/morpheus/cli/{library_upgrades_command.rb → commands/library_upgrades_command.rb} +0 -4
  102. data/lib/morpheus/cli/{license.rb → commands/license.rb} +0 -3
  103. data/lib/morpheus/cli/commands/load_balancer_monitors.rb +70 -0
  104. data/lib/morpheus/cli/commands/load_balancer_pools.rb +90 -0
  105. data/lib/morpheus/cli/commands/load_balancer_profiles.rb +64 -0
  106. data/lib/morpheus/cli/{load_balancer_types.rb → commands/load_balancer_types.rb} +9 -8
  107. data/lib/morpheus/cli/{load_balancer_virtual_servers.rb → commands/load_balancer_virtual_servers.rb} +69 -58
  108. data/lib/morpheus/cli/commands/load_balancers.rb +192 -0
  109. data/lib/morpheus/cli/commands/{standard/log_level_command.rb → log_level_command.rb} +0 -3
  110. data/lib/morpheus/cli/{log_settings_command.rb → commands/log_settings_command.rb} +0 -0
  111. data/lib/morpheus/cli/{login.rb → commands/login.rb} +0 -5
  112. data/lib/morpheus/cli/commands/logout.rb +63 -0
  113. data/lib/morpheus/cli/{logs_command.rb → commands/logs_command.rb} +0 -3
  114. data/lib/morpheus/cli/commands/{standard/man_command.rb → man_command.rb} +0 -2
  115. data/lib/morpheus/cli/{monitoring_alerts_command.rb → commands/monitoring_alerts_command.rb} +0 -7
  116. data/lib/morpheus/cli/{monitoring_apps_command.rb → commands/monitoring_apps_command.rb} +0 -1
  117. data/lib/morpheus/cli/{monitoring_checks_command.rb → commands/monitoring_checks_command.rb} +0 -1
  118. data/lib/morpheus/cli/{monitoring_contacts_command.rb → commands/monitoring_contacts_command.rb} +0 -7
  119. data/lib/morpheus/cli/{monitoring_groups_command.rb → commands/monitoring_groups_command.rb} +0 -1
  120. data/lib/morpheus/cli/{monitoring_incidents_command.rb → commands/monitoring_incidents_command.rb} +0 -1
  121. data/lib/morpheus/cli/commands/network_dhcp_relays_command.rb +416 -0
  122. data/lib/morpheus/cli/commands/network_dhcp_servers_command.rb +407 -0
  123. data/lib/morpheus/cli/{network_domains_command.rb → commands/network_domains_command.rb} +0 -4
  124. data/lib/morpheus/cli/commands/network_edge_clusters_command.rb +329 -0
  125. data/lib/morpheus/cli/commands/network_firewalls_command.rb +823 -0
  126. data/lib/morpheus/cli/{network_groups_command.rb → commands/network_groups_command.rb} +0 -4
  127. data/lib/morpheus/cli/{network_pool_servers_command.rb → commands/network_pool_servers_command.rb} +0 -4
  128. data/lib/morpheus/cli/{network_pools_command.rb → commands/network_pools_command.rb} +0 -4
  129. data/lib/morpheus/cli/{network_proxies_command.rb → commands/network_proxies_command.rb} +0 -4
  130. data/lib/morpheus/cli/{network_routers_command.rb → commands/network_routers_command.rb} +96 -50
  131. data/lib/morpheus/cli/{network_services_command.rb → commands/network_services_command.rb} +0 -4
  132. data/lib/morpheus/cli/commands/network_static_routes_command.rb +451 -0
  133. data/lib/morpheus/cli/{network_scopes_command.rb → commands/network_transport_zones_command.rb} +102 -92
  134. data/lib/morpheus/cli/{networks_command.rb → commands/networks_command.rb} +20 -20
  135. data/lib/morpheus/cli/commands/open_command.rb +30 -0
  136. data/lib/morpheus/cli/commands/options.rb +98 -0
  137. data/lib/morpheus/cli/{packages_command.rb → commands/packages_command.rb} +0 -2
  138. data/lib/morpheus/cli/{ping.rb → commands/ping.rb} +3 -12
  139. data/lib/morpheus/cli/{policies_command.rb → commands/policies_command.rb} +2 -9
  140. data/lib/morpheus/cli/{power_schedules_command.rb → commands/power_schedules_command.rb} +0 -0
  141. data/lib/morpheus/cli/{preseed_scripts_command.rb → commands/preseed_scripts_command.rb} +0 -3
  142. data/lib/morpheus/cli/{price_sets_command.rb → commands/price_sets_command.rb} +0 -0
  143. data/lib/morpheus/cli/{prices_command.rb → commands/prices_command.rb} +7 -7
  144. data/lib/morpheus/cli/{processes_command.rb → commands/processes_command.rb} +0 -1
  145. data/lib/morpheus/cli/{projects_command.rb → commands/projects_command.rb} +0 -0
  146. data/lib/morpheus/cli/{provisioning_licenses_command.rb → commands/provisioning_licenses_command.rb} +0 -0
  147. data/lib/morpheus/cli/{provisioning_settings_command.rb → commands/provisioning_settings_command.rb} +1 -0
  148. data/lib/morpheus/cli/{recent_activity_command.rb → commands/recent_activity_command.rb} +0 -0
  149. data/lib/morpheus/cli/{remote.rb → commands/remote.rb} +21 -19
  150. data/lib/morpheus/cli/{reports_command.rb → commands/reports_command.rb} +0 -2
  151. data/lib/morpheus/cli/commands/{standard/rm_command.rb → rm_command.rb} +0 -0
  152. data/lib/morpheus/cli/{roles.rb → commands/roles.rb} +245 -40
  153. data/lib/morpheus/cli/{search_command.rb → commands/search_command.rb} +0 -0
  154. data/lib/morpheus/cli/{security_group_rules.rb → commands/security_group_rules.rb} +0 -5
  155. data/lib/morpheus/cli/{security_groups.rb → commands/security_groups.rb} +2 -8
  156. data/lib/morpheus/cli/{service_catalog_command.rb → commands/service_catalog_command.rb} +0 -0
  157. data/lib/morpheus/cli/{service_plans_command.rb → commands/service_plans_command.rb} +1 -1
  158. data/lib/morpheus/cli/commands/{standard/set_prompt_command.rb → set_prompt_command.rb} +0 -3
  159. data/lib/morpheus/cli/{setup.rb → commands/setup.rb} +1 -1
  160. data/lib/morpheus/cli/{shell.rb → commands/shell.rb} +4 -105
  161. data/lib/morpheus/cli/commands/{standard/sleep_command.rb → sleep_command.rb} +0 -2
  162. data/lib/morpheus/cli/commands/snapshots.rb +139 -0
  163. data/lib/morpheus/cli/commands/{standard/source_command.rb → source_command.rb} +0 -2
  164. data/lib/morpheus/cli/commands/{standard/ssl_verification_command.rb → ssl_verification_command.rb} +0 -3
  165. data/lib/morpheus/cli/{storage_providers_command.rb → commands/storage_providers_command.rb} +0 -4
  166. data/lib/morpheus/cli/commands/storage_server_types.rb +50 -0
  167. data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
  168. data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
  169. data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
  170. data/lib/morpheus/cli/{subnets_command.rb → commands/subnets_command.rb} +0 -4
  171. data/lib/morpheus/cli/{tasks.rb → commands/tasks.rb} +5 -9
  172. data/lib/morpheus/cli/commands/{standard/tee_command.rb → tee_command.rb} +0 -0
  173. data/lib/morpheus/cli/{tenants_command.rb → commands/tenants_command.rb} +1 -8
  174. data/lib/morpheus/cli/commands/{standard/update_command.rb → update_command.rb} +0 -1
  175. data/lib/morpheus/cli/{usage_command.rb → commands/usage_command.rb} +0 -0
  176. data/lib/morpheus/cli/{user_groups_command.rb → commands/user_groups_command.rb} +1 -2
  177. data/lib/morpheus/cli/{user_settings_command.rb → commands/user_settings_command.rb} +3 -2
  178. data/lib/morpheus/cli/{user_sources_command.rb → commands/user_sources_command.rb} +1 -2
  179. data/lib/morpheus/cli/{users.rb → commands/users.rb} +28 -35
  180. data/lib/morpheus/cli/{vdi_allocations_command.rb → commands/vdi_allocations_command.rb} +0 -0
  181. data/lib/morpheus/cli/{vdi_apps_command.rb → commands/vdi_apps_command.rb} +0 -0
  182. data/lib/morpheus/cli/{vdi_command.rb → commands/vdi_command.rb} +0 -0
  183. data/lib/morpheus/cli/{vdi_gateways_command.rb → commands/vdi_gateways_command.rb} +0 -0
  184. data/lib/morpheus/cli/{vdi_pools_command.rb → commands/vdi_pools_command.rb} +0 -0
  185. data/lib/morpheus/cli/commands/{standard/version_command.rb → version_command.rb} +0 -0
  186. data/lib/morpheus/cli/commands/view.rb +102 -0
  187. data/lib/morpheus/cli/{virtual_images.rb → commands/virtual_images.rb} +4 -5
  188. data/lib/morpheus/cli/{whitelabel_settings_command.rb → commands/whitelabel_settings_command.rb} +0 -1
  189. data/lib/morpheus/cli/{whoami.rb → commands/whoami.rb} +0 -4
  190. data/lib/morpheus/cli/{wiki_command.rb → commands/wiki_command.rb} +0 -5
  191. data/lib/morpheus/cli/{workflows.rb → commands/workflows.rb} +0 -3
  192. data/lib/morpheus/cli/mixins/accounts_helper.rb +5 -5
  193. data/lib/morpheus/cli/mixins/load_balancers_helper.rb +24 -4
  194. data/lib/morpheus/cli/mixins/logs_helper.rb +1 -1
  195. data/lib/morpheus/cli/mixins/print_helper.rb +51 -18
  196. data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
  197. data/lib/morpheus/cli/mixins/provisioning_helper.rb +96 -6
  198. data/lib/morpheus/cli/mixins/rest_command.rb +222 -62
  199. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +249 -70
  200. data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
  201. data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
  202. data/lib/morpheus/cli/option_types.rb +150 -46
  203. data/lib/morpheus/cli/version.rb +1 -1
  204. data/lib/morpheus/cli.rb +5 -135
  205. data/lib/morpheus/ext/string.rb +29 -6
  206. data/lib/morpheus/routes.rb +238 -0
  207. data/lib/morpheus/terminal.rb +5 -6
  208. data/lib/morpheus/util.rb +6 -1
  209. metadata +174 -144
  210. data/lib/morpheus/cli/change_password_command.rb +0 -147
  211. data/lib/morpheus/cli/library.rb +0 -1
  212. data/lib/morpheus/cli/load_balancer_pools.rb +0 -111
  213. data/lib/morpheus/cli/load_balancers.rb +0 -90
  214. 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/cli/option_parser'
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
@@ -1012,7 +1011,7 @@ module Morpheus
1012
1011
  # meh, could deprecate and make subcommand define handle() itself
1013
1012
  # if args.count == 0 && default_subcommand
1014
1013
  # # p "using default subcommand #{default_subcommand}"
1015
- # return self.send(default_subcommand, args || [])
1014
+ # return send(default_subcommand, args || [])
1016
1015
  # end
1017
1016
  subcommand_name = args[0]
1018
1017
  if args.empty?
@@ -1033,7 +1032,7 @@ module Morpheus
1033
1032
  error_msg = "'#{command_name} #{subcommand_name}' is not a #{prog_name} command.\n#{full_command_usage}"
1034
1033
  raise CommandNotFoundError.new(error_msg)
1035
1034
  end
1036
- self.send(cmd_method, args[1..-1])
1035
+ send(cmd_method, args[1..-1])
1037
1036
  end
1038
1037
 
1039
1038
  def handle(args)
@@ -1231,6 +1230,72 @@ module Morpheus
1231
1230
  true
1232
1231
  end
1233
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
+
1234
1299
  # parse the parameters provided by the common :list options
1235
1300
  # this includes the :query options too via parse_query_options().
1236
1301
  # returns Hash of params the format {"phrase": => "foobar", "max": 100}
@@ -1245,7 +1310,11 @@ module Morpheus
1245
1310
  end
1246
1311
  # arbitrary filters
1247
1312
  list_params.merge!(parse_query_options(options))
1248
-
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
1249
1318
  return list_params
1250
1319
  end
1251
1320
 
@@ -1366,7 +1435,7 @@ module Morpheus
1366
1435
  full_outfile = File.expand_path(options[:outfile])
1367
1436
  if output
1368
1437
  print_to_file(output, options[:outfile], options[:overwrite])
1369
- print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)} B)\n" unless options[:quiet]
1438
+ print "#{cyan}Wrote output to file #{options[:outfile]} (#{format_bytes(File.size(full_outfile))})\n" unless options[:quiet]
1370
1439
  else
1371
1440
  # uhhh ok lets try this
1372
1441
  Morpheus::Logging::DarkPrinter.puts "using experimental feature: --out without a common format like json, yml or csv" if Morpheus::Logging.debug?
@@ -1374,7 +1443,7 @@ module Morpheus
1374
1443
  if result && result != 0
1375
1444
  return result
1376
1445
  end
1377
- print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)} B)\n" unless options[:quiet]
1446
+ print "#{cyan}Wrote output to file #{options[:outfile]} (#{format_bytes(File.size(full_outfile))})\n" unless options[:quiet]
1378
1447
  return 0, nil
1379
1448
  end
1380
1449
  else
@@ -1405,6 +1474,184 @@ module Morpheus
1405
1474
 
1406
1475
  alias :render_with_format :render_response
1407
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 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
+
1408
1655
  module ClassMethods
1409
1656
 
1410
1657
  def prog_name
@@ -1412,14 +1659,14 @@ module Morpheus
1412
1659
  end
1413
1660
 
1414
1661
  def set_command_name(cmd_name)
1415
- @command_name = cmd_name
1662
+ @command_name = cmd_name.to_sym
1416
1663
  Morpheus::Cli::CliRegistry.add(self, self.command_name)
1417
1664
  end
1418
1665
 
1419
1666
  def default_command_name
1420
1667
  class_name = self.name.split('::')[-1]
1421
1668
  #class_name.sub!(/Command$/, '')
1422
- Morpheus::Cli::CliRegistry.cli_ize(class_name)
1669
+ Morpheus::Cli::CliRegistry.cli_ize(class_name).to_sym
1423
1670
  end
1424
1671
 
1425
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
@@ -297,7 +298,7 @@ module Morpheus
297
298
  every_command = cached_command_list
298
299
  guess = command_name
299
300
  suggestions = []
300
- while guess.size >= 3
301
+ while suggestions.empty? && guess.size >= 3
301
302
  plural_guess = guess.pluralize
302
303
  if every_command.include?(guess)
303
304
  suggestions << guess
@@ -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
- # "Remote" => lambda {|wallet| display_appliance(@appliance_name, @appliance_url) },
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
@@ -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:my_aliases.size,total:my_aliases.size.to_i})
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
@@ -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 :'prepare-apply' => :prepare_apply
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
- @users_interface = @api_client.users
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
@@ -901,9 +890,7 @@ This is only supported by certain types of apps.
901
890
  EOT
902
891
  end
903
892
  optparse.parse!(args)
904
- if args.count != 1
905
- raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
906
- end
893
+ verify_args!(args:args, optparse:optparse, count:1)
907
894
  connect(options)
908
895
 
909
896
  begin
@@ -928,65 +915,11 @@ EOT
928
915
  return
929
916
  end
930
917
  json_response = @apps_interface.refresh(app["id"], params, payload)
931
- render_result = render_with_format(json_response, options)
932
- return 0 if render_result
933
- print_green_success "Refreshed app #{app['name']}"
934
- return get([app['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
935
- rescue RestClient::Exception => e
936
- print_rest_exception(e, options)
937
- exit 1
938
- end
939
- end
940
-
941
- def prepare_apply(args)
942
- params, payload, options = {}, {}, {}
943
- optparse = Morpheus::Cli::OptionParser.new do |opts|
944
- opts.banner = subcommand_usage("[app] [options]")
945
- build_standard_update_options(opts, options, [:auto_confirm])
946
- opts.footer = <<-EOT
947
- Prepare to apply an app.
948
- [app] is required. This is the name or id of an app.
949
- Template parameter values can be applied with -O templateParameter.foo=bar
950
- This only prints the app configuration that would be applied.
951
- It does not make any updates.
952
- This is only supported by certain types of apps.
953
- EOT
954
- end
955
- optparse.parse!(args)
956
- if args.count != 1
957
- raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
958
- end
959
- connect(options)
960
-
961
- begin
962
- app = find_app_by_name_or_id(args[0])
963
- return 1 if app.nil?
964
- # construct request
965
- params.merge!(parse_query_options(options))
966
- payload = {}
967
- if options[:payload]
968
- payload = options[:payload]
969
- payload.deep_merge!(parse_passed_options(options))
970
- else
971
- payload.deep_merge!(parse_passed_options(options))
972
- # 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)
973
921
  end
974
- @apps_interface.setopts(options)
975
- if options[:dry_run]
976
- print_dry_run @apps_interface.dry.prepare_apply(app["id"], params, payload)
977
- return
978
- end
979
- json_response = @apps_interface.prepare_apply(app["id"], params, payload)
980
- render_result = render_with_format(json_response, options)
981
- return 0 if render_result
982
- # print_green_success "Prepared to apply app: #{app['name']}"
983
- print_h1 "Prepared App: #{app['name']}"
984
- app_config = json_response['data']
985
- # app_config = json_response if app_config.nil?
986
- puts as_yaml(app_config, options)
987
- #return get([app['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
988
- print "\n", reset
989
- return 0
922
+ return 0, nil
990
923
  rescue RestClient::Exception => e
991
924
  print_rest_exception(e, options)
992
925
  exit 1
@@ -1001,17 +934,11 @@ EOT
1001
934
  opts.footer = <<-EOT
1002
935
  Apply an app.
1003
936
  [app] is required. This is the name or id of an app.
1004
- Template parameter values can be applied with -O templateParameter.foo=bar
1005
- This is a way to apply an app with new configuration parameters to an app.
1006
- This prints the app configuration that would be applied.
1007
- It does not make any updates.
1008
- This is only supported by certain types of apps.
937
+ This is only supported by certain types of apps such as terraform.
1009
938
  EOT
1010
939
  end
1011
940
  optparse.parse!(args)
1012
- if args.count != 1
1013
- raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
1014
- end
941
+ verify_args!(args:args, optparse:optparse, count:1)
1015
942
  connect(options)
1016
943
 
1017
944
  begin
@@ -1036,11 +963,11 @@ EOT
1036
963
  return
1037
964
  end
1038
965
  json_response = @apps_interface.apply(app["id"], params, payload)
1039
- render_result = render_with_format(json_response, options)
1040
- return 0 if render_result
1041
- print_green_success "Applied app #{app['name']}"
1042
- #return get([app['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
1043
- 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
1044
971
  rescue RestClient::Exception => e
1045
972
  print_rest_exception(e, options)
1046
973
  exit 1
@@ -1,9 +1,3 @@
1
- require 'fileutils'
2
- require 'json'
3
- require 'yaml'
4
- require 'rest_client'
5
- require 'optparse'
6
- require 'filesize'
7
1
  require 'morpheus/cli/cli_command'
8
2
 
9
3
  class Morpheus::Cli::ArchivesCommand