morpheus-cli 4.1.14 → 4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/api_client.rb +4 -0
  4. data/lib/morpheus/api/library_container_types_interface.rb +1 -1
  5. data/lib/morpheus/api/library_instance_types_interface.rb +7 -7
  6. data/lib/morpheus/api/library_layouts_interface.rb +1 -1
  7. data/lib/morpheus/api/network_routers_interface.rb +101 -0
  8. data/lib/morpheus/api/tasks_interface.rb +12 -14
  9. data/lib/morpheus/cli.rb +1 -0
  10. data/lib/morpheus/cli/apps.rb +15 -12
  11. data/lib/morpheus/cli/cli_command.rb +40 -2
  12. data/lib/morpheus/cli/clusters.rb +13 -7
  13. data/lib/morpheus/cli/cypher_command.rb +5 -2
  14. data/lib/morpheus/cli/hosts.rb +1 -1
  15. data/lib/morpheus/cli/instances.rb +21 -5
  16. data/lib/morpheus/cli/jobs_command.rb +83 -27
  17. data/lib/morpheus/cli/library_cluster_layouts_command.rb +12 -12
  18. data/lib/morpheus/cli/library_container_scripts_command.rb +52 -40
  19. data/lib/morpheus/cli/library_container_types_command.rb +2 -60
  20. data/lib/morpheus/cli/library_instance_types_command.rb +22 -1
  21. data/lib/morpheus/cli/library_layouts_command.rb +65 -65
  22. data/lib/morpheus/cli/library_option_lists_command.rb +72 -59
  23. data/lib/morpheus/cli/library_option_types_command.rb +30 -186
  24. data/lib/morpheus/cli/library_spec_templates_command.rb +39 -64
  25. data/lib/morpheus/cli/mixins/library_helper.rb +213 -0
  26. data/lib/morpheus/cli/mixins/provisioning_helper.rb +89 -37
  27. data/lib/morpheus/cli/mixins/whoami_helper.rb +16 -1
  28. data/lib/morpheus/cli/network_routers_command.rb +1281 -0
  29. data/lib/morpheus/cli/networks_command.rb +164 -72
  30. data/lib/morpheus/cli/option_types.rb +187 -73
  31. data/lib/morpheus/cli/price_sets_command.rb +4 -4
  32. data/lib/morpheus/cli/prices_command.rb +15 -15
  33. data/lib/morpheus/cli/remote.rb +3 -3
  34. data/lib/morpheus/cli/service_plans_command.rb +17 -8
  35. data/lib/morpheus/cli/tasks.rb +437 -169
  36. data/lib/morpheus/cli/version.rb +1 -1
  37. data/lib/morpheus/formatters.rb +8 -0
  38. metadata +6 -3
@@ -556,67 +556,9 @@ class Morpheus::Cli::LibraryContainerTypesCommand
556
556
 
557
557
  private
558
558
 
559
- def find_container_type_by_name_or_id(layout_id, val)
560
- if val.to_s =~ /\A\d{1,}\Z/
561
- return find_container_type_by_id(layout_id, val)
562
- else
563
- return find_container_type_by_name(layout_id, val)
564
- end
565
- end
566
-
567
- def find_container_type_by_id(layout_id, id)
568
- begin
569
- json_response = @library_container_types_interface.get(layout_id, id.to_i)
570
- return json_response['containerType']
571
- rescue RestClient::Exception => e
572
- if e.response && e.response.code == 404
573
- print_red_alert "Instance Type not found by id #{id}"
574
- else
575
- raise e
576
- end
577
- end
578
- end
579
-
580
- def find_container_type_by_name(layout_id, name)
581
- container_types = @library_container_types_interface.list(layout_id, {name: name.to_s})['containerTypes']
582
- if container_types.empty?
583
- print_red_alert "Node Type not found by name #{name}"
584
- return nil
585
- elsif container_types.size > 1
586
- print_red_alert "#{container_types.size} node types found by name #{name}"
587
- print_container_types_table(container_types, {color: red})
588
- print_red_alert "Try using ID instead"
589
- print reset,"\n"
590
- return nil
591
- else
592
- return container_types[0]
593
- end
594
- end
595
-
596
- def print_container_types_table(container_types, opts={})
597
- columns = [
598
- {"ID" => lambda {|it| it['id'] } },
599
- {"TECHNOLOGY" => lambda {|it| format_container_type_technology(it) } },
600
- {"NAME" => lambda {|it| it['name'] } },
601
- {"SHORT NAME" => lambda {|it| it['shortName'] } },
602
- {"VERSION" => lambda {|it| it['containerVersion'] } },
603
- {"CATEGORY" => lambda {|it| it['category'] } },
604
- {"OWNER" => lambda {|it| it['account'] ? it['account']['name'] : '' } }
605
- ]
606
- if opts[:include_fields]
607
- columns = opts[:include_fields]
608
- end
609
- print as_pretty_table(container_types, columns, opts)
610
- end
611
-
612
- def format_container_type_technology(container_type)
613
- if container_type
614
- container_type['provisionType'] ? container_type['provisionType']['name'] : ''
615
- else
616
- ""
617
- end
618
- end
559
+ ## finders are in LibraryHelper
619
560
 
561
+ ## these layout methods should be consolidated as well
620
562
 
621
563
  def find_layout_by_name_or_id(instance_type_id, val)
622
564
  if val.to_s =~ /\A\d{1,}\Z/
@@ -244,9 +244,17 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
244
244
  options = {}
245
245
  params = {}
246
246
  logo_file = nil
247
+ option_type_ids = nil
247
248
  optparse = Morpheus::Cli::OptionParser.new do|opts|
248
- opts.banner = subcommand_usage()
249
+ opts.banner = subcommand_usage("[name]")
249
250
  build_option_type_options(opts, options, add_instance_type_option_types())
251
+ opts.on('--option-types [x,y,z]', Array, "List of Option Type IDs") do |list|
252
+ if list.nil?
253
+ option_type_ids = []
254
+ else
255
+ option_type_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
256
+ end
257
+ end
250
258
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
251
259
  opts.footer = "Create a new instance type."
252
260
  end
@@ -284,6 +292,17 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
284
292
  params['hasSettings'] = ['on','true','1'].include?(params['hasSettings'].to_s) if params.key?('hasSettings')
285
293
  params['hasAutoScale'] = ['on','true','1'].include?(params['hasAutoScale'].to_s) if params.key?('hasAutoScale')
286
294
  params['hasDeployment'] = ['on','true','1'].include?(params['hasDeployment'].to_s) if params.key?('hasDeployment')
295
+
296
+ # OPTION TYPES
297
+ if params['optionTypes']
298
+ prompt_results = prompt_for_option_types(params, options, @api_client)
299
+ if prompt_results[:success]
300
+ params['optionTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
301
+ else
302
+ return 1
303
+ end
304
+ end
305
+
287
306
  payload = {instanceType: params}
288
307
  @library_instance_types_interface.setopts(options)
289
308
  if options[:dry_run]
@@ -529,6 +548,8 @@ class Morpheus::Cli::LibraryInstanceTypesCommand
529
548
 
530
549
  private
531
550
 
551
+ ## finders are in LibraryHelper
552
+
532
553
  def add_instance_type_option_types
533
554
  [
534
555
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
@@ -20,6 +20,7 @@ class Morpheus::Cli::LibraryLayoutsCommand
20
20
  @api_client = establish_remote_appliance_connection(opts)
21
21
  @library_layouts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).library_layouts
22
22
  @library_instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).library_instance_types
23
+ @library_container_types_interface = @api_client.library_container_types
23
24
  @spec_templates_interface = @api_client.library_spec_templates
24
25
  @spec_template_types_interface = @api_client.library_spec_template_types
25
26
  @provision_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).provision_types
@@ -272,8 +273,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
272
273
  options = {}
273
274
  params = {}
274
275
  instance_type_id = nil
275
- option_type_ids = nil
276
- node_type_ids = nil
277
276
  evars = nil
278
277
  optparse = Morpheus::Cli::OptionParser.new do|opts|
279
278
  opts.banner = subcommand_usage("[instance-type]")
@@ -289,27 +288,36 @@ class Morpheus::Cli::LibraryLayoutsCommand
289
288
  opts.on('--description VALUE', String, "Description") do |val|
290
289
  params['description'] = val
291
290
  end
291
+ opts.on("--creatable [on|off]", ['on','off'], "Creatable") do |val|
292
+ params['creatable'] = (val.to_s != 'false' && val.to_s != 'off')
293
+ end
292
294
  opts.on('--technology CODE', String, "Technology") do |val|
293
295
  params['provisionTypeCode'] = val
294
296
  end
295
297
  opts.on('--min-memory VALUE', String, "Minimum Memory (MB)") do |val|
296
298
  params['memoryRequirement'] = val
297
299
  end
300
+ opts.on("--auto-scale [on|off]", ['on','off'], "Enable Scaling (Horizontal)") do |val|
301
+ params['hasAutoScale'] = (val.to_s != 'false' && val.to_s != 'off')
302
+ end
303
+ opts.on("--convert-to-managed [on|off]", ['on','off'], "Supports Convert To Managed") do |val|
304
+ params['supportsConvertToManaged'] = (val.to_s != 'false' && val.to_s != 'off')
305
+ end
298
306
  opts.on('--workflow ID', String, "Workflow") do |val|
299
307
  params['taskSetId'] = val.to_i
300
308
  end
301
309
  opts.on('--option-types [x,y,z]', Array, "List of Option Type IDs") do |list|
302
310
  if list.nil?
303
- option_type_ids = []
311
+ params['optionTypes'] = []
304
312
  else
305
- option_type_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
313
+ params['optionTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
306
314
  end
307
315
  end
308
316
  opts.on('--node-types [x,y,z]', Array, "List of Node Type IDs") do |list|
309
317
  if list.nil?
310
- node_type_ids = []
318
+ params['containerTypes'] = []
311
319
  else
312
- node_type_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
320
+ params['containerTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
313
321
  end
314
322
  end
315
323
  opts.on('--spec-templates [x,y,z]', Array, "List of Spec Templates to include in this layout, comma separated list of names or IDs.") do |list|
@@ -319,7 +327,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
319
327
  params['specTemplates'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
320
328
  end
321
329
  end
322
- #build_option_type_options(opts, options, add_layout_option_types())
323
330
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
324
331
  opts.footer = "Create a new layout." + "\n" +
325
332
  "[instance-type] is required and can be passed as --instance-type instead."
@@ -350,8 +357,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
350
357
  if options[:payload]
351
358
  payload = options[:payload]
352
359
  else
353
- # v_prompt = Morpheus::Cli::OptionTypes.prompt(add_layout_option_types, options[:options], @api_client, options[:params])
354
- # params.deep_merge!(v_prompt)
355
360
  params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
356
361
 
357
362
  if !params['name']
@@ -366,6 +371,10 @@ class Morpheus::Cli::LibraryLayoutsCommand
366
371
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'type' => 'text', 'fieldLabel' => 'Description', 'required' => false}], options[:options])
367
372
  params['description'] = v_prompt['description'] if v_prompt['description']
368
373
  end
374
+ if params['creatable'].nil?
375
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'creatable', 'type' => 'checkbox', 'fieldLabel' => 'Creatable', 'defaultValue' => 'on'}], options[:options])
376
+ params['creatable'] = ['true','on'].include?(v_prompt['creatable'].to_s) if v_prompt['creatable'] != nil
377
+ end
369
378
 
370
379
  provision_types = @provision_types_interface.list({customSupported: true})['provisionTypes']
371
380
  if provision_types.empty?
@@ -386,7 +395,14 @@ class Morpheus::Cli::LibraryLayoutsCommand
386
395
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryRequirement', 'type' => 'text', 'fieldLabel' => 'Min Memory (MB)', 'required' => false, 'description' => 'This will override any memory requirement set on the virtual image'}], options[:options])
387
396
  params['memoryRequirement'] = v_prompt['memoryRequirement'] if v_prompt['memoryRequirement']
388
397
  end
389
-
398
+ if params['hasAutoScale'].nil?
399
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'hasAutoScale', 'type' => 'checkbox', 'fieldLabel' => 'Enable Scaling (Horizontal)'}], options[:options])
400
+ params['hasAutoScale'] = ['true','on'].include?(v_prompt['hasAutoScale'].to_s) if v_prompt['hasAutoScale'] != nil
401
+ end
402
+ if params['supportsConvertToManaged'].nil?
403
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'supportsConvertToManaged', 'type' => 'checkbox', 'fieldLabel' => 'Supports Convert To Managed'}], options[:options])
404
+ params['supportsConvertToManaged'] = ['true','on'].include?(v_prompt['supportsConvertToManaged'].to_s) if v_prompt['supportsConvertToManaged'] != nil
405
+ end
390
406
  if !params['taskSetId']
391
407
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'taskSetId', 'type' => 'text', 'fieldLabel' => 'Workflow ID', 'required' => false, 'description' => 'Worflow ID'}], options[:options])
392
408
  params['taskSetId'] = v_prompt['taskSetId'].to_i if v_prompt['taskSetId']
@@ -400,17 +416,19 @@ class Morpheus::Cli::LibraryLayoutsCommand
400
416
  end
401
417
 
402
418
  # OPTION TYPES
403
- if option_type_ids
404
- params['optionTypes'] = option_type_ids.collect {|it| it.to_i }.select { |it| it != 0 }
419
+ prompt_results = prompt_for_option_types(params, options, @api_client)
420
+ if prompt_results[:success]
421
+ params['optionTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
405
422
  else
406
- # prompt
423
+ return 1
407
424
  end
408
425
 
409
426
  # NODE TYPES
410
- if node_type_ids
411
- params['containerTypes'] = node_type_ids.collect {|it| it.to_i }.select { |it| it != 0 }
427
+ prompt_results = prompt_for_container_types(params, options, @api_client)
428
+ if prompt_results[:success]
429
+ params['containerTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
412
430
  else
413
- # prompt
431
+ return 1
414
432
  end
415
433
 
416
434
  # SPEC TEMPLATES
@@ -452,8 +470,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
452
470
  options = {}
453
471
  params = {}
454
472
  instance_type_id = nil
455
- option_type_ids = nil
456
- node_type_ids = nil
457
473
  evars = nil
458
474
  optparse = Morpheus::Cli::OptionParser.new do|opts|
459
475
  opts.banner = subcommand_usage("[name] [options]")
@@ -466,27 +482,36 @@ class Morpheus::Cli::LibraryLayoutsCommand
466
482
  opts.on('--description VALUE', String, "Description") do |val|
467
483
  params['description'] = val
468
484
  end
469
- # opts.on('--technology CODE', String, "Technology") do |val|
470
- # params['provisionTypeCode'] = val
471
- # end
485
+ opts.on("--creatable [on|off]", ['on','off'], "Creatable") do |val|
486
+ params['creatable'] = (val.to_s != 'false' && val.to_s != 'off')
487
+ end
488
+ opts.on('--technology CODE', String, "Technology") do |val|
489
+ params['provisionTypeCode'] = val
490
+ end
472
491
  opts.on('--min-memory VALUE', String, "Minimum Memory (MB)") do |val|
473
492
  params['memoryRequirement'] = val
474
493
  end
494
+ opts.on("--auto-scale [on|off]", ['on','off'], "Enable Scaling (Horizontal)") do |val|
495
+ params['hasAutoScale'] = (val.to_s != 'false' && val.to_s != 'off')
496
+ end
497
+ opts.on("--convert-to-managed [on|off]", ['on','off'], "Supports Convert To Managed") do |val|
498
+ params['supportsConvertToManaged'] = (val.to_s != 'false' && val.to_s != 'off')
499
+ end
475
500
  opts.on('--workflow ID', String, "Workflow") do |val|
476
501
  params['taskSetId'] = val.to_i
477
502
  end
478
503
  opts.on('--option-types [x,y,z]', Array, "List of Option Type IDs") do |list|
479
504
  if list.nil?
480
- option_type_ids = []
505
+ params['optionTypes'] = []
481
506
  else
482
- option_type_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
507
+ params['optionTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
483
508
  end
484
509
  end
485
510
  opts.on('--node-types [x,y,z]', Array, "List of Node Type IDs") do |list|
486
511
  if list.nil?
487
- node_type_ids = []
512
+ params['containerTypes'] = []
488
513
  else
489
- node_type_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
514
+ params['containerTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
490
515
  end
491
516
  end
492
517
  opts.on('--spec-templates [x,y,z]', Array, "List of Spec Templates to include in this layout, comma separated list of names or IDs.") do |list|
@@ -496,7 +521,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
496
521
  params['specTemplates'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
497
522
  end
498
523
  end
499
- #build_option_type_options(opts, options, update_layout_option_types())
500
524
  build_common_options(opts, options, [:options, :json, :dry_run, :remote])
501
525
  opts.footer = "Update a layout."
502
526
  end
@@ -513,8 +537,6 @@ class Morpheus::Cli::LibraryLayoutsCommand
513
537
  if options[:payload]
514
538
  payload = options[:payload]
515
539
  else
516
- # option_types = update_layout_option_types(instance_type)
517
- # params = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
518
540
  params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
519
541
 
520
542
  # ENVIRONMENT VARIABLES
@@ -525,17 +547,23 @@ class Morpheus::Cli::LibraryLayoutsCommand
525
547
  end
526
548
 
527
549
  # OPTION TYPES
528
- if option_type_ids
529
- params['optionTypes'] = option_type_ids.collect {|it| it.to_i }.select { |it| it != 0 }
530
- else
531
- # prompt
550
+ if params['optionTypes']
551
+ prompt_results = prompt_for_option_types(params, options, @api_client)
552
+ if prompt_results[:success]
553
+ params['optionTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
554
+ else
555
+ return 1
556
+ end
532
557
  end
533
558
 
534
559
  # NODE TYPES
535
- if node_type_ids
536
- params['containerTypes'] = node_type_ids.collect {|it| it.to_i }.select { |it| it != 0 }
537
- else
538
- # prompt
560
+ if params['containerTypes']
561
+ prompt_results = prompt_for_container_types(params, options, @api_client)
562
+ if prompt_results[:success]
563
+ params['containerTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
564
+ else
565
+ return 1
566
+ end
539
567
  end
540
568
 
541
569
  # SPEC TEMPLATES
@@ -549,8 +577,7 @@ class Morpheus::Cli::LibraryLayoutsCommand
549
577
  end
550
578
 
551
579
  if params.empty?
552
- puts optparse
553
- exit 1
580
+ raise_command_error "Specify at least one option to update.\n#{optparse}"
554
581
  end
555
582
 
556
583
  payload = {'instanceTypeLayout' => params}
@@ -685,31 +712,4 @@ class Morpheus::Cli::LibraryLayoutsCommand
685
712
  val.to_s # .capitalize
686
713
  end
687
714
 
688
- def add_layout_option_types
689
- [
690
- # {'fieldName' => 'instanceTypeId', 'fieldLabel' => 'Instance Type ID', 'type' => 'text', 'required' => true, 'displayOrder' => 2, 'description' => 'The instance type this layout belongs to'},
691
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
692
- {'fieldName' => 'code', 'fieldLabel' => 'Code', 'type' => 'text', 'required' => true, 'displayOrder' => 2, 'description' => 'Useful shortcode for provisioning naming schemes and export reference.'},
693
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 3},
694
- {'fieldName' => 'category', 'fieldLabel' => 'Category', 'type' => 'select', 'optionSource' => 'categories', 'required' => true, 'displayOrder' => 4},
695
- {'fieldName' => 'logo', 'fieldLabel' => 'Icon File', 'type' => 'text', 'displayOrder' => 5},
696
- {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 6},
697
- {'fieldName' => 'environmentPrefix', 'fieldLabel' => 'Environment Prefix', 'type' => 'text', 'displayOrder' => 7, 'description' => 'Used for exportable environment variables when tying instance types together in app contexts. If not specified a name will be generated.'},
698
- {'fieldName' => 'hasSettings', 'fieldLabel' => 'Enable Settings', 'type' => 'checkbox', 'displayOrder' => 8},
699
- {'fieldName' => 'hasAutoScale', 'fieldLabel' => 'Enable Scaling (Horizontal)', 'type' => 'checkbox', 'displayOrder' => 9},
700
- {'fieldName' => 'hasDeployment', 'fieldLabel' => 'Supports Deployments', 'type' => 'checkbox', 'displayOrder' => 10, 'description' => 'Requires a data volume be configured on each version. Files will be copied into this location.'}
701
- ]
702
- end
703
-
704
- def update_layout_option_types(instance_type=nil)
705
- if instance_type
706
- opts = add_layout_option_types
707
- opts.find {|opt| opt['fieldName'] == 'name'}['defaultValue'] = instance_type['name']
708
- opts
709
- else
710
- add_layout_option_types
711
- end
712
- end
713
-
714
-
715
715
  end
@@ -31,8 +31,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
31
31
  options = {}
32
32
  optparse = Morpheus::Cli::OptionParser.new do|opts|
33
33
  opts.banner = subcommand_usage()
34
- build_common_options(opts, options, [:list, :query, :dry_run, :json, :remote])
35
- opts.footer = "This outputs a list of custom Option List records."
34
+ build_standard_list_options(opts, options)
35
+ opts.footer = "List option lists."
36
36
  end
37
37
  optparse.parse!(args)
38
38
  connect(options)
@@ -46,11 +46,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
46
46
  end
47
47
 
48
48
  json_response = @option_type_lists_interface.list(params)
49
-
50
- if options[:json]
51
- print JSON.pretty_generate(json_response), "\n"
52
- return
53
- end
49
+ render_result = render_with_format(json_response, options, 'optionTypeLists')
50
+ return 0 if render_result
54
51
 
55
52
  option_type_lists = json_response['optionTypeLists']
56
53
  subtitles = []
@@ -68,17 +65,20 @@ class Morpheus::Cli::LibraryOptionListsCommand
68
65
  size: option_type_list['listItems'] ? option_type_list['listItems'].size : ''
69
66
  }
70
67
  end
68
+ columns = [
69
+ :id,
70
+ :name,
71
+ :description,
72
+ :type,
73
+ :size
74
+ ]
75
+ print cyan
76
+ print as_pretty_table(rows, columns, options)
77
+ print reset
78
+ print_results_pagination(json_response)
71
79
  end
72
- columns = [
73
- :id,
74
- :name,
75
- :description,
76
- :type,
77
- :size
78
- ]
79
- print cyan
80
- print as_pretty_table(rows, columns, options)
81
80
  print reset,"\n"
81
+ return 0
82
82
  rescue RestClient::Exception => e
83
83
  print_rest_exception(e, options)
84
84
  exit 1
@@ -87,35 +87,41 @@ class Morpheus::Cli::LibraryOptionListsCommand
87
87
 
88
88
  def get(args)
89
89
  options = {}
90
- optparse = Morpheus::Cli::OptionParser.new do|opts|
90
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
91
91
  opts.banner = subcommand_usage("[name]")
92
- build_common_options(opts, options, [:json, :dry_run, :remote])
93
- opts.footer = "This outputs details about a particular Option List."
92
+ build_standard_get_options(opts, options)
93
+ opts.footer = "Get details about an option list.\n" +
94
+ "[name] is required. This is the name or id of an option list. Supports 1-N [name] arguments."
94
95
  end
95
96
  optparse.parse!(args)
96
97
  if args.count < 1
97
- puts optparse
98
- exit 1
98
+ raise_command_error "wrong number of arguments, expected 1-N and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
99
99
  end
100
-
101
100
  connect(options)
101
+ id_list = parse_id_list(args)
102
+ return run_command_for_each_arg(id_list) do |arg|
103
+ _get(arg, options)
104
+ end
105
+ end
106
+
107
+ def _get(id, options)
108
+
102
109
  begin
103
110
  @option_type_lists_interface.setopts(options)
104
111
  if options[:dry_run]
105
- if args[0].to_s =~ /\A\d{1,}\Z/
106
- print_dry_run @option_type_lists_interface.dry.get(args[0].to_i)
112
+ if id.to_s =~ /\A\d{1,}\Z/
113
+ print_dry_run @option_type_lists_interface.dry.get(id.to_i)
107
114
  else
108
- print_dry_run @option_type_lists_interface.dry.list({name: args[0]})
115
+ print_dry_run @option_type_lists_interface.dry.list({name: id})
109
116
  end
110
117
  return
111
118
  end
112
- option_type_list = find_option_type_list_by_name_or_id(args[0])
113
- exit 1 if option_type_list.nil?
119
+ option_type_list = find_option_type_list_by_name_or_id(id)
120
+ return 1 if option_type_list.nil?
114
121
 
115
- if options[:json]
116
- print JSON.pretty_generate({optionTypeList: option_type_list}), "\n"
117
- return
118
- end
122
+ json_response = {'optionTypeList' => option_type_list}
123
+ render_result = render_with_format(json_response, options, 'optionTypeList')
124
+ return 0 if render_result
119
125
 
120
126
  print_h1 "Option List Details", options
121
127
  print cyan
@@ -127,7 +133,7 @@ class Morpheus::Cli::LibraryOptionListsCommand
127
133
  "Type" => lambda {|it| it['type'].to_s.capitalize },
128
134
  }, option_type_list)
129
135
  # print_h2 "Initial Dataset"
130
- # print bright_black,"#{option_type_list['initialDataset']}","\n",reset
136
+ # print reset,"#{option_type_list['initialDataset']}","\n",reset
131
137
  else
132
138
  option_list_columns = {
133
139
  "ID" => 'id',
@@ -154,11 +160,11 @@ class Morpheus::Cli::LibraryOptionListsCommand
154
160
  end
155
161
  if !option_type_list['initialDataset'].empty?
156
162
  print_h2 "Initial Dataset"
157
- print bright_black,"#{option_type_list['initialDataset']}","\n",reset
163
+ print reset,"#{option_type_list['initialDataset']}","\n",reset
158
164
  end
159
165
  if !option_type_list['translationScript'].empty?
160
166
  print_h2 "Translation Script"
161
- print bright_black,"#{option_type_list['translationScript']}","\n",reset
167
+ print reset,"#{option_type_list['translationScript']}","\n",reset
162
168
  end
163
169
  end
164
170
  print_h2 "List Items"
@@ -176,8 +182,6 @@ class Morpheus::Cli::LibraryOptionListsCommand
176
182
  end
177
183
 
178
184
  def add(args)
179
- # JD: this is annoying because our option_types (for prompting and help)
180
- # are the same type of object being managed here.., options options options
181
185
  options = {}
182
186
  my_option_types = nil
183
187
  list_type = nil
@@ -189,7 +193,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
189
193
  # options[:options]['type'] = val
190
194
  end
191
195
  build_option_type_options(opts, options, new_option_type_list_option_types())
192
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
196
+ build_standard_add_options(opts, options)
197
+ opts.footer = "Create a new option list."
193
198
  end
194
199
  optparse.parse!(args)
195
200
 
@@ -222,9 +227,6 @@ class Morpheus::Cli::LibraryOptionListsCommand
222
227
  params['config']['sourceHeaders'] = source_headers
223
228
  end
224
229
  end
225
- if params.key?('required')
226
- params['required'] = ['on','true'].include?(params['required'].to_s)
227
- end
228
230
  list_payload = params
229
231
  payload = {'optionTypeList' => list_payload}
230
232
  end
@@ -234,10 +236,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
234
236
  return
235
237
  end
236
238
  json_response = @option_type_lists_interface.create(payload)
237
- if options[:json]
238
- print JSON.pretty_generate(json_response), "\n"
239
- return
240
- end
239
+ render_result = render_with_format(json_response, options)
240
+ return 0 if render_result
241
241
  option_type_list = json_response['optionTypeList']
242
242
  print_green_success "Added Option List #{option_type_list['name']}"
243
243
  get([option_type_list['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
@@ -249,13 +249,13 @@ class Morpheus::Cli::LibraryOptionListsCommand
249
249
  end
250
250
 
251
251
  def update(args)
252
- # JD: this is annoying because our option_types (for prompting and help)
253
- # are the same type of object being managed here.., options options options
254
252
  options = {}
255
253
  optparse = Morpheus::Cli::OptionParser.new do |opts|
256
254
  opts.banner = subcommand_usage("[name] [options]")
257
255
  build_option_type_options(opts, options, update_option_type_list_option_types())
258
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
256
+ build_standard_update_options(opts, options)
257
+ opts.footer = "Update an option list.\n" +
258
+ "[name] is required. This is the name or id of an option list."
259
259
  end
260
260
  optparse.parse!(args)
261
261
  connect(options)
@@ -304,15 +304,13 @@ class Morpheus::Cli::LibraryOptionListsCommand
304
304
  return
305
305
  end
306
306
  json_response = @option_type_lists_interface.update(option_type_list['id'], payload)
307
- if options[:json]
308
- print JSON.pretty_generate(json_response), "\n"
309
- return
310
- end
307
+ render_result = render_with_format(json_response, options)
308
+ return 0 if render_result
311
309
  print_green_success "Updated Option List #{list_payload['name']}"
312
310
  get([option_type_list['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
313
311
  rescue RestClient::Exception => e
314
312
  print_rest_exception(e, options)
315
- exit 1
313
+ return 1
316
314
  end
317
315
  end
318
316
 
@@ -320,7 +318,9 @@ class Morpheus::Cli::LibraryOptionListsCommand
320
318
  options = {}
321
319
  optparse = Morpheus::Cli::OptionParser.new do |opts|
322
320
  opts.banner = subcommand_usage("[name]")
323
- build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
321
+ build_standard_remove_options(opts, options)
322
+ opts.footer = "Delete an option list.\n" +
323
+ "[name] is required. This is the name or id of an option list."
324
324
  end
325
325
  optparse.parse!(args)
326
326
  if args.count < 1
@@ -342,11 +342,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
342
342
  return
343
343
  end
344
344
  json_response = @option_type_lists_interface.destroy(option_type_list['id'])
345
-
346
- if options[:json]
347
- print JSON.pretty_generate(json_response), "\n"
348
- return
349
- end
345
+ render_result = render_with_format(json_response, options)
346
+ return 0 if render_result
350
347
 
351
348
  print_green_success "Removed Option List #{option_type_list['name']}"
352
349
  #list([])
@@ -479,7 +476,8 @@ class Morpheus::Cli::LibraryOptionListsCommand
479
476
 
480
477
  def get_available_option_list_types
481
478
  [
482
- {'name' => 'Rest', 'value' => 'rest'},
479
+ {'name' => 'REST', 'value' => 'rest'},
480
+ {'name' => 'Morpheus Api', 'value' => 'api'},
483
481
  {'name' => 'Manual', 'value' => 'manual'}
484
482
  ]
485
483
  end
@@ -494,18 +492,33 @@ class Morpheus::Cli::LibraryOptionListsCommand
494
492
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
495
493
  {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
496
494
  #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
495
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
497
496
  {'fieldName' => 'sourceUrl', 'fieldLabel' => 'Source Url', 'type' => 'text', 'required' => true, 'description' => "A REST URL can be used to fetch list data and is cached in the appliance database.", 'displayOrder' => 4},
498
497
  {'fieldName' => 'ignoreSSLErrors', 'fieldLabel' => 'Ignore SSL Errors', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 5},
499
498
  {'fieldName' => 'realTime', 'fieldLabel' => 'Real Time', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 6},
500
499
  {'fieldName' => 'sourceMethod', 'fieldLabel' => 'Source Method', 'type' => 'select', 'selectOptions' => [{'name' => 'GET', 'value' => 'GET'}, {'name' => 'POST', 'value' => 'POST'}], 'defaultValue' => 'GET', 'required' => true, 'displayOrder' => 7},
500
+ # sourceHeaders component (is done afterwards manually)
501
501
  {'fieldName' => 'initialDataset', 'fieldLabel' => 'Initial Dataset', 'type' => 'code-editor', 'description' => "Create an initial json dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'. However, if there is a translation script, that will also be passed through.", 'displayOrder' => 8},
502
502
  {'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 9},
503
+ {'fieldName' => 'requestScript', 'fieldLabel' => 'Request Script', 'type' => 'code-editor', 'description' => "Create a js script to prepare the request. Return a data object as the body for a post, and return an array containing properties name and value for a get. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 10},
504
+
505
+ ]
506
+ elsif list_type.to_s.downcase == 'api'
507
+ [
508
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
509
+ {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
510
+ #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
511
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
512
+ {'fieldName' => 'apiType', 'fieldLabel' => 'Option List', 'type' => 'select', 'optionSource' => 'apiOptionLists', 'required' => true, 'description' => 'The code of the api list to use, eg. clouds, servers, etc.', 'displayOrder' => 6},
513
+ {'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 9},
514
+ {'fieldName' => 'requestScript', 'fieldLabel' => 'Request Script', 'type' => 'code-editor', 'description' => "Create a js script to prepare the request. Return a data object as the body for a post, and return an array containing properties name and value for a get. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 10},
503
515
  ]
504
516
  elsif list_type.to_s.downcase == 'manual'
505
517
  [
506
518
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
507
519
  {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
508
520
  #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
521
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
509
522
  {'fieldName' => 'initialDataset', 'fieldLabel' => 'Dataset', 'type' => 'code-editor', 'required' => true, 'description' => "Create an initial JSON or CSV dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'.", 'displayOrder' => 4},
510
523
  ]
511
524
  else