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
@@ -85,6 +85,37 @@ module Morpheus::Cli::SecondaryRestCommand
85
85
 
86
86
  alias :set_rest_parent_arg :rest_parent_arg=
87
87
 
88
+ def rest_parent_param
89
+ @rest_parent_param || default_rest_parent_param
90
+ end
91
+
92
+ def default_rest_parent_param
93
+ param = rest_parent_key.to_s.split('_').collect(&:capitalize).join
94
+ "#{param[0].downcase}#{param[1..-1]}Id"
95
+ end
96
+
97
+ def rest_parent_param=(v)
98
+ @rest_parent_param = v.to_s
99
+ end
100
+
101
+ alias :set_rest_parent_param :rest_parent_param=
102
+
103
+ # rest_parent_has_name indicates a resource has a name and can be retrieved by name or id
104
+ # true by default, set to false for lookups by only id
105
+ def rest_parent_has_name
106
+ @rest_parent_has_name != nil ? @rest_parent_has_name : default_rest_parent_has_name
107
+ end
108
+
109
+ def default_rest_parent_has_name
110
+ true
111
+ end
112
+
113
+ def rest_parent_has_name=(v)
114
+ @rest_parent_has_name = !!v
115
+ end
116
+
117
+ alias :set_rest_parent_has_name :rest_parent_has_name=
118
+
88
119
  # rest_parent_label is the capitalized resource label eg. "Neat Thing"
89
120
  def rest_parent_label
90
121
  @rest_parent_label || default_rest_parent_label
@@ -147,6 +178,14 @@ module Morpheus::Cli::SecondaryRestCommand
147
178
  self.class.rest_parent_arg
148
179
  end
149
180
 
181
+ def rest_parent_param
182
+ self.class.rest_parent_param
183
+ end
184
+
185
+ def rest_parent_has_name
186
+ self.class.rest_parent_has_name
187
+ end
188
+
150
189
  def rest_parent_label
151
190
  self.class.rest_parent_label
152
191
  end
@@ -164,23 +203,56 @@ module Morpheus::Cli::SecondaryRestCommand
164
203
  end
165
204
 
166
205
  def rest_parent_object_key
167
- self.send("#{rest_parent_key}_object_key")
206
+ send("#{rest_parent_key}_object_key")
168
207
  end
169
208
 
170
209
  def rest_parent_list_key
171
- self.send("#{rest_parent_key}_list_key")
210
+ send("#{rest_parent_key}_list_key")
172
211
  end
173
212
 
174
- def rest_parent_column_definitions
175
- self.send("#{rest_parent_key}_column_definitions")
213
+ def rest_parent_column_definitions(options)
214
+ send("#{rest_parent_key}_column_definitions", options)
176
215
  end
177
216
 
178
- def rest_parent_list_column_definitions
179
- self.send("#{rest_parent_key}_list_column_definitions")
217
+ def rest_parent_list_column_definitions(options)
218
+ send("#{rest_parent_key}_list_column_definitions", options)
180
219
  end
181
220
 
182
- def rest_parent_find_by_name_or_id(name)
183
- return self.send("find_#{rest_parent_key}_by_name_or_id", name)
221
+ def rest_parent_find_by_name_or_id(val)
222
+ # use explicitly defined finders
223
+ # else default to new generic CliCommand find_by methods
224
+ if rest_parent_has_name
225
+ if respond_to?("find_#{rest_parent_key}_by_name_or_id", true)
226
+ send("find_#{rest_parent_key}_by_name_or_id", val)
227
+ else
228
+ find_by_name_or_id(rest_parent_key, val)
229
+ end
230
+ else
231
+ if respond_to?("find_#{rest_parent_key}_by_id", true)
232
+ send("find_#{rest_parent_key}_by_id", val)
233
+ else
234
+ find_by_id(rest_parent_key, val)
235
+ end
236
+ end
237
+ end
238
+
239
+ # override RestCommand method to include parent_id parameter
240
+ def rest_find_by_name_or_id(parent_id, val)
241
+ # use explicitly defined finders
242
+ # else default to new generic CliCommand find_by methods
243
+ if rest_has_name
244
+ if respond_to?("find_#{rest_key}_by_name_or_id", true)
245
+ send("find_#{rest_key}_by_name_or_id", parent_id, val)
246
+ else
247
+ find_by_name_or_id(rest_key, parent_id, val)
248
+ end
249
+ else
250
+ if respond_to?("find_#{rest_key}_by_id", true)
251
+ send("find_#{rest_key}_by_id", parent_id, val)
252
+ else
253
+ find_by_id(rest_key, parent_id, val)
254
+ end
255
+ end
184
256
  end
185
257
 
186
258
  def registered_interfaces
@@ -193,29 +265,23 @@ module Morpheus::Cli::SecondaryRestCommand
193
265
  options = {}
194
266
  optparse = Morpheus::Cli::OptionParser.new do |opts|
195
267
  opts.banner = subcommand_usage("[#{rest_parent_arg}] [search]")
196
- build_standard_list_options(opts, options)
268
+ build_list_options(opts, options, params)
197
269
  opts.footer = <<-EOT
198
270
  List #{rest_label_plural.downcase}.
199
- [#{rest_parent_arg}] is required. This is the name or id of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
271
+ [#{rest_parent_arg}] is required. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
200
272
  [search] is optional. This is a search phrase to filter the results.
201
273
  EOT
202
274
  end
203
275
  optparse.parse!(args)
204
- parent_id = args[0]
205
- if args[1] # && rest_has_name
206
- record_name = args[1]
207
- end
208
276
  verify_args!(args:args, optparse:optparse, min:1)
209
- if args.count > 1
210
- options[:phrase] = args[1..-1].join(" ")
211
- end
212
277
  connect(options)
278
+ parent_id = args[0]
213
279
  parent_record = rest_parent_find_by_name_or_id(parent_id)
214
280
  if parent_record.nil?
215
- raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
281
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
216
282
  end
217
283
  parent_id = parent_record['id']
218
- params.merge!(parse_list_options(options))
284
+ parse_list_options!(args.count > 1 ? args[1..-1] : [], options, params)
219
285
  rest_interface.setopts(options)
220
286
  if options[:dry_run]
221
287
  print_dry_run rest_interface.dry.list(parent_id, params)
@@ -228,7 +294,7 @@ EOT
228
294
  if records.nil? || records.empty?
229
295
  print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
230
296
  else
231
- print as_pretty_table(records, rest_list_column_definitions.upcase_keys!, options)
297
+ print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
232
298
  print_results_pagination(json_response) if json_response['meta']
233
299
  end
234
300
  print reset,"\n"
@@ -241,43 +307,41 @@ EOT
241
307
  options = {}
242
308
  optparse = Morpheus::Cli::OptionParser.new do |opts|
243
309
  opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}]")
244
- build_standard_get_options(opts, options)
310
+ build_get_options(opts, options, params)
245
311
  opts.footer = <<-EOT
246
312
  Get details about #{a_or_an(rest_label)} #{rest_label.downcase}.
247
- [#{rest_parent_arg}] is required. This is the name or id of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
248
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
313
+ [#{rest_parent_arg}] is required. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
314
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
249
315
  EOT
250
316
  end
251
317
  optparse.parse!(args)
252
318
  verify_args!(args:args, optparse:optparse, min:2)
253
319
  connect(options)
320
+ parse_get_options!(args.count > 1 ? args[1..-1] : [], options, params)
254
321
  parent_id = args[0]
255
322
  parent_record = rest_parent_find_by_name_or_id(parent_id)
256
323
  if parent_record.nil?
257
- raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
324
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
258
325
  end
259
326
  parent_id = parent_record['id']
260
- params.merge!(parse_query_options(options))
261
- id_list = parse_id_list(args[1..-1])
262
- return run_command_for_each_arg(id_list) do |arg|
263
- _get(parent_id, arg, params, options)
264
- end
327
+ id = args[1..-1].join(" ")
328
+ _get(parent_id, id, params, options)
265
329
  end
266
330
 
267
331
  def _get(parent_id, id, params, options)
268
332
  if id !~ /\A\d{1,}\Z/
269
- record = rest_find_by_name_or_id(id)
333
+ record = rest_find_by_name_or_id(parent_id, id)
270
334
  if record.nil?
271
- raise_command_error "#{rest_label} not found for name '#{id}'"
335
+ return 1, "#{rest_label} not found for '#{id}"
272
336
  end
273
337
  id = record['id']
274
338
  end
275
339
  rest_interface.setopts(options)
276
340
  if options[:dry_run]
277
- print_dry_run rest_interface.dry.get(id, params)
341
+ print_dry_run rest_interface.dry.get(parent_id, id, params)
278
342
  return
279
343
  end
280
- json_response = rest_interface.get(id, params)
344
+ json_response = rest_interface.get(parent_id, id, params)
281
345
  render_response_for_get(json_response, options)
282
346
  return 0, nil
283
347
  end
@@ -287,7 +351,7 @@ EOT
287
351
  record = json_response[rest_object_key]
288
352
  print_h1 rest_label, [], options
289
353
  print cyan
290
- print_description_list(rest_column_definitions, record, options)
354
+ print_description_list(rest_column_definitions(options), record, options)
291
355
  # show config settings...
292
356
  if record['optionTypes'] && record['optionTypes'].size > 0
293
357
  print_h2 "Option Types", options
@@ -301,22 +365,22 @@ EOT
301
365
  parent_id, parent_record = nil, nil
302
366
  record_type_id = nil
303
367
  options = {}
368
+ option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
369
+ advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
370
+ type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
304
371
  optparse = Morpheus::Cli::OptionParser.new do |opts|
305
- if rest_has_type
306
- opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}] -t TYPE")
372
+ opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}]")
373
+ if rest_has_type && type_option_type.nil?
307
374
  opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
308
375
  record_type_id = val
309
376
  end
310
- else
311
- opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}]")
312
377
  end
313
- # if defined?(add_#{rest_key}_option_types)
314
- # build_option_type_options(opts, options, add_#{rest_key}_option_types)
315
- # end
378
+ build_option_type_options(opts, options, option_types)
379
+ build_option_type_options(opts, options, advanced_option_types)
316
380
  build_standard_add_options(opts, options)
317
381
  opts.footer = <<-EOT
318
382
  Create a new #{rest_label.downcase}.
319
- [#{rest_parent_arg}] is required. This is the name or id of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
383
+ [#{rest_parent_arg}] is required. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
320
384
  [#{rest_arg}] is required. This is the name of the new #{rest_label.downcase}.
321
385
  EOT
322
386
  end
@@ -326,28 +390,39 @@ EOT
326
390
  # for now args[0] is assumed to be the 'name'
327
391
  record_name = nil
328
392
  parent_id = args[0]
329
- if args[1] # && rest_has_name
330
- record_name = args[1]
331
- end
332
- # todo: maybe need a flag to make this required, it could be an option type too, so
333
- if rest_has_type
334
- if record_type_id.nil?
335
- raise_command_error "#{rest_type_label} is required.\n#{optparse}"
393
+ if rest_has_name
394
+ if args[1]
395
+ record_name = args[1]
336
396
  end
397
+ verify_args!(args:args, optparse:optparse, min:1, max: 2)
398
+ else
399
+ verify_args!(args:args, optparse:optparse, count: 1)
337
400
  end
338
401
  connect(options)
339
- if rest_has_type
340
- record_type = rest_type_find_by_name_or_id(record_type_id)
341
- if record_type.nil?
342
- raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
343
- end
344
- end
402
+ # load parent record
403
+ # todo: prompt instead of error
345
404
  parent_record = rest_parent_find_by_name_or_id(parent_id)
346
405
  if parent_record.nil?
347
- raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
406
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
348
407
  end
349
408
  parent_id = parent_record['id']
409
+ # load or prompt for type
410
+ if rest_has_type && type_option_type.nil?
411
+ if record_type_id.nil?
412
+ #raise_command_error "#{rest_type_label} is required.\n#{optparse}"
413
+ type_list = rest_type_interface.list({max:10000, creatable: true})[rest_type_list_key]
414
+ type_dropdown_options = type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
415
+ 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']
416
+ end
417
+ record_type = rest_type_find_by_name_or_id(record_type_id)
418
+ if record_type.nil?
419
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
420
+ end
421
+ end
350
422
  passed_options = parse_passed_options(options)
423
+ options[:params] ||= {}
424
+ options[:params][rest_parent_param] = parent_id
425
+ options[:options]['_object_key'] = rest_object_key
351
426
  payload = {}
352
427
  if options[:payload]
353
428
  payload = options[:payload]
@@ -357,15 +432,41 @@ EOT
357
432
  if record_name
358
433
  record_payload['name'] = record_name
359
434
  options[:options]['name'] = record_name # injected for prompt
435
+ options[:options][rest_arg] = record_name
360
436
  end
361
437
  if rest_has_type && record_type
362
438
  # record_payload['type'] = {'code' => record_type['code']}
363
439
  record_payload['type'] = record_type['code']
364
440
  options[:options]['type'] = record_type['code'] # injected for prompt
441
+ # initialize params for loading optionSource data
442
+ options[:params]['type'] = record_type['code']
365
443
  end
366
444
  record_payload.deep_merge!(passed_options)
445
+ if option_types && !option_types.empty?
446
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
447
+ v_prompt.deep_compact!
448
+ v_prompt.booleanize! # 'on' => true
449
+ record_payload.deep_merge!(v_prompt)
450
+ end
367
451
  # options by type
368
- my_option_types = record_type ? record_type['optionTypes'] : nil
452
+ if rest_has_type && record_type.nil?
453
+ type_value = record_payload['type'].is_a?(Hash) ? record_payload['type']['id'] : record_payload['type']
454
+ if type_value
455
+ record_type = rest_type_find_by_name_or_id(type_value)
456
+ if record_type.nil?
457
+ return 1, "#{rest_type_label} not found for '#{type_value}"
458
+ end
459
+ end
460
+ # reload the type by id to get all the details ie. optionTypes
461
+ if record_type && record_type['optionTypes'].nil?
462
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
463
+ end
464
+ end
465
+ if respond_to?("load_option_types_for_#{rest_key}", true)
466
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, parent_record)
467
+ else
468
+ my_option_types = record_type ? record_type['optionTypes'] : nil
469
+ end
369
470
  if my_option_types && !my_option_types.empty?
370
471
  # remove redundant fieldContext
371
472
  my_option_types.each do |option_type|
@@ -373,7 +474,15 @@ EOT
373
474
  option_type['fieldContext'] = nil
374
475
  end
375
476
  end
376
- v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, options[:params])
477
+ api_params = (options[:params] || {}).merge(record_payload)
478
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, api_params)
479
+ v_prompt.deep_compact!
480
+ v_prompt.booleanize! # 'on' => true
481
+ record_payload.deep_merge!(v_prompt)
482
+ end
483
+ # advanced options (uses no_prompt)
484
+ if advanced_option_types && !advanced_option_types.empty?
485
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
377
486
  v_prompt.deep_compact!
378
487
  v_prompt.booleanize! # 'on' => true
379
488
  record_payload.deep_merge!(v_prompt)
@@ -397,34 +506,104 @@ EOT
397
506
  def update(args)
398
507
  parent_id = args[0]
399
508
  id = args[1]
509
+ record_type = nil
510
+ record_type_id = nil
400
511
  options = {}
401
- params = {}
402
- account_name = nil
512
+ option_types = respond_to?("update_#{rest_key}_option_types", true) ? send("update_#{rest_key}_option_types") : []
513
+ advanced_option_types = respond_to?("update_#{rest_key}_advanced_option_types", true) ? send("update_#{rest_key}_advanced_option_types") : []
403
514
  optparse = Morpheus::Cli::OptionParser.new do |opts|
404
515
  opts.banner = subcommand_usage("[#{rest_parent_arg}] [#{rest_arg}] [options]")
405
516
  build_standard_update_options(opts, options)
406
517
  opts.footer = <<-EOT
407
518
  Update an existing #{rest_label.downcase}.
408
- [#{rest_parent_arg}] is required. This is the name or id of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
409
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
519
+ [#{rest_parent_arg}] is required. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
520
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
410
521
  EOT
411
522
  end
412
523
  optparse.parse!(args)
413
524
  verify_args!(args:args, optparse:optparse, count:2)
525
+ connect(options)
414
526
  parent_record = rest_parent_find_by_name_or_id(parent_id)
415
527
  if parent_record.nil?
416
- raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
528
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
417
529
  end
418
530
  parent_id = parent_record['id']
419
531
  connect(options)
420
- record = rest_find_by_name_or_id(id)
532
+ record = rest_find_by_name_or_id(parent_id, id)
533
+ if record.nil?
534
+ return 1, "#{rest_name} not found for '#{id}'"
535
+ end
536
+ # load type so we can prompt for those option types
537
+ if rest_has_type
538
+ record_type_id = record['type']['id']
539
+ record_type = rest_type_find_by_name_or_id(record_type_id)
540
+ if record_type.nil?
541
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
542
+ end
543
+ # reload the type by id to get all the details ie. optionTypes
544
+ if record_type['optionTypes'].nil?
545
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
546
+ end
547
+ end
421
548
  passed_options = parse_passed_options(options)
422
- payload = nil
549
+ payload = {}
423
550
  if options[:payload]
424
551
  payload = options[:payload]
425
552
  payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
426
553
  else
427
554
  record_payload = passed_options
555
+ if rest_has_type && record_type
556
+ # inject type to options for prompting
557
+ # record_payload['type'] = record_type['code']
558
+ # options[:options]['type'] = record_type['code']
559
+ # initialize params for loading optionSource data
560
+ options[:params] ||= {}
561
+ options[:params]['type'] = record_type['code']
562
+ end
563
+ # update options without prompting by default
564
+ if false && option_types && !option_types.empty?
565
+ api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
566
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(option_types, options[:options], @api_client, api_params)
567
+ v_prompt.deep_compact!
568
+ v_prompt.booleanize! # 'on' => true
569
+ record_payload.deep_merge!(v_prompt)
570
+ end
571
+ # options by type
572
+ my_option_types = nil
573
+ if respond_to?("load_option_types_for_#{rest_key}", true)
574
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, parent_record)
575
+ else
576
+ my_option_types = record_type ? record_type['optionTypes'] : nil
577
+ end
578
+ if false && my_option_types && !my_option_types.empty?
579
+ # remove redundant fieldContext
580
+ # make them optional for updates
581
+ # todo: use current value as default instead of just making things optioanl
582
+ # maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
583
+ my_option_types.each do |option_type|
584
+ if option_type['fieldContext'] == rest_object_key
585
+ option_type['fieldContext'] = nil
586
+ end
587
+ option_type.delete('required')
588
+ option_type.delete('defaultValue')
589
+ end
590
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, options[:params])
591
+ v_prompt.deep_compact!
592
+ v_prompt.booleanize! # 'on' => true
593
+ record_payload.deep_merge!(v_prompt)
594
+ end
595
+ # advanced options
596
+ if false && advanced_option_types && !advanced_option_types.empty?
597
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
598
+ v_prompt.deep_compact!
599
+ v_prompt.booleanize! # 'on' => true
600
+ record_payload.deep_merge!(v_prompt)
601
+ end
602
+ # remove empty config, compact could hanlde this
603
+ if record_payload['config'] && record_payload['config'].empty?
604
+ record_payload.delete('config')
605
+ end
606
+ # prevent updating with empty payload
428
607
  if record_payload.empty?
429
608
  raise_command_error "Specify at least one option to update.\n#{optparse}"
430
609
  end
@@ -453,8 +632,8 @@ EOT
453
632
  build_standard_remove_options(opts, options)
454
633
  opts.footer = <<-EOT
455
634
  Delete an existing #{rest_label.downcase}.
456
- [#{rest_parent_arg}] is required. This is the name or id of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
457
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
635
+ [#{rest_parent_arg}] is required. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
636
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
458
637
  EOT
459
638
  end
460
639
  optparse.parse!(args)
@@ -462,9 +641,9 @@ EOT
462
641
  connect(options)
463
642
  parent_record = rest_parent_find_by_name_or_id(parent_id)
464
643
  if parent_record.nil?
465
- raise_command_error "#{rest_parent_label} not found for '#{parent_id}'.\n#{optparse}"
644
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
466
645
  end
467
- record = rest_find_by_name_or_id(id)
646
+ record = rest_find_by_name_or_id(parent_record['id'], id)
468
647
  if record.nil?
469
648
  return 1, "#{rest_name} not found for '#{id}'"
470
649
  end
@@ -474,7 +653,7 @@ EOT
474
653
  params.merge!(parse_query_options(options))
475
654
  rest_interface.setopts(options)
476
655
  if options[:dry_run]
477
- print_dry_run rest_interface.dry.destroy(parent_id, record['id'])
656
+ print_dry_run rest_interface.dry.destroy(parent_id, record['id'], params)
478
657
  return 0, nil
479
658
  end
480
659
  json_response = rest_interface.destroy(parent_id, record['id'], params)
@@ -0,0 +1,156 @@
1
+ require 'morpheus/cli/mixins/print_helper'
2
+ require 'morpheus/cli/option_types'
3
+ require 'morpheus/rest_client'
4
+ # Mixin for Morpheus::Cli command classes
5
+ # Provides common methods for storage server management
6
+ # including storage servers and storage server types
7
+ module Morpheus::Cli::StorageServersHelper
8
+
9
+ def self.included(klass)
10
+ klass.send :include, Morpheus::Cli::PrintHelper
11
+ end
12
+
13
+ def storage_servers_interface
14
+ # @api_client.storage_servers
15
+ raise "#{self.class} has not defined @storage_servers_interface" if @storage_servers_interface.nil?
16
+ @storage_servers_interface
17
+ end
18
+
19
+ def storage_server_types_interface
20
+ # @api_client.storage_server_types
21
+ raise "#{self.class} has not defined @storage_server_types_interface" if @storage_server_types_interface.nil?
22
+ @storage_server_types_interface
23
+ end
24
+
25
+ def storage_server_object_key
26
+ 'storageServer'
27
+ end
28
+
29
+ def storage_server_list_key
30
+ 'storageServers'
31
+ end
32
+
33
+ def storage_server_label
34
+ 'Storage Server'
35
+ end
36
+
37
+ def storage_server_label_plural
38
+ 'Storage Server'
39
+ end
40
+
41
+ def storage_server_type_object_key
42
+ 'storageServerType'
43
+ end
44
+
45
+ def storage_server_type_list_key
46
+ 'storageServerTypes'
47
+ end
48
+
49
+ def storage_server_type_label
50
+ 'Storage Server Type'
51
+ end
52
+
53
+ def storage_server_type_label_plural
54
+ 'Storage Server Types'
55
+ end
56
+
57
+ def find_storage_server_by_name_or_id(val)
58
+ if val.to_s =~ /\A\d{1,}\Z/
59
+ return find_storage_server_by_id(val)
60
+ else
61
+ return find_storage_server_by_name(val)
62
+ end
63
+ end
64
+
65
+ def find_storage_server_by_id(id)
66
+ begin
67
+ json_response = storage_servers_interface.get(id.to_i)
68
+ return json_response[storage_server_object_key]
69
+ rescue RestClient::Exception => e
70
+ if e.response && e.response.code == 404
71
+ print_red_alert "Storage Server not found by id #{id}"
72
+ else
73
+ raise e
74
+ end
75
+ end
76
+ end
77
+
78
+ def find_storage_server_by_name(name)
79
+ lbs = storage_servers_interface.list({name: name.to_s})[storage_server_list_key]
80
+ if lbs.empty?
81
+ print_red_alert "Storage Server not found by name #{name}"
82
+ return nil
83
+ elsif lbs.size > 1
84
+ print_red_alert "#{lbs.size} storage servers found by name #{name}"
85
+ #print_lbs_table(lbs, {color: red})
86
+ print reset,"\n\n"
87
+ return nil
88
+ else
89
+ return lbs[0]
90
+ end
91
+ end
92
+
93
+ def get_available_storage_server_types(refresh=false)
94
+ if !@available_storage_server_types || refresh
95
+ @available_storage_server_types = storage_server_types_interface.list({max:1000})[storage_server_type_list_key]
96
+ end
97
+ return @available_storage_server_types
98
+ end
99
+
100
+ def storage_server_type_for_name_or_id(val)
101
+ if val.to_s =~ /\A\d{1,}\Z/
102
+ return storage_server_type_for_id(val)
103
+ else
104
+ return storage_server_type_for_name(val)
105
+ end
106
+ end
107
+
108
+ def storage_server_type_for_id(id)
109
+ return get_available_storage_server_types().find { |z| z['id'].to_i == id.to_i}
110
+ end
111
+
112
+ def storage_server_type_for_name(name)
113
+ return get_available_storage_server_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
114
+ end
115
+
116
+ def find_storage_server_type_by_name_or_id(val)
117
+ if val.to_s =~ /\A\d{1,}\Z/
118
+ return find_storage_server_type_by_id(val)
119
+ else
120
+ return find_storage_server_type_by_name(val)
121
+ end
122
+ end
123
+
124
+ def find_storage_server_type_by_id(id)
125
+ begin
126
+ json_response = storage_server_types_interface.get(id.to_i)
127
+ return json_response[storage_server_type_object_key]
128
+ rescue RestClient::Exception => e
129
+ if e.response && e.response.code == 404
130
+ print_red_alert "Storage Server Type not found by id #{id}"
131
+ return nil
132
+ else
133
+ raise e
134
+ end
135
+ end
136
+ end
137
+
138
+ def find_storage_server_type_by_name(name)
139
+ json_response = storage_server_types_interface.list({name: name.to_s})
140
+ storage_server_types = json_response[storage_server_type_list_key]
141
+ if storage_server_types.empty?
142
+ print_red_alert "Storage Server Type not found by name #{name}"
143
+ return storage_server_types
144
+ elsif storage_server_types.size > 1
145
+ print_red_alert "#{storage_server_types.size} storage server types found by name #{name}"
146
+ rows = storage_server_types.collect do |it|
147
+ {id: it['id'], name: it['name']}
148
+ end
149
+ puts as_pretty_table(rows, [:id, :name], {color:red})
150
+ return nil
151
+ else
152
+ return storage_server_types[0]
153
+ end
154
+ end
155
+
156
+ end