morpheus-cli 5.4.0 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) 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 +51 -9
  5. data/lib/morpheus/api/audit_interface.rb +9 -0
  6. data/lib/morpheus/api/instances_interface.rb +21 -0
  7. data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
  8. data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
  9. data/lib/morpheus/api/load_balancer_profiles_interface.rb +4 -5
  10. data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +13 -4
  11. data/lib/morpheus/api/load_balancers_interface.rb +5 -0
  12. data/lib/morpheus/api/network_routers_interface.rb +9 -0
  13. data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
  14. data/lib/morpheus/api/read_interface.rb +4 -3
  15. data/lib/morpheus/api/rest_interface.rb +3 -3
  16. data/lib/morpheus/api/secondary_read_interface.rb +1 -1
  17. data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
  18. data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
  19. data/lib/morpheus/api/storage_servers_interface.rb +9 -0
  20. data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
  21. data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
  22. data/lib/morpheus/api/users_interface.rb +16 -63
  23. data/lib/morpheus/cli/cli_command.rb +253 -5
  24. data/lib/morpheus/cli/cli_registry.rb +1 -1
  25. data/lib/morpheus/cli/commands/alias_command.rb +1 -1
  26. data/lib/morpheus/cli/commands/apps.rb +14 -78
  27. data/lib/morpheus/cli/commands/audit.rb +188 -0
  28. data/lib/morpheus/cli/commands/blueprints_command.rb +1 -1
  29. data/lib/morpheus/cli/commands/change_password_command.rb +4 -4
  30. data/lib/morpheus/cli/commands/clusters.rb +37 -12
  31. data/lib/morpheus/cli/commands/hosts.rb +15 -15
  32. data/lib/morpheus/cli/commands/instances.rb +109 -2
  33. data/lib/morpheus/cli/commands/load_balancer_monitors.rb +71 -0
  34. data/lib/morpheus/cli/commands/load_balancer_pools.rb +30 -50
  35. data/lib/morpheus/cli/commands/load_balancer_profiles.rb +65 -0
  36. data/lib/morpheus/cli/commands/load_balancer_types.rb +9 -4
  37. data/lib/morpheus/cli/commands/load_balancer_virtual_servers.rb +77 -57
  38. data/lib/morpheus/cli/commands/load_balancers.rb +93 -6
  39. data/lib/morpheus/cli/commands/network_firewalls_command.rb +22 -5
  40. data/lib/morpheus/cli/commands/network_routers_command.rb +96 -45
  41. data/lib/morpheus/cli/commands/network_static_routes_command.rb +446 -0
  42. data/lib/morpheus/cli/commands/network_transport_zones_command.rb +4 -4
  43. data/lib/morpheus/cli/commands/open_command.rb +30 -0
  44. data/lib/morpheus/cli/commands/options.rb +98 -0
  45. data/lib/morpheus/cli/commands/policies_command.rb +1 -1
  46. data/lib/morpheus/cli/commands/prices_command.rb +7 -7
  47. data/lib/morpheus/cli/commands/remote.rb +4 -2
  48. data/lib/morpheus/cli/commands/roles.rb +1 -1
  49. data/lib/morpheus/cli/commands/shell.rb +2 -2
  50. data/lib/morpheus/cli/commands/storage_server_types.rb +50 -0
  51. data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
  52. data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
  53. data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
  54. data/lib/morpheus/cli/commands/tenants_command.rb +1 -1
  55. data/lib/morpheus/cli/commands/user_groups_command.rb +1 -1
  56. data/lib/morpheus/cli/commands/user_settings_command.rb +2 -1
  57. data/lib/morpheus/cli/commands/user_sources_command.rb +1 -1
  58. data/lib/morpheus/cli/commands/users.rb +28 -28
  59. data/lib/morpheus/cli/commands/view.rb +102 -0
  60. data/lib/morpheus/cli/mixins/accounts_helper.rb +5 -5
  61. data/lib/morpheus/cli/mixins/load_balancers_helper.rb +24 -4
  62. data/lib/morpheus/cli/mixins/print_helper.rb +50 -18
  63. data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
  64. data/lib/morpheus/cli/mixins/provisioning_helper.rb +15 -5
  65. data/lib/morpheus/cli/mixins/rest_command.rb +145 -73
  66. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +174 -81
  67. data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
  68. data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
  69. data/lib/morpheus/cli/option_types.rb +45 -24
  70. data/lib/morpheus/cli/version.rb +1 -1
  71. data/lib/morpheus/cli.rb +1 -0
  72. data/lib/morpheus/ext/string.rb +29 -6
  73. data/lib/morpheus/routes.rb +238 -0
  74. data/lib/morpheus/util.rb +6 -1
  75. metadata +29 -8
@@ -0,0 +1,446 @@
1
+ require 'morpheus/cli/cli_command'
2
+
3
+ class Morpheus::Cli::NetworkStaticRoutesCommand
4
+ include Morpheus::Cli::CliCommand
5
+ include Morpheus::Cli::ProvisioningHelper
6
+ include Morpheus::Cli::WhoamiHelper
7
+
8
+ set_command_name :'network-static-routes'
9
+ register_subcommands :list, :get, :add, :remove, :update
10
+
11
+ def connect(opts)
12
+ @api_client = establish_remote_appliance_connection(opts)
13
+ @account_interface = @api_client.accounts
14
+ @network_static_routes_interface = @api_client.network_static_routes
15
+ @networks_interface = @api_client.networks
16
+ @network_types_interface = @api_client.network_types
17
+ @options_interface = @api_client.options
18
+ end
19
+
20
+ def handle(args)
21
+ handle_subcommand(args)
22
+ end
23
+
24
+ def list(args)
25
+ options = {}
26
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
27
+ opts.banner = subcommand_usage("[network] [search]")
28
+ build_standard_list_options(opts, options)
29
+ opts.footer = "List network DHCP Static Routes." + "\n" +
30
+ "[network] is required. This is the name or id of a network."
31
+ end
32
+
33
+ optparse.parse!(args)
34
+ connect(options)
35
+
36
+ verify_args!(args:args, optparse:optparse, min:1)
37
+ if args.count > 1
38
+ options[:phrase] = args[1..-1].join(" ")
39
+ end
40
+
41
+ network = find_network(args[0])
42
+ if network.nil?
43
+ return 1
44
+ end
45
+
46
+ network_type = find_network_type(network['type']['id'])
47
+ if network_type.nil?
48
+ return 1
49
+ end
50
+
51
+ _list(network, network_type, options)
52
+ end
53
+
54
+ def _list(network, network_type, options)
55
+ params = parse_list_options(options)
56
+ @network_static_routes_interface.setopts(options)
57
+ if options[:dry_run]
58
+ print_dry_run @network_static_routes_interface.dry.list_static_routes(network['id'], params)
59
+ return
60
+ end
61
+
62
+ json_response = @network_static_routes_interface.list_static_routes(network['id'], params)
63
+ render_response(json_response, options, 'networkRoutes') do
64
+ print_h1 "Network DHCP Static Routes For: #{network['name']}"
65
+ print_static_routes(network, network_type, json_response)
66
+ end
67
+ return 0, nil
68
+ end
69
+
70
+ def get(args)
71
+ options = {}
72
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
73
+ opts.banner = subcommand_usage("[network] [network_route]")
74
+ build_standard_get_options(opts, options)
75
+ opts.footer = "Display details on a network Static Route." + "\n" +
76
+ "[network] is required. This is the name or id of a network.\n" +
77
+ "[network_route] is required. This is the id of a network route.\n"
78
+ end
79
+
80
+ optparse.parse!(args)
81
+ connect(options)
82
+
83
+ verify_args!(args:args, optparse:optparse, count:2)
84
+
85
+ network = find_network(args[0])
86
+ if network.nil?
87
+ return 1
88
+ end
89
+
90
+ network_type = find_network_type(network['type']['id'])
91
+ if network_type.nil?
92
+ return 1
93
+ end
94
+
95
+ _get(network, network_type, args[1], options)
96
+ end
97
+
98
+ def _get(network, network_type, route_id, options)
99
+ # params = parse_query_options(options) # todo: use this
100
+ @network_static_routes_interface.setopts(options)
101
+
102
+ if options[:dry_run]
103
+ if route_id.to_s =~ /\A\d{1,}\Z/
104
+ print_dry_run @network_static_routes_interface.dry.get_static_route(network['id'], route_id.to_i)
105
+ else
106
+ print_dry_run @network_static_routes_interface.dry.list_static_routes(network['id'], {name: route_id})
107
+ end
108
+ return
109
+ end
110
+
111
+ route = find_static_route(network['id'], route_id)
112
+ return 1 if route.nil?
113
+
114
+ render_response({route: route}, options, 'route') do
115
+ print_h1 "Network Route Details"
116
+ print cyan
117
+
118
+ description_cols = {}
119
+
120
+ network_type['routeOptionTypes'].sort_by {|it| it['displayOrder']}.each do |option_type|
121
+ description_cols[option_type['fieldLabel']] = lambda {|it| Morpheus::Cli::OptionTypes.get_option_value(it, option_type, true)}
122
+ end
123
+ print_description_list(description_cols, route)
124
+ end
125
+
126
+ println reset
127
+ end
128
+
129
+ def add(args)
130
+ options = {:options=>{}}
131
+ params = {}
132
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
133
+ opts.banner = subcommand_usage("[network]")
134
+ build_standard_add_options(opts, options)
135
+ opts.footer = "Create a network static route." + "\n" +
136
+ "[network] is required. This is the name or id of a network.\n";
137
+ end
138
+ optparse.parse!(args)
139
+ connect(options)
140
+ verify_args!(args:args, optparse:optparse, count:1)
141
+
142
+ network = find_network(args[0])
143
+ if network.nil?
144
+ return 1
145
+ end
146
+
147
+ network_type = find_network_type(network['type']['id'])
148
+ if network_type.nil?
149
+ return 1
150
+ end
151
+
152
+ payload = nil
153
+ if options[:payload]
154
+ payload = options[:payload]
155
+ else
156
+ option_types = network_type['routeOptionTypes'].sort_by {|it| it['displayOrder']}
157
+ # prompt options
158
+ option_result = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options].deep_merge({:context_map => {'networkRoute' => ''}}), @api_client, {'networkId' => network['id']}, nil, true)
159
+ payload = {'networkRoute' => params.deep_merge(option_result)}
160
+ # copy all domain level fields to route
161
+ if payload['networkRoute']['domain']
162
+ payload['networkRoute']['domain'].each do |k,v|
163
+ payload['networkRoute'][k] = v
164
+ end
165
+ end
166
+ payload['networkRoute'].delete('domain')
167
+
168
+ end
169
+
170
+ @network_static_routes_interface.setopts(options)
171
+
172
+ if options[:dry_run]
173
+ print_dry_run @network_static_routes_interface.dry.create_static_route(network['id'], payload)
174
+ return
175
+ end
176
+
177
+ json_response = @network_static_routes_interface.create_static_route(network['id'], payload)
178
+ render_response(json_response, options, 'networkRoute') do
179
+ print_green_success "\nAdded Network Static Route #{json_response['id']}\n"
180
+ _get(network, network_type, json_response['id'], options)
181
+ end
182
+ end
183
+
184
+ def update(args)
185
+ options = {:options=>{}}
186
+ params = {}
187
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
188
+ opts.banner = subcommand_usage("[network] [networkRoute]")
189
+ build_standard_update_options(opts, options)
190
+ opts.footer = "Update a network Static Route.\n" +
191
+ "[network] is required. This is the name or id of an existing network.\n" +
192
+ "[networkRoute] is required. This is the name or id of an existing network static route."
193
+ end
194
+ optparse.parse!(args)
195
+ verify_args!(args:args, optparse:optparse, count:2)
196
+ connect(options)
197
+
198
+ network = find_network(args[0])
199
+ if network.nil?
200
+ return 1
201
+ end
202
+
203
+ network_type = find_network_type(network['type']['id'])
204
+ if network_type.nil?
205
+ return 1
206
+ end
207
+
208
+ route = find_static_route(network['id'], args[1])
209
+ return 1 if route.nil?
210
+
211
+ payload = parse_payload(options) || {'networkRoute' => params}
212
+ payload['networkRoute'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options] && !payload['networkRoute'].nil?
213
+
214
+ if payload['networkRoute'].empty?
215
+ option_types = network_type['routeOptionTypes'].sort_by {|it| it['displayOrder']}
216
+ print_green_success "Nothing to update"
217
+ println cyan
218
+ print Morpheus::Cli::OptionTypes.display_option_types_help(
219
+ option_types,
220
+ {:include_context => true, :context_map => {'networkRoute' => ''}, :color => cyan, :title => "Available Network Static Route Options"}
221
+ )
222
+ exit 1
223
+ end
224
+
225
+ # copy all domain level fields to route
226
+ if payload['networkRoute']['domain']
227
+ payload['networkRoute']['domain'].each do |k,v|
228
+ payload['networkRoute'][k] = v
229
+ end
230
+ payload['networkRoute'].delete('domain')
231
+ end
232
+
233
+ @network_static_routes_interface.setopts(options)
234
+
235
+ if options[:dry_run]
236
+ print_dry_run @network_static_routes_interface.dry.update_static_route(network['id'], route['id'], payload)
237
+ return
238
+ end
239
+
240
+ # build update payload
241
+ update_payload = {'networkRoute' => route.select{|x| !['id', 'code', 'internalId', 'externalId', 'uniqueId', 'providerId', 'externalType', 'enabled', 'visible', 'externalInterface'].include?(x)}}.deep_merge(payload)
242
+
243
+ json_response = @network_static_routes_interface.update_static_route(network['id'], route['id'], update_payload)
244
+ render_response(json_response, options, 'networkRoute') do
245
+ print_green_success "\nUpdated Network Static Route #{route['id']}\n"
246
+ _get(network, network_type, route['id'], options)
247
+ end
248
+ end
249
+
250
+ def remove(args)
251
+ options = {}
252
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
253
+ opts.banner = subcommand_usage("[network] [network_route]")
254
+ build_standard_remove_options(opts, options)
255
+ opts.footer = "Delete a network static route.\n" +
256
+ "[network] is required. This is the name or id of an existing network.\n" +
257
+ "[network_route] is required. This is the name or id of an existing network static route."
258
+ end
259
+ optparse.parse!(args)
260
+ verify_args!(args:args, optparse:optparse, count:2)
261
+ connect(options)
262
+
263
+ network = find_network(args[0])
264
+ if network.nil?
265
+ return 1
266
+ end
267
+
268
+ network_type = find_network_type(network['type']['id'])
269
+ if network_type.nil?
270
+ return 1
271
+ end
272
+
273
+ route = find_static_route(network['id'], args[1])
274
+ return 1 if route.nil?
275
+
276
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the network static route '#{route['source']},#{route['destination']}' from network '#{network['name']}'?", options)
277
+ return 9, "aborted command"
278
+ end
279
+
280
+ @network_static_routes_interface.setopts(options)
281
+
282
+ if options[:dry_run]
283
+ print_dry_run @network_static_routes_interface.dry.delete_static_routes(network['id'], route['id'])
284
+ return
285
+ end
286
+ json_response = @network_static_routes_interface.delete_static_route(network['id'], route['id'])
287
+ render_response(json_response, options, 'networkRoute') do
288
+ print_green_success "\nDeleted Network Static Route '#{route['source']},#{route['destination']}'\n"
289
+ _list(network, network_type, options)
290
+ end
291
+ end
292
+
293
+ private
294
+
295
+ def print_static_routes(network, network_type, json_response)
296
+ routes = json_response['networkRoutes']
297
+ print cyan
298
+ if routes.count > 0
299
+ cols = [:id]
300
+ network_type['routeOptionTypes'].sort_by {|it| it['displayOrder']}.each do |option_type|
301
+ cols << option_type['fieldLabel']
302
+ end
303
+ rows = routes.collect do |it|
304
+ row = {
305
+ id: it['id']
306
+ }
307
+ network_type['routeOptionTypes'].sort_by {|it| it['displayOrder']}.each do |option_type|
308
+ row[option_type['fieldLabel']] = Morpheus::Cli::OptionTypes.get_option_value(it, option_type, true)
309
+ end
310
+ row
311
+ end
312
+ print as_pretty_table(rows, cols)
313
+ print_results_pagination(json_response)
314
+ else
315
+ println "No Static Routes"
316
+ end
317
+ println reset
318
+ end
319
+
320
+ def find_network(val)
321
+ if val.to_s =~ /\A\d{1,}\Z/
322
+ return find_network_by_id(val)
323
+ else
324
+ if network = find_network_by_name(val)
325
+ return find_network_by_id(network['id'])
326
+ end
327
+ end
328
+ end
329
+
330
+ def find_network_by_id(id)
331
+ begin
332
+ json_response = @networks_interface.get(id.to_i)
333
+ return json_response['network']
334
+ rescue RestClient::Exception => e
335
+ if e.response && e.response.code == 404
336
+ print_red_alert "Network not found by id #{id}"
337
+ return nil
338
+ else
339
+ raise e
340
+ end
341
+ end
342
+ end
343
+
344
+ def find_network_by_name(name)
345
+ json_response = @networks_interface.list({phrase: name.to_s})
346
+ networks = json_response['network']
347
+ if networks.empty?
348
+ print_red_alert "Network not found by name #{name}"
349
+ return nil
350
+ elsif networks.size > 1
351
+ print_red_alert "#{networks.size} network found by name #{name}"
352
+ rows = networks.collect do |it|
353
+ {id: it['id'], name: it['name']}
354
+ end
355
+ puts as_pretty_table(rows, [:id, :name], {color:red})
356
+ return nil
357
+ else
358
+ return networks[0]
359
+ end
360
+ end
361
+
362
+ def find_network_type(val)
363
+ if val.to_s =~ /\A\d{1,}\Z/
364
+ return find_network_type_by_id(val)
365
+ else
366
+ if network_type = find_network_type_by_name(val)
367
+ return find_network_type_by_id(network_type['id'])
368
+ end
369
+ end
370
+ end
371
+
372
+ def find_network_type_by_id(id)
373
+ begin
374
+ json_response = @network_types_interface.get(id.to_i)
375
+ return json_response['networkType']
376
+ rescue RestClient::Exception => e
377
+ if e.response && e.response.code == 404
378
+ print_red_alert "Network Type not found by id #{id}"
379
+ return nil
380
+ else
381
+ raise e
382
+ end
383
+ end
384
+ end
385
+
386
+ def find_network_type_by_name(name)
387
+ json_response = @network_types_interface.list({phrase: name.to_s})
388
+ networkTypes = json_response['networkType']
389
+ if networkTypes.empty?
390
+ print_red_alert "Network Type not found by name #{name}"
391
+ return nil
392
+ elsif networkTypes.size > 1
393
+ print_red_alert "#{networkTypes.size} network type found by name #{name}"
394
+ rows = networkTypes.collect do |it|
395
+ {id: it['id'], name: it['name']}
396
+ end
397
+ puts as_pretty_table(rows, [:id, :name], {color:red})
398
+ return nil
399
+ else
400
+ return networkTypes[0]
401
+ end
402
+ end
403
+
404
+ def find_static_route(network_id, val)
405
+ if val.to_s =~ /\A\d{1,}\Z/
406
+ return find_static_route_by_id(network_id, val)
407
+ else
408
+ if route = find_static_route_by_name(network_id, val)
409
+ return find_static_route_by_id(network_id, route['id'])
410
+ end
411
+ end
412
+ end
413
+
414
+ def find_static_route_by_id(network_id, route_id)
415
+ begin
416
+ json_response = @network_static_routes_interface.get_static_route(network_id, route_id.to_i)
417
+ return json_response['networkRoute']
418
+ rescue RestClient::Exception => e
419
+ if e.response && e.response.code == 404
420
+ print_red_alert "Network Static Route not found by id #{route_id}"
421
+ return nil
422
+ else
423
+ raise e
424
+ end
425
+ end
426
+ end
427
+
428
+ def find_static_route_by_name(network_id, name)
429
+ json_response = @network_static_routes_interface.list_static_routes(network_id, {phrase: name.to_s})
430
+ routes = json_response['networkRoutes']
431
+ if routes.empty?
432
+ print_red_alert "Network Static Routes not found by name #{name}"
433
+ return nil
434
+ elsif routes.size > 1
435
+ print_red_alert "#{routes.size} network Static Routes found by name #{name}"
436
+ rows = routes.collect do |it|
437
+ {id: it['id'], source: it['source'], destination: it['destination']}
438
+ end
439
+ puts as_pretty_table(rows, [:id, :source, :destination], {color:red})
440
+ return nil
441
+ else
442
+ return routes[0]
443
+ end
444
+ end
445
+
446
+ end
@@ -89,7 +89,7 @@ class Morpheus::Cli::NetworkTransportZonesCommand
89
89
  server = find_network_server(server_id)
90
90
  return 1 if server.nil?
91
91
 
92
- scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'rule', 'type' => 'select', 'fieldLabel' => 'Firewall Rule', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Firewall Rule.'}],options[:options],@api_client,{})['rule']
92
+ scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'rule', 'type' => 'select', 'fieldLabel' => 'Transport Zone', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Transport Zone.'}],options[:options],@api_client,{})['rule']
93
93
 
94
94
  _get(server, scope_id, options)
95
95
  end
@@ -236,7 +236,7 @@ class Morpheus::Cli::NetworkTransportZonesCommand
236
236
  return 1
237
237
  end
238
238
 
239
- scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'scope', 'type' => 'select', 'fieldLabel' => 'Firewall Rule', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Transport Zone.'}],options[:options],@api_client,{})['scope']
239
+ scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'scope', 'type' => 'select', 'fieldLabel' => 'Transport Zone', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Transport Zone.'}],options[:options],@api_client,{})['scope']
240
240
  scope = find_scope(server['id'], scope_id)
241
241
  return 1 if scope.nil?
242
242
 
@@ -305,7 +305,7 @@ class Morpheus::Cli::NetworkTransportZonesCommand
305
305
  return 1
306
306
  end
307
307
 
308
- scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'scope', 'type' => 'select', 'fieldLabel' => 'Firewall Rule', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Transport Zone.'}],options[:options],@api_client,{})['scope']
308
+ scope_id = args.count > 1 ? args[1] : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'scope', 'type' => 'select', 'fieldLabel' => 'Transport Zone', 'selectOptions' => search_scopes(server['id']).collect {|it| {'name' => it['name'], 'value' => it['id']}}, 'required' => true, 'description' => 'Select Transport Zone.'}],options[:options],@api_client,{})['scope']
309
309
  scope = find_scope(server['id'], scope_id)
310
310
  return 1 if scope.nil?
311
311
 
@@ -384,7 +384,7 @@ class Morpheus::Cli::NetworkTransportZonesCommand
384
384
  end
385
385
 
386
386
  def find_network_server_by_name(name)
387
- servers = search_network_servers
387
+ servers = search_network_servers(name)
388
388
  if servers.empty?
389
389
  print_red_alert "Network Server not found by name #{name}"
390
390
  return nil
@@ -0,0 +1,30 @@
1
+ require 'morpheus/cli/cli_command'
2
+
3
+ # This is for opening a file
4
+ class Morpheus::Cli::OpenCommand
5
+ include Morpheus::Cli::CliCommand
6
+ set_command_name :open
7
+ set_command_hidden
8
+
9
+ def handle(args)
10
+ append_newline = true
11
+ options = {}
12
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
13
+ opts.banner = "Usage: morpheus #{command_name} [file ...]"
14
+ build_common_options(opts, options, [:dry_run])
15
+ opts.footer = "Open file(s)." + "\n" +
16
+ "[file] is required. This is the name of a file. Supports many [file] arguments."
17
+ end
18
+ optparse.parse!(args)
19
+ verify_args!(args:args, optparse:optparse, min: 1)
20
+ open_args = args.join(" ")
21
+ if options[:dry_run]
22
+ print "\n"
23
+ print "#{cyan}#{bold}#{dark}SYSTEM COMMAND#{reset}\n"
24
+ puts Morpheus::Util.open_url_command(open_args)
25
+ return 0, nil
26
+ end
27
+ return Morpheus::Util.open_url(open_args)
28
+ end
29
+
30
+ end
@@ -0,0 +1,98 @@
1
+ require 'morpheus/cli/cli_command'
2
+
3
+ class Morpheus::Cli::Options
4
+ include Morpheus::Cli::CliCommand
5
+
6
+ set_command_description "List options by source name or option type"
7
+ set_command_name :'options'
8
+
9
+ # options is not published yet
10
+ set_command_hidden
11
+
12
+ def connect(opts)
13
+ @api_client = establish_remote_appliance_connection(opts)
14
+ @options_interface = @api_client.options
15
+ end
16
+
17
+ def handle(args)
18
+ list(args)
19
+ end
20
+
21
+ def list(args)
22
+ options = {}
23
+ params = {}
24
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
25
+ opts.banner = "Usage: morpheus #{command_name} [source] [option-type]"
26
+ # build_standard_list_options(opts, options)
27
+ build_standard_get_options(opts, options)
28
+ opts.footer = <<-EOT
29
+ View options by source name or list options for a specific library option type.
30
+ [source] is required. This is the name of the options source to load eg. "currencies"
31
+ [option-type] is required when [source] is 'list'. This is the name or id of an option type to view.
32
+
33
+ Examples:
34
+ options currencies
35
+ options dnsRecordType
36
+ options list "widgets"
37
+ EOT
38
+ end
39
+ optparse.parse!(args)
40
+ source_name = args[0]
41
+ option_type_id = args.size > 1 ? args[1..-1].join(" ") : nil
42
+ if source_name == "list"
43
+ verify_args!(args:args, optparse:optparse, min: 2)
44
+ else
45
+ verify_args!(args:args, optparse:optparse, count: 1)
46
+ end
47
+ connect(options)
48
+ params.merge!(parse_list_options(options))
49
+ if source_name == "list"
50
+ if option_type_id.to_s =~ /\A\d{1,}\Z/
51
+ params["optionTypeId"] = option_type_id
52
+ else
53
+ option_type = find_by_name_or_id(:option_type, option_type_id)
54
+ if option_type.nil?
55
+ return 1, "Option Type not found by name '#{option_type_id}'"
56
+ end
57
+ params["optionTypeId"] = option_type["id"]
58
+ end
59
+ end
60
+ # could find_by_name_or_id for params['servers'] and params['containers']
61
+ @options_interface.setopts(options)
62
+ if options[:dry_run]
63
+ print_dry_run @options_interface.dry.options_for_source(source_name, params)
64
+ return
65
+ end
66
+ json_response = nil
67
+ begin
68
+ json_response = @options_interface.options_for_source(source_name, params)
69
+ rescue RestClient::Exception => e
70
+ if e.response && e.response.code == 404
71
+ raise_command_error("Options source not found by name '#{source_name}'", args, optparse)
72
+ elsif e.response && e.response.code == 500
73
+ # API is actually returning 500, so just expect it
74
+ if e.response.body.to_s.include?("groovy.lang.MissingMethodException")
75
+ raise_command_error("Options source not found by name '#{source_name}'", args, optparse)
76
+ else
77
+ raise e
78
+ end
79
+ else
80
+ raise e
81
+ end
82
+ end
83
+ render_response(json_response, options, "data") do
84
+ records = json_response["data"]
85
+ # print_h1 "Morpheus Options: #{source}", parse_list_subtitles(options), options
86
+ print_h1 "Morpheus Options", ["Source: #{source_name}"] + parse_list_subtitles(options), options
87
+ if records.nil? || records.empty?
88
+ print cyan,"No options found.",reset,"\n"
89
+ else
90
+ print as_pretty_table(records, [:name, :value], options)
91
+ print_results_pagination(json_response)
92
+ end
93
+ print reset,"\n"
94
+ end
95
+ return 0, nil
96
+ end
97
+
98
+ end
@@ -24,7 +24,7 @@ class Morpheus::Cli::PoliciesCommand
24
24
  @cloud_policies_interface = @api_client.cloud_policies
25
25
  @clouds_interface = @api_client.clouds
26
26
  @groups_interface = @api_client.groups
27
- @users_interface = @api_client.users
27
+ @account_users_interface = @api_client.account_users
28
28
  @roles_interface = @api_client.roles
29
29
  @active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
30
30
  end
@@ -211,11 +211,11 @@ class Morpheus::Cli::PricesCommand
211
211
  raise_command_error "Invalid price unit '#{val}'. Available price units: #{price_units.join(', ')}"
212
212
  end
213
213
  end
214
- opts.on("--platform [PLATFORM]", String, "Price platform [linux|windows]. Required for platform price type") do |val|
215
- if ['linux', 'windows'].include?(val)
214
+ opts.on("--platform [PLATFORM]", String, "Price platform [centos|debian|fedora|canonical|opensuse|redhat|suse|xen|linux|windows]. Required for platform price type") do |val|
215
+ if ['centos','debian','fedora','canonical','opensuse','redhat','suse','xen','linux', 'windows'].include?(val)
216
216
  params['platform'] = val
217
217
  else
218
- raise_command_error "Invalid platform '#{val}'. Available platforms: linux, windows"
218
+ raise_command_error "Invalid platform '#{val}'. Available platforms/vendors: centos, debian, fedora, canonical, opensuse, redhat, suse, xen, linux, windows"
219
219
  end
220
220
  end
221
221
  opts.on("--software [TEXT]", String, "Price software. Required for software price type") do |val|
@@ -375,11 +375,11 @@ class Morpheus::Cli::PricesCommand
375
375
  raise_command_error "Invalid price unit '#{val}'. Available price units: #{price_units.join(', ')}"
376
376
  end
377
377
  end
378
- opts.on("--platform [PLATFORM]", String, "Price platform [linux|windows]. Required for platform price type") do |val|
379
- if ['linux', 'windows'].include?(val)
378
+ opts.on("--platform [PLATFORM]", String, "Price platform [centos|debian|fedora|canonical|opensuse|redhat|suse|xen|linux|windows]. Required for platform price type") do |val|
379
+ if ['centos','debian','fedora','canonical','opensuse','redhat','suse','xen','linux', 'windows'].include?(val)
380
380
  params['platform'] = val
381
381
  else
382
- raise_command_error "Invalid platform '#{val}'. Available platforms: linux, windows"
382
+ raise_command_error "Invalid platform '#{val}'. Available platforms: centos, debian, fedora, canonical, opensuse, redhat, suse, xen, linux, windows"
383
383
  end
384
384
  end
385
385
  opts.on("--software [TEXT]", String, "Price software. Required for software price type") do |val|
@@ -614,7 +614,7 @@ class Morpheus::Cli::PricesCommand
614
614
  def prompt_for_price_type(params, options, price={})
615
615
  case params['priceType']
616
616
  when 'platform'
617
- params['platform'] ||= price['platform'] || Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'platform', 'type' => 'select', 'fieldLabel' => 'Platform', 'required' => true, 'description' => 'Select platform for platform price type', 'selectOptions' => [{'name' => 'Linux', 'value' => 'linux'}, {'name' => 'Windows', 'value' => 'windows'}]}], options[:options], @api_client, {}, options[:no_prompt])['platform']
617
+ params['platform'] ||= price['platform'] || Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'platform', 'type' => 'select', 'fieldLabel' => 'Platform', 'required' => true, 'description' => 'Select platform for platform price type', 'selectOptions' => [ {'name' => 'CentOS', 'value' => 'centos'}, {'name' => 'Debian', 'value' => 'debian'}, {'name' => 'Fedora', 'value' => 'fedora'}, {'name' => 'Canonical', 'value' => 'canonical'}, {'name' => 'openSUSE', 'value' => 'opensuse'}, {'name' => 'Red Hat', 'value' => 'redhat'}, {'name' => 'SUSE', 'value' => 'suse'}, {'name' => 'Xen', 'value' => 'xen'}, {'name' => 'Linux', 'value' => 'linux'}, {'name' => 'Windows', 'value' => 'windows'}]}], options[:options], @api_client, {}, options[:no_prompt])['platform']
618
618
  when 'software'
619
619
  params['software'] ||= price['software'] || Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'software', 'type' => 'text', 'fieldLabel' => 'Software', 'required' => true, 'description' => 'Set software for software price type'}], options[:options], @api_client,{}, options[:no_prompt])['software']
620
620
  when 'datastore'