morpheus-cli 5.3.4 → 5.4.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -57,9 +57,9 @@ module Morpheus::Cli::ProvisioningHelper
57
57
  @api_client.accounts
58
58
  end
59
59
 
60
- def get_available_groups(refresh=false)
60
+ def get_available_groups(params = {}, refresh=false)
61
61
  if !@available_groups || refresh
62
- option_results = options_interface.options_for_source('groups',{})
62
+ option_results = options_interface.options_for_source('groups', params)
63
63
  @available_groups = option_results['data'].collect {|it|
64
64
  {"id" => it["value"], "name" => it["name"], "value" => it["value"]}
65
65
  }
@@ -68,9 +68,9 @@ module Morpheus::Cli::ProvisioningHelper
68
68
  return @available_groups
69
69
  end
70
70
 
71
- def get_available_clouds(group_id, refresh=false)
71
+ def get_available_clouds(group_id, params = {}, refresh=false)
72
72
  if !group_id
73
- option_results = options_interface.options_for_source('clouds', {'default' => 'false'})
73
+ option_results = options_interface.options_for_source('clouds', params.merge({'default' => 'false'}))
74
74
  return option_results['data'].collect {|it|
75
75
  {"id" => it["value"], "name" => it["name"], "value" => it["value"], "zoneTypeId" => it["zoneTypeId"]}
76
76
  }
@@ -80,7 +80,7 @@ module Morpheus::Cli::ProvisioningHelper
80
80
  return []
81
81
  end
82
82
  if !group["clouds"] || refresh
83
- option_results = options_interface.options_for_source('clouds', {groupId: group_id})
83
+ option_results = options_interface.options_for_source('clouds', params.merge({groupId: group_id}))
84
84
  group["clouds"] = option_results['data'].collect {|it|
85
85
  {"id" => it["value"], "name" => it["name"], "value" => it["value"], "zoneTypeId" => it["zoneTypeId"]}
86
86
  }
@@ -484,7 +484,7 @@ module Morpheus::Cli::ProvisioningHelper
484
484
  if options[:instance_type_code]
485
485
  instance_type_code = options[:instance_type_code]
486
486
  else
487
- instance_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'optionSource' => 'instanceTypes', 'required' => true, 'description' => 'Select Instance Type.'}],options[:options],api_client,{groupId: group_id}, no_prompt, true)
487
+ instance_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'optionSource' => 'instanceTypes', 'required' => true, 'description' => 'Select Instance Type.'}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, restrictProvisionType:true}, no_prompt, true)
488
488
  instance_type_code = instance_type_prompt['type']
489
489
  end
490
490
  if instance_type_code.to_s =~ /\A\d{1,}\Z/
@@ -870,6 +870,12 @@ module Morpheus::Cli::ProvisioningHelper
870
870
  end
871
871
  end
872
872
 
873
+ # plan customizations
874
+ plan_opts = prompt_service_plan_options(service_plan, options, api_client, {zoneId: cloud_id, layoutId: layout['id'], siteId: group_id})
875
+ if plan_opts && !plan_opts.empty?
876
+ payload['servicePlanOptions'] = plan_opts
877
+ end
878
+
873
879
  # prompt networks
874
880
  if locked_fields.include?('networks')
875
881
  # payload['networkInterfaces'] = options[:options]['networkInterfaces'] if options[:options]['networkInterfaces']
@@ -942,6 +948,7 @@ module Morpheus::Cli::ProvisioningHelper
942
948
  # prompt for option types
943
949
  api_params['config'] = payload['config'] if payload['config']
944
950
  api_params['poolId'] = payload['config']['resourcePoolId'] if payload['config'] && payload['config']['resourcePoolId']
951
+ api_params['resourcePoolId'] = api_params['poolId']
945
952
 
946
953
  # set option type defaults from config
947
954
  if options[:default_config]
@@ -2093,6 +2100,15 @@ module Morpheus::Cli::ProvisioningHelper
2093
2100
  permissions
2094
2101
  end
2095
2102
 
2103
+ def prompt_permissions_v2(options, excludes = [])
2104
+ perms = prompt_permissions(options, excludes)
2105
+ rtn = {}
2106
+
2107
+ rtn['visibility'] = perms['resourcePool']['visibility'] if !perms['resourcePool'].nil?
2108
+ rtn['tenants'] = ((perms['tenantPermissions'] || {})['accounts'] || []).collect {|it| {'id' => it}}
2109
+ rtn
2110
+ end
2111
+
2096
2112
  def print_permissions(permissions, excludes = [])
2097
2113
  if permissions.nil?
2098
2114
  print_h2 "Permissions"
@@ -2230,6 +2246,80 @@ module Morpheus::Cli::ProvisioningHelper
2230
2246
  return ports
2231
2247
  end
2232
2248
 
2249
+ def prompt_service_plan_options(plan_info, options={}, api_client=nil, api_params={}, instance=nil)
2250
+ plan_opts = {}
2251
+ # provisioning with blueprint can lock fields
2252
+ locked_fields = options[:locked_fields] || []
2253
+ if options[:options]['servicePlanOptions']
2254
+ plan_opts = options[:options]['servicePlanOptions']
2255
+ end
2256
+ default_max_cores = plan_info['maxCores'].to_i != 0 ? plan_info['maxCores'] : 1
2257
+ default_cores_per_socket = plan_info['coresPerSocket'].to_i != 0 ? plan_info['coresPerSocket'] : 1
2258
+ default_max_memory = plan_info['maxMemory'].to_i != 0 ? plan_info['maxMemory'] : nil
2259
+ # use defaults from the instance/server
2260
+ if instance
2261
+ default_max_cores = instance["maxCores"] if instance["maxCores"]
2262
+ default_cores_per_socket = instance["coresPerSocket"] if instance["coresPerSocket"]
2263
+ default_max_memory = instance["maxMemory"] if instance["maxMemory"]
2264
+ end
2265
+ # Core Count
2266
+ if plan_info["customCores"]
2267
+ if locked_fields.include?('servicePlanOptions.maxCores')
2268
+ if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxCores']
2269
+ plan_opts['maxCores'] = options[:options]['servicePlanOptions']['maxCores'].to_i
2270
+ end
2271
+ else
2272
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'servicePlanOptions', 'fieldName' => 'maxCores', 'type' => 'number', 'fieldLabel' => "Core Count", 'required' => true, 'defaultValue' => default_max_cores, 'description' => "Customize service plan options Core Count"}], options[:options])
2273
+ if v_prompt['servicePlanOptions'] && v_prompt['servicePlanOptions']['maxCores']
2274
+ plan_opts['maxCores'] = v_prompt['servicePlanOptions']['maxCores'].to_i
2275
+ end
2276
+ end
2277
+ end
2278
+ # Cores Per Socket
2279
+ if plan_info["customCoresPerSocket"]
2280
+ if locked_fields.include?('servicePlanOptions.coresPerSocket')
2281
+ if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['coresPerSocket']
2282
+ plan_opts['coresPerSocket'] = options[:options]['servicePlanOptions']['coresPerSocket'].to_i
2283
+ end
2284
+ else
2285
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'servicePlanOptions', 'fieldName' => 'coresPerSocket', 'type' => 'number', 'fieldLabel' => "Cores Per Socket", 'required' => true, 'defaultValue' => default_cores_per_socket, 'description' => "Customize service plan options Cores Per Socket"}], options[:options])
2286
+ if v_prompt['servicePlanOptions'] && v_prompt['servicePlanOptions']['coresPerSocket']
2287
+ plan_opts['coresPerSocket'] = v_prompt['servicePlanOptions']['coresPerSocket'].to_i
2288
+ end
2289
+ end
2290
+ end
2291
+ # Memory
2292
+ if plan_info["customMaxMemory"]
2293
+ if locked_fields.include?('servicePlanOptions.maxMemory')
2294
+ if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxMemory']
2295
+ plan_opts['maxMemory'] = options[:options]['servicePlanOptions']['maxMemory'].to_i
2296
+ end
2297
+ else
2298
+ if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxMemory']
2299
+ plan_opts['maxMemory'] = options[:options]['servicePlanOptions']['maxMemory'].to_i
2300
+ else
2301
+ # prompt for "memoryMB" field as MB or "memoryGB" in GB
2302
+ # always convert maxMemory to bytes
2303
+ if plan_info["memorySizeType"] == "MB" || options[:options]["memoryMB"]
2304
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryMB', 'type' => 'text', 'fieldLabel' => "Memory (MB)", 'required' => true, 'defaultValue' => default_max_memory / (1024 * 1024), 'description' => "Customize service plan options Memory (MB). Value is in megabytes."}], options[:options])
2305
+ if v_prompt['memoryMB'].to_s != ""
2306
+ plan_opts['maxMemory'] = v_prompt['memoryMB'].to_i * 1024 * 1024
2307
+ end
2308
+ else
2309
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryGB', 'type' => 'text', 'fieldLabel' => "Memory (GB)", 'required' => true, 'defaultValue' => default_max_memory / (1024 * 1024 * 1024), 'description' => "Customize service plan options Memory (GB). Value is in gigabytes."}], options[:options])
2310
+ if v_prompt['memoryGB'].to_s != ""
2311
+ plan_opts['maxMemory'] = v_prompt['memoryGB'].to_i * 1024 * 1024 * 1024
2312
+ end
2313
+ end
2314
+ # remove transient memory field just used for prompting for MB or GB
2315
+ plan_opts.delete("memoryMB")
2316
+ plan_opts.delete("memoryGB")
2317
+ end
2318
+ end
2319
+ end
2320
+ return plan_opts
2321
+ end
2322
+
2233
2323
  def format_instance_status(instance, return_color=cyan)
2234
2324
  out = ""
2235
2325
  status_string = instance['status'].to_s
@@ -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 rest command resource eg. NeatThingsCommand would be "neat_things"
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
@@ -86,6 +86,22 @@ module Morpheus::Cli::RestCommand
86
86
 
87
87
  alias :set_rest_arg :rest_arg=
88
88
 
89
+ # rest_has_name indicates a resource has a name and can be retrieved by name or id
90
+ # true by default, set to false for lookups by only id
91
+ def rest_has_name
92
+ @rest_has_name != nil ? @rest_has_name : default_rest_has_name
93
+ end
94
+
95
+ def default_rest_has_name
96
+ true
97
+ end
98
+
99
+ def rest_has_name=(v)
100
+ @rest_has_name = !!v
101
+ end
102
+
103
+ alias :set_rest_has_name :rest_has_name=
104
+
89
105
  # rest_label is the capitalized resource label eg. "Neat Thing"
90
106
  def rest_label
91
107
  @rest_label || default_rest_label
@@ -297,6 +313,10 @@ module Morpheus::Cli::RestCommand
297
313
  self.class.rest_arg
298
314
  end
299
315
 
316
+ def rest_has_name
317
+ self.class.rest_has_name
318
+ end
319
+
300
320
  def rest_label
301
321
  self.class.rest_label
302
322
  end
@@ -316,23 +336,37 @@ module Morpheus::Cli::RestCommand
316
336
  end
317
337
 
318
338
  def rest_object_key
319
- self.send("#{rest_key}_object_key")
339
+ send("#{rest_key}_object_key")
320
340
  end
321
341
 
322
342
  def rest_list_key
323
- self.send("#{rest_key}_list_key")
343
+ send("#{rest_key}_list_key")
324
344
  end
325
345
 
326
- def rest_column_definitions
327
- self.send("#{rest_key}_column_definitions")
346
+ def rest_column_definitions(options)
347
+ send("#{rest_key}_column_definitions", options)
328
348
  end
329
349
 
330
- def rest_list_column_definitions
331
- self.send("#{rest_key}_list_column_definitions")
350
+ def rest_list_column_definitions(options)
351
+ send("#{rest_key}_list_column_definitions", options)
332
352
  end
333
353
 
334
- def rest_find_by_name_or_id(name)
335
- return self.send("find_#{rest_key}_by_name_or_id", name)
354
+ def rest_find_by_name_or_id(val)
355
+ # use explicitly defined finders
356
+ # else default to new generic CliCommand method to find anything by type (singular underscore)
357
+ if rest_has_name
358
+ if respond_to?("find_#{rest_key}_by_name_or_id", true)
359
+ send("find_#{rest_key}_by_name_or_id", val)
360
+ else
361
+ find_by_name_or_id(rest_key, val)
362
+ end
363
+ else
364
+ if respond_to?("find_#{rest_key}_by_id", true)
365
+ send("find_#{rest_key}_by_id", val)
366
+ else
367
+ find_by_id(rest_key, val)
368
+ end
369
+ end
336
370
  end
337
371
 
338
372
  def rest_has_type
@@ -353,6 +387,10 @@ module Morpheus::Cli::RestCommand
353
387
  self.class.rest_type_arg
354
388
  end
355
389
 
390
+ def rest_has_name
391
+ self.class.rest_type_arg
392
+ end
393
+
356
394
  def rest_type_label
357
395
  self.class.rest_type_label
358
396
  end
@@ -370,23 +408,29 @@ module Morpheus::Cli::RestCommand
370
408
  end
371
409
 
372
410
  def rest_type_object_key
373
- self.send("#{rest_type_key}_object_key")
411
+ send("#{rest_type_key}_object_key")
374
412
  end
375
413
 
376
414
  def rest_type_list_key
377
- self.send("#{rest_type_key}_list_key")
415
+ send("#{rest_type_key}_list_key")
378
416
  end
379
417
 
380
- def rest_type_column_definitions
381
- self.send("#{rest_type_key}_column_definitions")
418
+ def rest_type_column_definitions(options)
419
+ send("#{rest_type_key}_column_definitions", options)
382
420
  end
383
421
 
384
- def rest_type_list_column_definitions
385
- self.send("#{rest_type_key}_list_column_definitions")
422
+ def rest_type_list_column_definitions(options)
423
+ send("#{rest_type_key}_list_column_definitions", options)
386
424
  end
387
425
 
388
- def rest_type_find_by_name_or_id(name)
389
- return self.send("find_#{rest_type_key}_by_name_or_id", name)
426
+ def rest_type_find_by_name_or_id(val)
427
+ # use explicately defined finders
428
+ # else default to new generic CliCommand method to find anything by type (singular underscore)
429
+ if respond_to?("find_#{rest_type_key}_by_name_or_id", true)
430
+ send("find_#{rest_type_key}_by_name_or_id", val)
431
+ else
432
+ find_by_name_or_id(rest_type_key, val)
433
+ end
390
434
  end
391
435
 
392
436
  def registered_interfaces
@@ -417,18 +461,15 @@ module Morpheus::Cli::RestCommand
417
461
  options = {}
418
462
  optparse = Morpheus::Cli::OptionParser.new do |opts|
419
463
  opts.banner = subcommand_usage("[search]")
420
- build_standard_list_options(opts, options)
421
- opts.footer = <<-EOT
464
+ build_list_options(opts, options, params)
465
+ opts.footer = <<-EOT
422
466
  List #{rest_label_plural.downcase}.
423
467
  [search] is optional. This is a search phrase to filter the results.
424
468
  EOT
425
469
  end
426
470
  optparse.parse!(args)
427
471
  connect(options)
428
- if args.count > 0
429
- options[:phrase] = args.join(" ")
430
- end
431
- params.merge!(parse_list_options(options))
472
+ parse_list_options!(args, options, params)
432
473
  rest_interface.setopts(options)
433
474
  if options[:dry_run]
434
475
  print_dry_run rest_interface.dry.list(params)
@@ -441,7 +482,7 @@ EOT
441
482
  if records.nil? || records.empty?
442
483
  print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
443
484
  else
444
- print as_pretty_table(records, rest_list_column_definitions.upcase_keys!, options)
485
+ print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
445
486
  print_results_pagination(json_response) if json_response['meta']
446
487
  end
447
488
  print reset,"\n"
@@ -454,27 +495,25 @@ EOT
454
495
  options = {}
455
496
  optparse = Morpheus::Cli::OptionParser.new do |opts|
456
497
  opts.banner = subcommand_usage("[#{rest_arg}]")
457
- build_standard_get_options(opts, options)
498
+ build_get_options(opts, options, params)
458
499
  opts.footer = <<-EOT
459
500
  Get details about #{a_or_an(rest_label)} #{rest_label.downcase}.
460
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
501
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
461
502
  EOT
462
503
  end
463
504
  optparse.parse!(args)
464
505
  verify_args!(args:args, optparse:optparse, min:1)
465
506
  connect(options)
466
- params.merge!(parse_query_options(options))
467
- id_list = parse_id_list(args)
468
- return run_command_for_each_arg(id_list) do |arg|
469
- _get(arg, params, options)
470
- end
507
+ parse_get_options!(args, options, params)
508
+ id = args.join(" ")
509
+ _get(id, params, options)
471
510
  end
472
511
 
473
512
  def _get(id, params, options)
474
- if id !~ /\A\d{1,}\Z/
513
+ if id !~ /\A\d{1,}\Z/ && rest_has_name
475
514
  record = rest_find_by_name_or_id(id)
476
515
  if record.nil?
477
- raise_command_error "#{rest_label} not found for name '#{id}'"
516
+ return 1, "#{rest_label} not found for '#{id}'"
478
517
  end
479
518
  id = record['id']
480
519
  end
@@ -493,8 +532,14 @@ EOT
493
532
  record = json_response[rest_object_key]
494
533
  print_h1 rest_label, [], options
495
534
  print cyan
496
- print_description_list(rest_column_definitions, record, options)
497
- # show config settings...
535
+ print_description_list(rest_column_definitions(options), record, options)
536
+ # # could always show config eh? or maybe only with --config if that is nicer.
537
+ # # config = record['config'].is_a?(Hash) && !record['config'].empty?
538
+ # if config && !config.empty?
539
+ # print_h2 "Configuration"
540
+ # print_description_list(config.keys, config)
541
+ # end
542
+ # Option Types
498
543
  if record['optionTypes'] && record['optionTypes'].size > 0
499
544
  print_h2 "Option Types", options
500
545
  print format_option_types_table(record['optionTypes'], options, rest_object_key)
@@ -504,45 +549,52 @@ EOT
504
549
  end
505
550
 
506
551
  def add(args)
552
+ record_type = nil
507
553
  record_type_id = nil
508
554
  options = {}
555
+ option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
556
+ advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
557
+ type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
509
558
  optparse = Morpheus::Cli::OptionParser.new do |opts|
510
- if rest_has_type
511
- opts.banner = subcommand_usage("[#{rest_arg}] -t TYPE")
559
+ opts.banner = subcommand_usage("[#{rest_arg}]")
560
+ if rest_has_type && type_option_type.nil?
512
561
  opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
513
562
  record_type_id = val
514
563
  end
515
- else
516
- opts.banner = subcommand_usage("[#{rest_arg}]")
517
564
  end
518
- # if defined?(add_#{rest_key}_option_types)
519
- # build_option_type_options(opts, options, add_#{rest_key}_option_types)
520
- # end
565
+ build_option_type_options(opts, options, option_types)
566
+ build_option_type_options(opts, options, advanced_option_types)
521
567
  build_standard_add_options(opts, options)
522
568
  opts.footer = <<-EOT
523
569
  Create a new #{rest_label.downcase}.
524
570
  [#{rest_arg}] is required. This is the name of the new #{rest_label.downcase}.
525
571
  EOT
572
+ opts.footer += send "add_#{rest_key}_footer_addn" if respond_to?("add_#{rest_key}_footer_addn", true)
526
573
  end
527
574
  optparse.parse!(args)
528
575
  # todo: make supporting args[0] optional and more flexible
529
576
  # for now args[0] is assumed to be the 'name'
530
577
  record_name = nil
531
- if args[0] # && rest_has_name
532
- record_name = args[0]
533
- end
534
- verify_args!(args:args, optparse:optparse, min:0, max: 1)
535
- # todo: maybe need a flag to make this required, it could be an option type too, so
536
- if rest_has_type
537
- if record_type_id.nil?
538
- raise_command_error "#{rest_type_label} is required.\n#{optparse}"
578
+ if rest_has_name
579
+ if args.count > 0
580
+ record_name = args.join(" ")
539
581
  end
582
+ verify_args!(args:args, optparse:optparse, min:0, max: 1)
583
+ else
584
+ verify_args!(args:args, optparse:optparse, count: 0)
540
585
  end
541
586
  connect(options)
542
- if rest_has_type
587
+ # load or prompt for type
588
+ if rest_has_type && type_option_type.nil?
589
+ if record_type_id.nil?
590
+ #raise_command_error "#{rest_type_label} is required.\n#{optparse}"
591
+ type_list = rest_type_interface.list({max:10000, creatable:true})[rest_type_list_key]
592
+ type_dropdown_options = respond_to?("#{rest_key}_type_list_to_options", true) ? send("#{rest_key}_type_list_to_options", type_list) : type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
593
+ 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']
594
+ end
543
595
  record_type = rest_type_find_by_name_or_id(record_type_id)
544
596
  if record_type.nil?
545
- raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
597
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
546
598
  end
547
599
  end
548
600
  passed_options = parse_passed_options(options)
@@ -557,13 +609,40 @@ EOT
557
609
  options[:options]['name'] = record_name # injected for prompt
558
610
  end
559
611
  if rest_has_type && record_type
560
- # record_payload['type'] = {'code' => record_type['code']}
612
+ # inject type to options for prompting
561
613
  record_payload['type'] = record_type['code']
562
- options[:options]['type'] = record_type['code'] # injected for prompt
614
+ options[:options]['type'] = record_type['code']
615
+ # initialize params for loading optionSource data
616
+ options[:params] ||= {}
617
+ options[:params]['type'] = record_type['code']
563
618
  end
564
619
  record_payload.deep_merge!(passed_options)
620
+ if option_types && !option_types.empty?
621
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
622
+ v_prompt.deep_compact!
623
+ v_prompt.booleanize! # 'on' => true
624
+ record_payload.deep_merge!(v_prompt)
625
+ end
565
626
  # options by type
566
- my_option_types = record_type ? record_type['optionTypes'] : nil
627
+ if rest_has_type && record_type.nil?
628
+ type_value = record_payload['type'].is_a?(Hash) ? record_payload['type']['id'] : record_payload['type']
629
+ if type_value
630
+ record_type = rest_type_find_by_name_or_id(type_value)
631
+ if record_type.nil?
632
+ return 1, "#{rest_type_label} not found for '#{type_value}"
633
+ end
634
+ end
635
+ # reload the type by id to get all the details ie. optionTypes
636
+ if record_type && record_type['optionTypes'].nil?
637
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
638
+ end
639
+ end
640
+ my_option_types = nil
641
+ if respond_to?("load_option_types_for_#{rest_key}", true)
642
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
643
+ else
644
+ my_option_types = record_type ? record_type['optionTypes'] : nil
645
+ end
567
646
  if my_option_types && !my_option_types.empty?
568
647
  # remove redundant fieldContext
569
648
  my_option_types.each do |option_type|
@@ -571,7 +650,15 @@ EOT
571
650
  option_type['fieldContext'] = nil
572
651
  end
573
652
  end
574
- v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, options[:params])
653
+ api_params = (options[:params] || {}).merge(record_payload)
654
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, api_params)
655
+ v_prompt.deep_compact!
656
+ v_prompt.booleanize! # 'on' => true
657
+ record_payload.deep_merge!(v_prompt)
658
+ end
659
+ # advanced options (uses no_prompt)
660
+ if advanced_option_types && !advanced_option_types.empty?
661
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
575
662
  v_prompt.deep_compact!
576
663
  v_prompt.booleanize! # 'on' => true
577
664
  record_payload.deep_merge!(v_prompt)
@@ -594,28 +681,101 @@ EOT
594
681
 
595
682
  def update(args)
596
683
  id = args[0]
684
+ record_type = nil
685
+ record_type_id = nil
597
686
  options = {}
598
- params = {}
599
- account_name = nil
687
+ option_types = respond_to?("update_#{rest_key}_option_types", true) ? send("update_#{rest_key}_option_types") : []
688
+ advanced_option_types = respond_to?("update_#{rest_key}_advanced_option_types", true) ? send("update_#{rest_key}_advanced_option_types") : []
600
689
  optparse = Morpheus::Cli::OptionParser.new do |opts|
601
690
  opts.banner = subcommand_usage("[#{rest_arg}] [options]")
691
+ build_option_type_options(opts, options, option_types)
692
+ build_option_type_options(opts, options, advanced_option_types)
602
693
  build_standard_update_options(opts, options)
603
694
  opts.footer = <<-EOT
604
695
  Update an existing #{rest_label.downcase}.
605
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
696
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
606
697
  EOT
698
+ opts.footer += send "update_#{rest_key}_footer_addn" if respond_to?("update_#{rest_key}_footer_addn", true)
607
699
  end
608
700
  optparse.parse!(args)
609
701
  verify_args!(args:args, optparse:optparse, count:1)
610
702
  connect(options)
611
703
  record = rest_find_by_name_or_id(id)
704
+ if record.nil?
705
+ return 1, "#{rest_name} not found for '#{id}'"
706
+ end
707
+ # load type so we can prompt for those option types
708
+ if rest_has_type
709
+ record_type_id = record['type']['id']
710
+ record_type = rest_type_find_by_name_or_id(record_type_id)
711
+ if record_type.nil?
712
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
713
+ end
714
+ # reload the type by id to get all the details ie. optionTypes
715
+ if record_type['optionTypes'].nil?
716
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
717
+ end
718
+ end
612
719
  passed_options = parse_passed_options(options)
613
- payload = nil
720
+ payload = {}
614
721
  if options[:payload]
615
722
  payload = options[:payload]
616
723
  payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
617
724
  else
618
725
  record_payload = passed_options
726
+ if rest_has_type && record_type
727
+ # inject type to options for prompting
728
+ # record_payload['type'] = record_type['code']
729
+ # options[:options]['type'] = record_type['code']
730
+ # initialize params for loading optionSource data
731
+ options[:params] ||= {}
732
+ options[:params]['type'] = record_type['code']
733
+ end
734
+ # update options without prompting by default
735
+ if option_types && !option_types.empty?
736
+ api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
737
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(option_types, options[:options], @api_client, api_params)
738
+ v_prompt.deep_compact!
739
+ v_prompt.booleanize! # 'on' => true
740
+ record_payload.deep_merge!(v_prompt)
741
+ end
742
+ # options by type
743
+ my_option_types = nil
744
+ if respond_to?("load_option_types_for_#{rest_key}", true)
745
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
746
+ else
747
+ my_option_types = record_type ? record_type['optionTypes'] : nil
748
+ end
749
+ if my_option_types && !my_option_types.empty?
750
+ # remove redundant fieldContext
751
+ # make them optional for updates
752
+ # todo: use current value as default instead of just making things optioanl
753
+ # maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
754
+ my_option_types.each do |option_type|
755
+ if option_type['fieldContext'] == rest_object_key
756
+ option_type['fieldContext'] = nil
757
+ end
758
+ option_type.delete('required')
759
+ option_type.delete('defaultValue')
760
+ end
761
+ api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
762
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, api_params)
763
+ v_prompt.deep_compact!
764
+ v_prompt.booleanize! # 'on' => true
765
+ record_payload.deep_merge!(v_prompt)
766
+ end
767
+ # advanced options
768
+ if advanced_option_types && !advanced_option_types.empty?
769
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
770
+ v_prompt.deep_compact!
771
+ v_prompt.booleanize! # 'on' => true
772
+ record_payload.deep_merge!(v_prompt)
773
+ end
774
+ # remove empty config, compact could hanlde this
775
+ if record_payload['config'] && record_payload['config'].empty?
776
+ record_payload.delete('config')
777
+ end
778
+ # prevent updating with empty payload
619
779
  if record_payload.empty?
620
780
  raise_command_error "Specify at least one option to update.\n#{optparse}"
621
781
  end
@@ -643,7 +803,7 @@ EOT
643
803
  build_standard_remove_options(opts, options)
644
804
  opts.footer = <<-EOT
645
805
  Delete an existing #{rest_label.downcase}.
646
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
806
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
647
807
  EOT
648
808
  end
649
809
  optparse.parse!(args)
@@ -659,7 +819,7 @@ EOT
659
819
  end
660
820
  rest_interface.setopts(options)
661
821
  if options[:dry_run]
662
- print_dry_run rest_interface.dry.destroy(record['id'])
822
+ print_dry_run rest_interface.dry.destroy(record['id'], params)
663
823
  return 0, nil
664
824
  end
665
825
  json_response = rest_interface.destroy(record['id'], params)