morpheus-cli 3.6.3 → 3.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -211,7 +211,9 @@ module Morpheus::Cli::ProvisioningHelper
211
211
  # prompts user for all the configuartion options for a particular instance
212
212
  # returns payload of data for a new instance
213
213
  def prompt_new_instance(options={})
214
-
214
+ #puts "prompt_new_instance() #{options}"
215
+ print reset # clear colors
216
+ options[:options] ||= {}
215
217
  # Group
216
218
  group_id = nil
217
219
  group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
@@ -232,8 +234,10 @@ module Morpheus::Cli::ProvisioningHelper
232
234
  else
233
235
  # print_red_alert "Cloud not specified!"
234
236
  # exit 1
235
- cloud_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloud', 'type' => 'select', 'fieldLabel' => 'Cloud', 'selectOptions' => get_available_clouds(group_id), 'required' => true, 'description' => 'Select Cloud.'}],options[:options],api_client,{groupId: group_id})
237
+ available_clouds = get_available_clouds(group_id)
238
+ cloud_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloud', 'type' => 'select', 'fieldLabel' => 'Cloud', 'selectOptions' => get_available_clouds(group_id), 'required' => true, 'description' => 'Select Cloud.', 'defaultValue' => options[:default_cloud] ? options[:default_cloud] : nil}],options[:options],api_client,{groupId: group_id})
236
239
  cloud_id = cloud_prompt['cloud']
240
+ cloud = available_clouds.find {|it| it['id'] == cloud_id.to_i || it['name'] == cloud_id.to_s }
237
241
  end
238
242
  # Instance Type
239
243
  instance_type_code = nil
@@ -243,24 +247,28 @@ module Morpheus::Cli::ProvisioningHelper
243
247
  instance_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'optionSource' => 'instanceTypes', 'required' => true, 'description' => 'Select Instance Type.'}],options[:options],api_client,{groupId: group_id})
244
248
  instance_type_code = instance_type_prompt['type']
245
249
  end
246
- instance_type = find_instance_type_by_code(instance_type_code)
250
+ if instance_type_code.to_s =~ /\A\d{1,}\Z/
251
+ instance_type = find_instance_type_by_id(instance_type_code)
252
+ else
253
+ instance_type = find_instance_type_by_code(instance_type_code)
254
+ end
247
255
  exit 1 if !instance_type
248
256
 
249
257
  # Instance Name
250
-
251
258
  instance_name = nil
252
259
  if options[:instance_name]
253
- instance_name = options[:instance_name]
254
- else
255
- name_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Instance Name', 'type' => 'text', 'required' => options[:name_required]}], options[:options])
256
- instance_name = name_prompt['name'] || ''
260
+ options[:options]['name'] = options[:instance_name]
257
261
  end
262
+ name_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Instance Name', 'type' => 'text', 'required' => options[:name_required]}], options[:options])
263
+ instance_name = name_prompt['name']
264
+
258
265
 
259
266
  payload = {
260
267
  'zoneId' => cloud_id,
261
268
  # 'siteId' => siteId,
262
269
  'instance' => {
263
270
  'name' => instance_name,
271
+ 'cloud' => cloud['name'],
264
272
  'site' => {
265
273
  'id' => group_id
266
274
  },
@@ -271,16 +279,16 @@ module Morpheus::Cli::ProvisioningHelper
271
279
  }
272
280
  }
273
281
 
274
- # allow arbitrary -O values passed by the user (config and instance namespace only)
275
- if options[:options] && options[:options]['config'].is_a?(Hash)
276
- payload['config'] ||= {}
277
- payload['config'].deep_merge!(options[:options]['config'])
278
- end
279
- if options[:options] && options[:options]['instance'].is_a?(Hash)
280
- payload['instance'].deep_merge!(options[:options]['instance'])
282
+ # allow arbitrary -O values passed by the user
283
+ if options[:options]
284
+ arbitrary_options = (options[:options] || {}).reject {|k,v| k.is_a?(Symbol) }
285
+ payload.deep_merge!(arbitrary_options)
281
286
  end
282
287
 
283
288
  # Description
289
+ if options[:description]
290
+ options[:options]['description'] = options[:description]
291
+ end
284
292
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}], options[:options])
285
293
  payload['instance']['description'] = v_prompt['description'] if !v_prompt['description'].empty?
286
294
 
@@ -294,8 +302,9 @@ module Morpheus::Cli::ProvisioningHelper
294
302
 
295
303
  # Version and Layout
296
304
 
297
- version_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'version', 'type' => 'select', 'fieldLabel' => 'Version', 'optionSource' => 'instanceVersions', 'required' => true, 'skipSingleOption' => true, 'description' => 'Select which version of the instance type to be provisioned.'}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, instanceTypeId: instance_type['id']})
298
- layout_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'layout', 'type' => 'select', 'fieldLabel' => 'Layout', 'optionSource' => 'layoutsForCloud', 'required' => true, 'description' => 'Select which configuration of the instance type to be provisioned.'}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, instanceTypeId: instance_type['id'], version: version_prompt['version']})
305
+ version_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'version', 'type' => 'select', 'fieldLabel' => 'Version', 'optionSource' => 'instanceVersions', 'required' => true, 'skipSingleOption' => true, 'autoPickOption' => true, 'description' => 'Select which version of the instance type to be provisioned.'}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, instanceTypeId: instance_type['id']})
306
+ default_layout_value = payload['instance']['layout'] ? payload['instance']['layout']['id'] : nil
307
+ layout_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'layout', 'type' => 'select', 'fieldLabel' => 'Layout', 'optionSource' => 'layoutsForCloud', 'required' => true, 'description' => 'Select which configuration of the instance type to be provisioned.', 'defaultValue' => default_layout_value}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, instanceTypeId: instance_type['id'], version: version_prompt['version']})
299
308
  layout_id = layout_prompt['layout']
300
309
  layout = instance_type['instanceTypeLayouts'].find{ |lt| lt['id'] == layout_id.to_i}
301
310
  if !layout
@@ -307,15 +316,24 @@ module Morpheus::Cli::ProvisioningHelper
307
316
  # prompt for service plan
308
317
  service_plans_json = @instances_interface.service_plans({zoneId: cloud_id, layoutId: layout_id, siteId: group_id})
309
318
  service_plans = service_plans_json["plans"]
310
- service_plans_dropdown = service_plans.collect {|sp| {'name' => sp["name"], 'value' => sp["id"]} } # already sorted
311
- plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'description' => 'Choose the appropriately sized plan for this instance'}],options[:options])
319
+ service_plans_dropdown = service_plans.collect {|sp| {'name' => sp["name"], 'value' => sp["id"], 'code' => sp['code']} } # already sorted
320
+ default_plan = nil
321
+ if payload['plan']
322
+ default_plan = payload['plan']
323
+ elsif payload['instance'] && payload['instance']['plan']
324
+ default_plan = payload['instance']['plan']
325
+ end
326
+ default_plan_value = default_plan.is_a?(Hash) ? default_plan['id'] : default_plan
327
+ plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'description' => 'Choose the appropriately sized plan for this instance', 'defaultValue' => default_plan_value}],options[:options])
312
328
  plan_id = plan_prompt['servicePlan']
313
329
  service_plan = service_plans.find {|sp| sp["id"] == plan_id.to_i }
314
330
  if !service_plan
315
331
  print_red_alert "Plan not found by id #{plan_id}"
316
332
  exit 1
317
333
  end
318
- payload['instance']['plan'] = {'id' => service_plan["id"]}
334
+ #todo: consolidate these, instances api looks for instance.plan.id and apps looks for plan.id
335
+ payload['plan'] = {'id' => service_plan["id"], 'code' => service_plan["code"], 'name' => service_plan["name"]}
336
+ payload['instance']['plan'] = {'id' => service_plan["id"], 'code' => service_plan["code"], 'name' => service_plan["name"]}
319
337
 
320
338
  # prompt for resource pool
321
339
  has_zone_pools = layout["provisionType"] && layout["provisionType"]["id"] && layout["provisionType"]["hasZonePools"]
@@ -328,23 +346,27 @@ module Morpheus::Cli::ProvisioningHelper
328
346
  end
329
347
 
330
348
  # prompt for volumes
331
- volumes = prompt_volumes(service_plan, options, api_client, {})
332
- if !volumes.empty?
333
- payload['volumes'] = volumes
334
- end
335
-
336
- if layout["provisionType"] && layout["provisionType"]["id"] && layout["provisionType"]["hasNetworks"]
337
- # prompt for network interfaces (if supported)
338
- begin
339
- network_interfaces = prompt_network_interfaces(cloud_id, layout["provisionType"]["id"], options)
340
- if !network_interfaces.empty?
341
- payload['networkInterfaces'] = network_interfaces
349
+ # if payload['volumes'].nil?
350
+ volumes = prompt_volumes(service_plan, options, api_client, {})
351
+ if !volumes.empty?
352
+ payload['volumes'] = volumes
353
+ end
354
+ # end
355
+
356
+ # if payload['networkInterfaces'].nil?
357
+ if layout["provisionType"] && layout["provisionType"]["id"] && layout["provisionType"]["hasNetworks"]
358
+ # prompt for network interfaces (if supported)
359
+ begin
360
+ network_interfaces = prompt_network_interfaces(cloud_id, layout["provisionType"]["id"], options)
361
+ if !network_interfaces.empty?
362
+ payload['networkInterfaces'] = network_interfaces
363
+ end
364
+ rescue RestClient::Exception => e
365
+ print yellow,"Unable to load network options. Proceeding...",reset,"\n"
366
+ print_rest_exception(e, options) if Morpheus::Logging.debug?
342
367
  end
343
- rescue RestClient::Exception => e
344
- print yellow,"Unable to load network options. Proceeding...",reset,"\n"
345
- print_rest_exception(e, options) if Morpheus::Logging.debug?
346
368
  end
347
- end
369
+ # end
348
370
 
349
371
  # build option types
350
372
  option_type_list = []
@@ -447,6 +469,20 @@ module Morpheus::Cli::ProvisioningHelper
447
469
 
448
470
  field_context = "rootVolume"
449
471
 
472
+ volume_label = 'root'
473
+ volume = {
474
+ 'id' => -1,
475
+ 'rootVolume' => true,
476
+ 'name' => volume_label,
477
+ 'size' => plan_size,
478
+ 'sizeId' => nil,
479
+ 'storageType' => nil,
480
+ 'datastoreId' => nil
481
+ }
482
+ if options[:options] && options[:options]['volumes'] && options[:options]['volumes'][0]
483
+ volume = options[:options]['volumes'][0]
484
+ end
485
+
450
486
  if root_storage_types.empty?
451
487
  # this means there's no configuration, just send a single root volume to the server
452
488
  storage_type_id = nil
@@ -456,6 +492,7 @@ module Morpheus::Cli::ProvisioningHelper
456
492
  storage_type_id = v_prompt[field_context]['storageType']
457
493
  storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i }
458
494
  end
495
+ volume['storageType'] = storage_type_id
459
496
 
460
497
  # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form
461
498
  root_custom_size_options = []
@@ -467,38 +504,27 @@ module Morpheus::Cli::ProvisioningHelper
467
504
  end
468
505
  end
469
506
 
470
- volume_label = 'root'
471
- volume = {
472
- 'id' => -1,
473
- 'rootVolume' => true,
474
- 'name' => volume_label,
475
- 'size' => plan_size,
476
- 'sizeId' => nil,
477
- 'storageType' => storage_type_id,
478
- 'datastoreId' => nil
479
- }
480
-
481
507
  if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customLabel']
482
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Root Volume Label', 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume_label}], options[:options])
508
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Root Volume Label', 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume['name']}], options[:options])
483
509
  volume['name'] = v_prompt[field_context]['name']
484
510
  end
485
511
  if plan_info['rootDiskCustomizable'] && storage_type && storage_type['customSize']
486
512
  if root_custom_size_options.empty?
487
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => 'Root Volume Size (GB)', 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => plan_size}], options[:options])
513
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => 'Root Volume Size (GB)', 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => volume['size']}], options[:options])
488
514
  volume['size'] = v_prompt[field_context]['size']
489
515
  volume['sizeId'] = nil #volume.delete('sizeId')
490
516
  else
491
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => 'Root Volume Size', 'selectOptions' => root_custom_size_options, 'required' => true, 'description' => 'Choose a volume size.'}], options[:options])
517
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => 'Root Volume Size', 'selectOptions' => root_custom_size_options, 'required' => true, 'description' => 'Choose a volume size.', 'defaultValue' => volume['sizeId']}], options[:options])
492
518
  volume['sizeId'] = v_prompt[field_context]['sizeId']
493
519
  volume['size'] = nil #volume.delete('size')
494
520
  end
495
521
  else
496
522
  # might need different logic here ? =o
497
- volume['size'] = plan_size
498
- volume['sizeId'] = nil #volume.delete('sizeId')
523
+ #volume['size'] = plan_size
524
+ #volume['sizeId'] = nil #volume.delete('sizeId')
499
525
  end
500
526
  if !datastore_options.empty?
501
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => 'Root Datastore', 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.'}], options[:options])
527
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => 'Root Datastore', 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.', 'defaultValue' => volume['datastoreId']}], options[:options])
502
528
  volume['datastoreId'] = v_prompt[field_context]['datastoreId']
503
529
  end
504
530
 
@@ -506,15 +532,30 @@ module Morpheus::Cli::ProvisioningHelper
506
532
 
507
533
  if plan_info['addVolumes']
508
534
  volume_index = 1
509
- has_another_volume = options[:options] && options[:options]["dataVolume#{volume_index}"]
535
+ has_another_volume = (options[:options] && options[:options]["dataVolume#{volume_index}"]) || (options[:options] && options[:options]['volumes'] && options[:options]['volumes'][volume_index])
510
536
  add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add data volume?", {:default => false}))
511
537
  while add_another_volume do
512
538
  #puts "Configure Data #{volume_index} Volume"
513
539
 
514
540
  field_context = "dataVolume#{volume_index}"
515
541
 
516
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Storage Type", 'selectOptions' => storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.'}], options[:options])
542
+ volume_label = (volume_index == 1 ? 'data' : "data #{volume_index}")
543
+ volume = {
544
+ #'id' => -1,
545
+ 'rootVolume' => false,
546
+ 'name' => volume_label,
547
+ 'size' => plan_size,
548
+ 'sizeId' => nil,
549
+ 'storageType' => nil,
550
+ 'datastoreId' => nil
551
+ }
552
+ if options[:options] && options[:options]['volumes'] && options[:options]['volumes'][volume_index]
553
+ volume = options[:options]['volumes'][volume_index]
554
+ end
555
+
556
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'storageType', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Storage Type", 'selectOptions' => storage_types, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a storage type.', 'defaultValue' => volume['storageType']}], options[:options])
517
557
  storage_type_id = v_prompt[field_context]['storageType']
558
+ volume['storageType'] = storage_type_id
518
559
  storage_type = plan_info['storageTypes'].find {|i| i['id'] == storage_type_id.to_i }
519
560
 
520
561
  # sometimes the user chooses sizeId from a list of size options (AccountPrice) and other times it is free form
@@ -527,28 +568,17 @@ module Morpheus::Cli::ProvisioningHelper
527
568
  end
528
569
  end
529
570
 
530
- volume_label = (volume_index == 1 ? 'data' : "data #{volume_index}")
531
- volume = {
532
- 'id' => -1,
533
- 'rootVolume' => false,
534
- 'name' => volume_label,
535
- 'size' => plan_size,
536
- 'sizeId' => nil,
537
- 'storageType' => storage_type_id,
538
- 'datastoreId' => nil
539
- }
540
-
541
571
  if plan_info['customizeVolume'] && storage_type['customLabel']
542
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "Disk #{volume_index} Volume Label", 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume_label}], options[:options])
572
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "Disk #{volume_index} Volume Label", 'required' => true, 'description' => 'Enter a volume label.', 'defaultValue' => volume['name']}], options[:options])
543
573
  volume['name'] = v_prompt[field_context]['name']
544
574
  end
545
575
  if plan_info['customizeVolume'] && storage_type['customSize']
546
576
  if custom_size_options.empty?
547
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => "Disk #{volume_index} Volume Size (GB)", 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => plan_size}], options[:options])
577
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'size', 'type' => 'number', 'fieldLabel' => "Disk #{volume_index} Volume Size (GB)", 'required' => true, 'description' => 'Enter a volume size (GB).', 'defaultValue' => volume['size']}], options[:options])
548
578
  volume['size'] = v_prompt[field_context]['size']
549
579
  volume['sizeId'] = nil #volume.delete('sizeId')
550
580
  else
551
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Volume Size", 'selectOptions' => custom_size_options, 'required' => true, 'description' => 'Choose a volume size.'}], options[:options])
581
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'sizeId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Volume Size", 'selectOptions' => custom_size_options, 'required' => true, 'description' => 'Choose a volume size.', 'defaultValue' => volume['sizeId']}], options[:options])
552
582
  volume['sizeId'] = v_prompt[field_context]['sizeId']
553
583
  volume['size'] = nil #volume.delete('size')
554
584
  end
@@ -558,17 +588,19 @@ module Morpheus::Cli::ProvisioningHelper
558
588
  volume['sizeId'] = nil #volume.delete('sizeId')
559
589
  end
560
590
  if !datastore_options.empty?
561
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Datastore", 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.'}], options[:options])
591
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'datastoreId', 'type' => 'select', 'fieldLabel' => "Disk #{volume_index} Datastore", 'selectOptions' => datastore_options, 'required' => true, 'description' => 'Choose a datastore.', 'defaultValue' => volume['datastoreId']}], options[:options])
562
592
  volume['datastoreId'] = v_prompt[field_context]['datastoreId']
563
593
  end
564
594
 
565
595
  volumes << volume
566
596
 
567
- # todo: should maxDisk check consider the root volume too?
568
- if plan_info['maxDisk'] && volume_index >= plan_info['maxDisk']
597
+ volume_index += 1
598
+ if options[:options] && options[:options]['volumes'] && options[:options]['volumes'][volume_index]
599
+ add_another_volume = true
600
+ elsif plan_info['maxDisk'] && volume_index >= plan_info['maxDisk']
601
+ # todo: should maxDisk check consider the root volume too?
569
602
  add_another_volume = false
570
603
  else
571
- volume_index += 1
572
604
  has_another_volume = options[:options] && options[:options]["dataVolume#{volume_index}"]
573
605
  add_another_volume = has_another_volume || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another data volume?", {:default => false}))
574
606
  end
@@ -904,20 +936,22 @@ module Morpheus::Cli::ProvisioningHelper
904
936
  end
905
937
  end
906
938
 
907
-
908
- interface_index = 1
939
+ interface_index = 0
909
940
  add_another_interface = true
910
941
  while add_another_interface do
911
942
  # if !no_prompt
912
- # if interface_index == 1
943
+ # if interface_index == 0
913
944
  # puts "Configure Network Interface"
914
945
  # else
915
- # puts "Configure Network Interface #{interface_index}"
946
+ # puts "Configure Network Interface #{interface_index+1}"
916
947
  # end
917
948
  # end
918
949
 
919
- field_context = interface_index == 1 ? "networkInterface" : "networkInterface#{interface_index}"
950
+ field_context = interface_index == 0 ? "networkInterface" : "networkInterface#{interface_index+1}"
920
951
  network_interface = {}
952
+ if options[:options] && options[:options]['networkInterfaces'] && options[:options]['networkInterfaces'][interface_index]
953
+ network_interface = options[:options]['networkInterfaces'][interface_index]
954
+ end
921
955
 
922
956
  # choose network
923
957
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'networkId', 'type' => 'select', 'fieldLabel' => "Network", 'selectOptions' => network_options, 'required' => true, 'skipSingleOption' => false, 'description' => 'Choose a network for this interface.', 'defaultValue' => network_interface['networkId']}], options[:options])
@@ -955,10 +989,12 @@ module Morpheus::Cli::ProvisioningHelper
955
989
 
956
990
  network_interfaces << network_interface
957
991
  interface_index += 1
958
- if max_networks && network_interfaces.size >= max_networks
992
+ if options[:options] && options[:options]['networkInterfaces'] && options[:options]['networkInterfaces'][interface_index]
993
+ add_another_interface = true
994
+ elsif max_networks && network_interfaces.size >= max_networks
959
995
  add_another_interface = false
960
996
  else
961
- has_another_interface = options[:options] && options[:options]["networkInterface#{interface_index}"]
997
+ has_another_interface = options[:options] && options[:options]["networkInterface#{interface_index+1}"]
962
998
  add_another_interface = has_another_interface || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another network interface?", {:default => false}))
963
999
  end
964
1000
 
@@ -299,7 +299,7 @@ class Morpheus::Cli::MonitoringChecksCommand
299
299
  end
300
300
 
301
301
  def add(args)
302
- options = {}
302
+ options = {:skip_booleanize => true}
303
303
  params = {'inUptime' => true, 'severity' => 'critical'}
304
304
  check_type = nil
305
305
  optparse = Morpheus::Cli::OptionParser.new do |opts|
@@ -376,7 +376,7 @@ class Morpheus::Cli::MonitoringChecksCommand
376
376
  end
377
377
 
378
378
  def update(args)
379
- options = {}
379
+ options = {:skip_booleanize => true}
380
380
  params = {}
381
381
  optparse = Morpheus::Cli::OptionParser.new do |opts|
382
382
  opts.banner = subcommand_usage("[name]")
@@ -44,6 +44,18 @@ module Morpheus
44
44
  context_map = results
45
45
  value = nil
46
46
  value_found=false
47
+
48
+
49
+ # How about this instead?
50
+ # option_type = option_type.clone
51
+ # field_key = [option_type['fieldContext'], option_type['fieldName']].select {|it| it && it != '' }.join('.')
52
+ # if field_key != ''
53
+ # value = get_object_value(options, field_key)
54
+ # if value != nil && options[:always_prompt] != true
55
+ # value_found = true
56
+ # end
57
+ # end
58
+
47
59
  if option_type['fieldContext']
48
60
  cur_namespace = options
49
61
  namespaces = option_type['fieldContext'].split(".")
@@ -63,7 +75,9 @@ module Morpheus
63
75
  # this should just fall down through below, with the extra params no_prompt, use_value
64
76
  value = select_prompt(option_type, api_client, api_params, true, value)
65
77
  end
66
- value_found = true
78
+ if options[:always_prompt] != true
79
+ value_found = true
80
+ end
67
81
  end
68
82
  else
69
83
  # no fieldContext
@@ -72,9 +86,19 @@ module Morpheus
72
86
  if option_type['type'] == 'number'
73
87
  value = value.to_s.include?('.') ? value.to_f : value.to_i
74
88
  end
75
- value_found = true
89
+ # still prompt
90
+ if options[:always_prompt] != true
91
+ value_found = true
92
+ end
76
93
  end
77
94
  end
95
+
96
+ # set the value that has been passed to the option type default value: options[fieldContext.fieldName]
97
+ if value != nil # && value != ''
98
+ option_type = option_type.clone
99
+ option_type['defaultValue'] = value
100
+ end
101
+
78
102
 
79
103
  # no_prompt means skip prompting and instead
80
104
  # use default value or error if a required option is not present
@@ -254,7 +278,10 @@ module Morpheus
254
278
 
255
279
  if no_prompt
256
280
  if !value_found
257
- if option_type['required']
281
+ if !select_options.nil? && select_options.count > 1 && option_type['autoPickOption'] == true
282
+ value_found = true
283
+ value = select_options[0]['value']
284
+ elsif option_type['required']
258
285
  print Term::ANSIColor.red, "\nMissing Required Option\n\n", Term::ANSIColor.reset
259
286
  print Term::ANSIColor.red, " * #{option_type['fieldLabel']} [-O #{option_type['fieldContext'] ? (option_type['fieldContext']+'.') : ''}#{option_type['fieldName']}=] - #{option_type['description']}\n", Term::ANSIColor.reset
260
287
  if select_options && select_options.size > 10
@@ -274,15 +274,19 @@ EOT
274
274
  options = {}
275
275
  checkall = false
276
276
  optparse = Morpheus::Cli::OptionParser.new do|opts|
277
- opts.banner = subcommand_usage("[name]")
277
+ opts.banner = <<-EOT
278
+ #{subcommand_usage("[name]")}
279
+ [name] is required. This is the name of the remote. Use 'current' to check the active appliance."
280
+ EOT
281
+ #opts.banner = "#{opts.banner}\n" + " " + "[name] is required. This is the name of the remote. Use 'current' to check the active appliance."
278
282
  opts.on("-a",'--all', "Refresh all appliances") do
279
283
  checkall = true
280
284
  end
281
285
  build_common_options(opts, options, [:quiet])
282
286
  opts.footer = <<-EOT
283
- This can be used to refresh a remote appliance status.
284
- It makes an api request to the configured appliance url, and stores the status
285
- of the server and other info, e.g. version, in the local morpheus cli configuration.
287
+ This can be used to refresh a remote appliance.
288
+ It makes an api request to the configured appliance url to check the status and version.
289
+ [name] is required. This is the name of the remote. Use 'current' to check the active appliance."
286
290
  EOT
287
291
  end
288
292
  optparse.parse!(args)