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
@@ -1321,7 +1321,7 @@ class Morpheus::Cli::Hosts
1321
1321
  payload = {}
1322
1322
  # i guess you must pass an option if there are editable options
1323
1323
  # any option, heh
1324
- task_types = @tasks_interface.task_types()
1324
+ task_types = @tasks_interface.list_types()
1325
1325
  editable_options = []
1326
1326
  workflow['taskSetTasks'].sort{|a,b| a['taskOrder'] <=> b['taskOrder']}.each do |task_set_task|
1327
1327
  task_type_id = task_set_task['task']['taskType']['id']
@@ -54,6 +54,7 @@ class Morpheus::Cli::Instances
54
54
 
55
55
  def list(args)
56
56
  options = {}
57
+ params = {}
57
58
  optparse = Morpheus::Cli::OptionParser.new do |opts|
58
59
  opts.banner = subcommand_usage()
59
60
  opts.on( '-g', '--group GROUP', "Group Name or ID" ) do |val|
@@ -71,6 +72,10 @@ class Morpheus::Cli::Instances
71
72
  opts.on('--details', "Display more details: memory and storage usage used / max values." ) do
72
73
  options[:details] = true
73
74
  end
75
+ opts.on('--status STATUS', "Filter by status i.e. provisioning,running,starting,stopping") do |val|
76
+ params['status'] ||= []
77
+ params['status'] << val
78
+ end
74
79
  opts.on('--pending-removal', "Include instances pending removal.") do
75
80
  options[:pendingRemoval] = true
76
81
  end
@@ -83,7 +88,6 @@ class Morpheus::Cli::Instances
83
88
  raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
84
89
  end
85
90
  begin
86
- params = {}
87
91
  params.merge!(parse_list_options(options))
88
92
  group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
89
93
  if group
@@ -333,6 +337,12 @@ class Morpheus::Cli::Instances
333
337
  opts.on("--workflow ID", String, "Automation: Workflow ID") do |val|
334
338
  options[:workflow_id] = val
335
339
  end
340
+ opts.on("--ports ARRAY", String, "Exposed Ports, JSON formatted list of objects containing name and port") do |val|
341
+ # expects format like --ports '[{"name":"web","port":8080}]'
342
+ ports_array = JSON.parse(val)
343
+ options[:ports] = ports_array
344
+ options[:options]['ports'] = ports_array
345
+ end
336
346
  # opts.on('-L', "--lb", "Enable Load Balancer") do
337
347
  # options[:enable_load_balancer] = true
338
348
  # end
@@ -342,10 +352,10 @@ class Morpheus::Cli::Instances
342
352
  opts.on("--user-group USERGROUP", String, "User Config: User Group") do |val|
343
353
  options[:user_group_id] = val
344
354
  end
345
- opts.on("--shutdown-days NUMBER", Integer, "Automation: Shutdown Days") do |val|
346
- options[:expire_days] = val.to_i
355
+ opts.on("--shutdown-days DAYS", Integer, "Automation: Shutdown Days") do |val|
356
+ options[:shutdown_days] = val.to_i
347
357
  end
348
- opts.on("--expire-days NUMBER", Integer, "Automation: Expiration Days") do |val|
358
+ opts.on("--expire-days DAYS", Integer, "Automation: Expiration Days") do |val|
349
359
  options[:expire_days] = val.to_i
350
360
  end
351
361
  opts.on("--create-backup [on|off]", String, "Automation: Create Backups.") do |val|
@@ -493,6 +503,12 @@ class Morpheus::Cli::Instances
493
503
  opts.on('--created-by ID', String, "Created By User ID") do |val|
494
504
  options[:created_by_id] = val
495
505
  end
506
+ # opts.on("--shutdown-days [DAYS]", Integer, "Automation: Shutdown Days") do |val|
507
+ # params['shutdownDays'] = val.to_s.empty? ? nil : val.to_i
508
+ # end
509
+ # opts.on("--expire-days DAYS", Integer, "Automation: Expiration Days") do |val|
510
+ # params['expireDays'] = val.to_s.empty? ? nil : val.to_i
511
+ # end
496
512
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
497
513
  end
498
514
  optparse.parse!(args)
@@ -2844,7 +2860,7 @@ class Morpheus::Cli::Instances
2844
2860
  connect(options)
2845
2861
  instance = find_instance_by_name_or_id(args[0])
2846
2862
  workflow = find_workflow_by_name_or_id(args[1])
2847
- task_types = @tasks_interface.task_types()
2863
+ task_types = @tasks_interface.list_types()
2848
2864
  editable_options = []
2849
2865
  workflow['taskSetTasks'].sort{|a,b| a['taskOrder'] <=> b['taskOrder']}.each do |task_set_task|
2850
2866
  task_type_id = task_set_task['task']['taskType']['id']
@@ -172,13 +172,22 @@ class Morpheus::Cli::JobsCommand
172
172
  print_h1 title, subtitles
173
173
 
174
174
  job = json_response['job']
175
- scheduleName = ''
175
+ schedule_name = ''
176
176
  if !job['scheduleMode'].nil?
177
177
  if job['scheduleMode'] == 'manual'
178
- scheduleName = 'Manual'
179
- else !job['scheduleMode']
180
- schedule = @execute_schedules_interface.get(job['scheduleMode'])['schedule']
181
- scheduleName = schedule ? schedule['name'] : ''
178
+ schedule_name = 'Manual'
179
+ elsif job['scheduleMode'].to_s.downcase == 'datetime'
180
+ schedule_name = ("Date and Time - " + (format_local_dt(job['dateTime']).to_s rescue 'n/a'))
181
+ elsif job['scheduleMode'].to_s == ''
182
+ schedule_name = 'n/a' # should not happen
183
+ else
184
+ begin
185
+ schedule = @execute_schedules_interface.get(job['scheduleMode'])['schedule']
186
+ schedule_name = schedule ? schedule['name'] : ''
187
+ rescue => ex
188
+ Morpheus::Logging::DarkPrinter.puts "Failed to load schedule name" if Morpheus::Logging.debug?
189
+ schedule_name = 'n/a'
190
+ end
182
191
  end
183
192
  end
184
193
 
@@ -189,7 +198,7 @@ class Morpheus::Cli::JobsCommand
189
198
  "Job Type" => lambda {|it| it['type']['name']},
190
199
  "Enabled" => lambda {|it| format_boolean(it['enabled'])},
191
200
  (job['workflow'] ? 'Workflow' : 'Task') => lambda {|it| it['jobSummary']},
192
- "Schedule" => lambda {|it| scheduleName}
201
+ "Schedule" => lambda {|it| schedule_name}
193
202
  }
194
203
 
195
204
  if job['targetType']
@@ -263,6 +272,10 @@ class Morpheus::Cli::JobsCommand
263
272
  opts.on('-R', '--run [on|off]', String, "Can be used to run the job now.") do |val|
264
273
  params['run'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
265
274
  end
275
+ opts.on('--date-time DATETIME', String, "Can be used to run schedule at a specific date and time. Use UTC time in the format 2020-02-15T05:00:00Z. This sets scheduleMode to 'dateTime'.") do |val|
276
+ options[:schedule] = 'dateTime'
277
+ params['dateTime'] = val.to_s
278
+ end
266
279
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
267
280
  opts.footer = "Create job."
268
281
  end
@@ -274,9 +287,11 @@ class Morpheus::Cli::JobsCommand
274
287
  end
275
288
 
276
289
  begin
277
- payload = parse_payload(options)
290
+ if options[:payload]
291
+ payload = parse_payload(options, 'job')
292
+ else
293
+ apply_options(params, options)
278
294
 
279
- if !payload
280
295
  # name
281
296
  params['name'] = params['name'] || args[0] || name = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Job Name', 'required' => true, 'description' => 'Job Name.'}],options[:options],@api_client,{})['name']
282
297
 
@@ -290,11 +305,9 @@ class Morpheus::Cli::JobsCommand
290
305
 
291
306
  # prompt task / workflow
292
307
  if job_type['code'] == 'morpheus.task'
293
- task_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'task', 'fieldLabel' => 'Task', 'type' => 'select', 'required' => true, 'optionSource' => 'tasks'}], {'optionTypeId' => job_options['optionTypes'][0]['id']}, @api_client, {})['task']
294
- params['task'] = {'id' => task_id}
308
+ params['task'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'task.id', 'fieldLabel' => 'Task', 'type' => 'select', 'required' => true, 'optionSource' => 'tasks'}], options[:options], @api_client, {})['task']
295
309
  else
296
- workflow_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'workflow', 'fieldLabel' => 'Workflow', 'type' => 'select', 'required' => true, 'optionSource' => 'operationTaskSets'}], {'optionTypeId' => job_options['optionTypes'][0]['id']}, @api_client, {})['workflow']
297
- params['workflow'] = {'id' => workflow_id}
310
+ params['workflow'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'workflow.id', 'fieldLabel' => 'Workflow', 'type' => 'select', 'required' => true, 'optionSource' => 'operationTaskSets'}], options[:options], @api_client, {})['workflow']
298
311
  end
299
312
  end
300
313
 
@@ -328,7 +341,7 @@ class Morpheus::Cli::JobsCommand
328
341
 
329
342
  # context type
330
343
  if params['targetType'].nil?
331
- params['targetType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'contextType', 'fieldLabel' => 'Context Type', 'type' => 'select', 'required' => true, 'selectOptions' => job_options['targetTypes'], 'defaultValue' => job_options['targetTypes'].first['name']}], {'optionTypeId' => option_type_id}, @api_client, {})['contextType']
344
+ params['targetType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'targetType', 'fieldLabel' => 'Context Type', 'type' => 'select', 'required' => true, 'selectOptions' => job_options['targetTypes'], 'defaultValue' => job_options['targetTypes'].first['name']}], options[:options], @api_client, {})['targetType']
332
345
  end
333
346
 
334
347
  # contexts
@@ -356,19 +369,28 @@ class Morpheus::Cli::JobsCommand
356
369
 
357
370
  # schedule
358
371
  if options[:schedule].nil?
359
- params['scheduleMode'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'schedule', 'fieldLabel' => "Schedule", 'type' => 'select', 'required' => true, 'selectOptions' => job_options['schedules'], 'defaultValue' => job_options['schedules'].first['name']}], options[:options], @api_client, {})['schedule']
360
- else
361
- if options[:schedule] != 'manual'
362
- schedule = job_options['schedules'].find {|it| it['name'] == options[:schedule] || it['value'] == options[:schedule].to_i}
372
+ options[:schedule] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'scheduleMode', 'fieldLabel' => "Schedule", 'type' => 'select', 'required' => true, 'selectOptions' => job_options['schedules'], 'defaultValue' => job_options['schedules'].first['name']}], options[:options], @api_client, {})['scheduleMode']
373
+ params['scheduleMode'] = options[:schedule]
374
+ end
363
375
 
364
- if schedule.nil?
365
- print_red_alert "Schedule #{options[:schedule]} not found"
366
- exit 1
367
- end
368
- options[:schedule] = schedule['value']
376
+ if options[:schedule] == 'manual'
377
+ # cool
378
+ elsif options[:schedule].to_s.downcase == 'datetime'
379
+ # prompt for dateTime
380
+ if params['dateTime'].nil?
381
+ params['dateTime'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'dateTime', 'fieldLabel' => "Date and Time", 'type' => 'text', 'required' => true}], options[:options], @api_client, {}, options[:no_prompt], true)['dateTime']
369
382
  end
370
- params['scheduleMode'] = options[:schedule]
383
+ elsif options[:schedule].to_s != ''
384
+ # ok they passed a schedule name or id
385
+ schedule = job_options['schedules'].find {|it| it['name'] == options[:schedule] || it['value'] == options[:schedule].to_i}
386
+
387
+ if schedule.nil?
388
+ print_red_alert "Schedule #{options[:schedule]} not found"
389
+ exit 1
390
+ end
391
+ options[:schedule] = schedule['value']
371
392
  end
393
+ params['scheduleMode'] = options[:schedule]
372
394
 
373
395
  # custom config
374
396
  if params['customConfig'].nil? && job_options['allowCustomConfig']
@@ -446,7 +468,11 @@ class Morpheus::Cli::JobsCommand
446
468
  opts.on('-R', '--run [on|off]', String, "Can be used to run the job now.") do |val|
447
469
  params['run'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
448
470
  end
449
- build_common_options(opts, options, [:payload, :list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
471
+ opts.on('--date-time DATETIME', String, "Can be used to run schedule at a specific date and time. Use UTC time in the format 2020-02-15T05:00:00Z. This sets scheduleMode to 'dateTime'.") do |val|
472
+ options[:schedule] = 'dateTime'
473
+ params['dateTime'] = val.to_s
474
+ end
475
+ build_common_options(opts, options, [:options, :payload, :list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
450
476
  opts.footer = "Update job.\n" +
451
477
  "[job] is required. Job ID or name"
452
478
  end
@@ -465,9 +491,11 @@ class Morpheus::Cli::JobsCommand
465
491
  exit 1
466
492
  end
467
493
 
468
- payload = parse_payload(options)
494
+ if options[:payload]
495
+ payload = parse_payload(options, 'job')
496
+ else
497
+ apply_options(params, options)
469
498
 
470
- if !payload
471
499
  job_type_id = job['type']['id']
472
500
 
473
501
  if !options[:task].nil?
@@ -507,7 +535,7 @@ class Morpheus::Cli::JobsCommand
507
535
  end
508
536
 
509
537
  if !options[:schedule].nil?
510
- if options[:schedule] != 'manual'
538
+ if options[:schedule] != 'manual' && options[:schedule].to_s.downcase != 'datetime'
511
539
  job_options = @jobs_interface.options(job_type_id)
512
540
  schedule = job_options['schedules'].find {|it| it['name'] == options[:schedule] || it['value'] == options[:schedule].to_i}
513
541
 
@@ -519,6 +547,34 @@ class Morpheus::Cli::JobsCommand
519
547
  end
520
548
  params['scheduleMode'] = options[:schedule]
521
549
  end
550
+
551
+
552
+ # schedule
553
+ if !options[:schedule].nil?
554
+
555
+
556
+ if options[:schedule] == 'manual'
557
+ # cool
558
+ elsif options[:schedule].to_s.downcase == 'datetime'
559
+ # prompt for dateTime
560
+ if params['dateTime'].nil?
561
+ raise_command_error "--date-time is required for schedule '#{options[:schedule]}'\n#{optparse}"
562
+ end
563
+ elsif options[:schedule].to_s != ''
564
+ job_options = @jobs_interface.options(job_type_id)
565
+ options[:schedule] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'schedule', 'fieldLabel' => "Schedule", 'type' => 'select', 'required' => true, 'selectOptions' => job_options['schedules'], 'defaultValue' => job_options['schedules'].first['name']}], options[:options], @api_client, {})['schedule']
566
+ params['scheduleMode'] = options[:schedule]
567
+ # ok they passed a schedule name or id
568
+ schedule = job_options['schedules'].find {|it| it['name'] == options[:schedule] || it['value'] == options[:schedule].to_i}
569
+
570
+ if schedule.nil?
571
+ print_red_alert "Schedule #{options[:schedule]} not found"
572
+ exit 1
573
+ end
574
+ options[:schedule] = schedule['value']
575
+ end
576
+ end
577
+
522
578
  payload = {'job' => params}
523
579
  end
524
580
 
@@ -295,17 +295,17 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
295
295
 
296
296
  # prompt for options
297
297
  if params['name'].nil?
298
- params['name'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Name', 'required' => true}], options[:options], @api_client,{})['value']
298
+ params['name'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Name', 'required' => true}], options[:options], @api_client,{})['name']
299
299
  end
300
300
 
301
301
  # version
302
302
  if params['computeVersion'].nil?
303
- params['computeVersion'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Version', 'required' => true}], options[:options], @api_client,{})['value']
303
+ params['computeVersion'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'computeVersion', 'type' => 'text', 'fieldLabel' => 'Version', 'required' => true}], options[:options], @api_client,{})['computeVersion']
304
304
  end
305
305
 
306
306
  # description
307
307
  if params['description'].nil?
308
- params['description'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Description', 'required' => false}], options[:options], @api_client,{})['value']
308
+ params['description'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'type' => 'text', 'fieldLabel' => 'Description', 'required' => false}], options[:options], @api_client,{})['description']
309
309
  end
310
310
 
311
311
  # creatable
@@ -322,7 +322,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
322
322
  end
323
323
  else
324
324
  cluster_type_options = cluster_types.collect {|type| {'name' => type['name'], 'value' => type['code']}}
325
- cluster_type_code = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'select', 'fieldLabel' => 'Cluster Type', 'required' => true, 'selectOptions' => cluster_type_options}], options[:options], @api_client,{}, nil, true)['value']
325
+ cluster_type_code = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'groupType', 'type' => 'select', 'fieldLabel' => 'Cluster Type', 'required' => true, 'selectOptions' => cluster_type_options}], options[:options], @api_client,{}, nil, true)['groupType']
326
326
  cluster_type = cluster_types.find {|type| type['code'] == cluster_type_code}
327
327
  end
328
328
 
@@ -337,7 +337,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
337
337
  end
338
338
  else
339
339
  provision_type_options = provision_types.collect {|type| {'name' => type['name'], 'value' => type['code']}}
340
- provision_type_code = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'select', 'fieldLabel' => 'Technology', 'required' => true, 'selectOptions' => provision_type_options}], options[:options], @api_client,{}, nil, true)['value']
340
+ provision_type_code = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'provisionType', 'type' => 'select', 'fieldLabel' => 'Technology', 'required' => true, 'selectOptions' => provision_type_options}], options[:options], @api_client,{}, nil, true)['provisionType']
341
341
  provision_type = provision_types.find {|type| type['code'] == provision_type_code}
342
342
  end
343
343
 
@@ -345,7 +345,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
345
345
 
346
346
  # min memory
347
347
  if params['memoryRequirement'].nil?
348
- memory = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Minimum Memory (MB) [can use GB modifier]', 'required' => false, 'description' => 'Memory (MB)'}],options[:options],@api_client,{}, options[:no_prompt])['value']
348
+ memory = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryRequirement', 'type' => 'text', 'fieldLabel' => 'Minimum Memory (MB) [can use GB modifier]', 'required' => false, 'description' => 'Memory (MB)'}], options[:options], @api_client,{}, options[:no_prompt])['memoryRequirement']
349
349
 
350
350
  if memory
351
351
  bytes = parse_bytes_param(memory, 'minimum memory', 'MB')
@@ -363,7 +363,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
363
363
  end
364
364
  params['taskSets'] = [{'id' => task_set['id']}]
365
365
  else
366
- task_set_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'fieldLabel' => 'Workflow', 'type' => 'select', 'required' => false, 'optionSource' => 'taskSets'}], {}, @api_client, {})['value']
366
+ task_set_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'taskSets', 'fieldLabel' => 'Workflow', 'type' => 'select', 'required' => false, 'optionSource' => 'taskSets'}], options[:options], @api_client, {})['taskSets']
367
367
 
368
368
  if task_set_id
369
369
  params['taskSets'] = [{'id' => task_set_id.to_i}]
@@ -399,7 +399,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
399
399
  avail_type_options = @options_types_interface.list({'max' => 1000})['optionTypes'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
400
400
  option_types = []
401
401
  while !avail_type_options.empty? && Morpheus::Cli::OptionTypes.confirm("Add #{option_types.empty? ? '' : 'another '}option type?", {:default => false}) do
402
- option_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'select', 'fieldLabel' => 'Option Type', 'selectOptions' => avail_type_options, 'required' => false}],options[:options],@api_client,{}, options[:no_prompt], true)['value']
402
+ option_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'optionType', 'type' => 'select', 'fieldLabel' => 'Option Type', 'selectOptions' => avail_type_options, 'required' => false}],options[:options],@api_client,{}, options[:no_prompt], true)['optionType']
403
403
 
404
404
  if option_type_id
405
405
  option_types << {'id' => option_type_id.to_i}
@@ -437,9 +437,9 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
437
437
  else
438
438
  avail_container_types = @library_container_types_interface.list(nil, {'technology' => provision_type['code'], 'max' => 1000})['containerTypes'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
439
439
  while !avail_container_types.empty? && Morpheus::Cli::OptionTypes.confirm("Add #{nodes.empty? ? '' : 'another '}#{node_type} node?", {:default => false}) do
440
- container_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'select', 'fieldLabel' => "#{node_type.capitalize} Node", 'selectOptions' => avail_container_types, 'required' => true}],options[:options],@api_client,{}, options[:no_prompt], true)['value']
441
- node_count = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'number', 'fieldLabel' => "#{node_type.capitalize} Node Count", 'required' => true, 'defaultValue' => 1}], options[:options], @api_client, {}, options[:no_prompt])['value']
442
- priority = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'number', 'fieldLabel' => "#{node_type.capitalize} Priority", 'required' => true, 'defaultValue' => priority}], options[:options], @api_client, {}, options[:no_prompt])['value']
440
+ container_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => "#{node_type}ContainerType", 'type' => 'select', 'fieldLabel' => "#{node_type.capitalize} Node", 'selectOptions' => avail_container_types, 'required' => true}],options[:options],@api_client,{}, options[:no_prompt], true)["#{node_type}ContainerType"]
441
+ node_count = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => "#{node_type}NodeCount", 'type' => 'number', 'fieldLabel' => "#{node_type.capitalize} Node Count", 'required' => true, 'defaultValue' => 1}], options[:options], @api_client, {}, options[:no_prompt])["#{node_type}NodeCount"]
442
+ priority = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => "#{node_type}Priority", 'type' => 'number', 'fieldLabel' => "#{node_type.capitalize} Priority", 'required' => true, 'defaultValue' => priority}], options[:options], @api_client, {}, options[:no_prompt])["#{node_type}Priority"]
443
443
  nodes << {'nodeCount' => node_count, 'priorityOrder' => priority, 'containerType' => {'id' => container_type_id.to_i}}
444
444
  avail_container_types.reject! {|it| it['value'] == container_type_id}
445
445
  end
@@ -863,7 +863,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
863
863
  end
864
864
 
865
865
  def prompt_evar(options)
866
- name = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Variable Name', 'required' => true}], options[:options], @api_client,{})['value']
866
+ name = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Variable Name', 'required' => true}], options[:options], @api_client,{})['name']
867
867
  value = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'value', 'type' => 'text', 'fieldLabel' => 'Variable Value', 'required' => false}], options[:options], @api_client,{})['value']
868
868
  masked = Morpheus::Cli::OptionTypes.confirm("Variable Masked?", {:default => false}) == true
869
869
  export = Morpheus::Cli::OptionTypes.confirm("Variable Label?", {:default => false}) == true
@@ -28,7 +28,7 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
28
28
  connect(options)
29
29
  if args.count > 0
30
30
  print_error Morpheus::Terminal.angry_prompt
31
- puts_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.inspect}\n#{optparse}"
31
+ puts_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
32
32
  return 1
33
33
  end
34
34
  begin
@@ -122,10 +122,11 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
122
122
  "Name" => lambda {|it| it['name'] },
123
123
  "Type" => lambda {|it| format_container_script_type(it['scriptType']) },
124
124
  "Phase" => lambda {|it| format_container_script_phase(it['scriptPhase']) },
125
+ "Run As User" => lambda {|it| it['runAsUser'] },
126
+ "Sudo" => lambda {|it| format_boolean(it['sudoUser']) },
125
127
  "Owner" => lambda {|it| it['account'] ? it['account']['name'] : '' },
126
- # "Enabled" => lambda {|it| format_boolean it['enabled'] },
127
- # "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
128
- # "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
128
+ "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
129
+ "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
129
130
  }
130
131
  print_description_list(description_cols, container_script)
131
132
 
@@ -144,22 +145,19 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
144
145
  end
145
146
 
146
147
  def add(args)
148
+ params = {} # {'scriptType' => 'bash', 'scriptPhase' => 'provision'}
147
149
  options = {}
148
- params = {'scriptType' => 'bash', 'scriptPhase' => 'provision'}
149
150
  optparse = Morpheus::Cli::OptionParser.new do |opts|
150
151
  opts.banner = subcommand_usage("[name]")
151
152
  opts.on('--name VALUE', String, "Name") do |val|
152
153
  params['name'] = val
153
154
  end
154
- opts.on('--type [bash|powershell]', String, "Script Type. Default is 'bash'") do |val|
155
+ opts.on('-t', '--type TYPE', "Script Type. i.e. bash, powershell. Default is bash.") do |val|
155
156
  params['scriptType'] = val
156
157
  end
157
- opts.on('--phase [provision|start|stop]', String, "Script Phase. Default is 'provision'") do |val|
158
+ opts.on('--phase PHASE', String, "Script Phase. i.e. start, stop, preProvision, provision, postProvision, preDeploy, deploy, reconfigure, teardown. Default is provision.") do |val|
158
159
  params['scriptPhase'] = val
159
- end
160
- opts.on('--category VALUE', String, "Category") do |val|
161
- params['category'] = val
162
- end
160
+ end
163
161
  opts.on('--script TEXT', String, "Contents of the script.") do |val|
164
162
  params['script'] = val
165
163
  end
@@ -176,8 +174,14 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
176
174
  params['name'] = File.basename(full_filename)
177
175
  end
178
176
  end
179
- # opts.on('--enabled [on|off]', String, "Can be used to disable it") do |val|
180
- # options['enabled'] = !(val.to_s == 'off' || val.to_s == 'false')
177
+ opts.on("--sudo [on|off]", String, "Run with sudo") do |val|
178
+ params['sudoUser'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
179
+ end
180
+ opts.on("--run-as-user VALUE", String, "Run as user") do |val|
181
+ params['runAsUser'] = val
182
+ end
183
+ # opts.on("--run-as-password VALUE", String, "Run as password") do |val|
184
+ # params['runAsPassword'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
181
185
  # end
182
186
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
183
187
  opts.footer = "Create a new container script." + "\n" +
@@ -188,22 +192,27 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
188
192
  if args[0]
189
193
  params['name'] = args[0]
190
194
  end
191
- if !params['name']
192
- print_error Morpheus::Terminal.angry_prompt
193
- puts_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
194
- return 1
195
- end
196
195
  connect(options)
197
196
  begin
198
- # construct payload
199
197
  payload = nil
198
+ arbitrary_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
199
+ create_payload = {}
200
+ create_payload.deep_merge!(params)
201
+ create_payload.deep_merge!(arbitrary_options)
200
202
  if options[:payload]
201
203
  payload = options[:payload]
204
+ payload.deep_merge!({'containerScript' => create_payload}) unless create_payload.empty?
202
205
  else
203
- # merge -O options into normally parsed options
204
- params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
205
- # todo: prompt?
206
- payload = {'containerScript' => params}
206
+ prompt_result = Morpheus::Cli::OptionTypes.prompt([
207
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true},
208
+ {'fieldName' => 'scriptType', 'fieldLabel' => 'Type', 'type' => 'select', 'optionSource' => 'scriptTypes', 'defaultValue' => 'bash', 'required' => true},
209
+ {'fieldName' => 'scriptPhase', 'fieldLabel' => 'Phase', 'type' => 'select', 'optionSource' => 'containerPhases', 'defaultValue' => 'provision', 'required' => true},
210
+ {'fieldName' => 'script', 'fieldLabel' => 'Script', 'type' => 'code-editor', 'required' => true},
211
+ {'fieldName' => 'runAsUser', 'fieldLabel' => 'Run As User', 'type' => 'text'},
212
+ {'fieldName' => 'sudoUser', 'fieldLabel' => 'Sudo', 'type' => 'checkbox', 'defaultValue' => false},
213
+ ], params.deep_merge(options[:options] || {}), @api_client)
214
+ create_payload.deep_merge!(prompt_result)
215
+ payload = {'containerScript' => create_payload}
207
216
  end
208
217
  @container_scripts_interface.setopts(options)
209
218
  if options[:dry_run]
@@ -234,21 +243,12 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
234
243
  opts.on('--name VALUE', String, "Name") do |val|
235
244
  params['name'] = val
236
245
  end
237
- # opts.on('--code VALUE', String, "Code") do |val|
238
- # params['code'] = val
239
- # end
240
- # opts.on('--description VALUE', String, "Description") do |val|
241
- # params['description'] = val
242
- # end
243
- opts.on('--type [bash|powershell]', String, "Script Type") do |val|
246
+ opts.on('-t', '--type TYPE', "Script Type. i.e. bash, powershell. Default is bash.") do |val|
244
247
  params['scriptType'] = val
245
248
  end
246
- opts.on('--phase [start|stop]', String, "Script Phase") do |val|
249
+ opts.on('--phase PHASE', String, "Script Phase. i.e. start, stop, preProvision, provision, postProvision, preDeploy, deploy, reconfigure, teardown. Default is provision.") do |val|
247
250
  params['scriptPhase'] = val
248
- end
249
- opts.on('--category VALUE', String, "Category") do |val|
250
- params['category'] = val
251
- end
251
+ end
252
252
  opts.on('--script TEXT', String, "Contents of the script.") do |val|
253
253
  params['script'] = val
254
254
  end
@@ -261,8 +261,14 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
261
261
  exit 1
262
262
  end
263
263
  end
264
- # opts.on('--enabled [on|off]', String, "Can be used to disable it") do |val|
265
- # options['enabled'] = !(val.to_s == 'off' || val.to_s == 'false')
264
+ opts.on("--sudo [on|off]", String, "Run with sudo") do |val|
265
+ params['sudoUser'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
266
+ end
267
+ opts.on("--run-as-user VALUE", String, "Run as user") do |val|
268
+ params['runAsUser'] = val
269
+ end
270
+ # opts.on("--run-as-password VALUE", String, "Run as password") do |val|
271
+ # params['runAsPassword'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
266
272
  # end
267
273
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
268
274
  opts.footer = "Update a container script." + "\n" +
@@ -271,7 +277,7 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
271
277
  optparse.parse!(args)
272
278
  if args.count != 1
273
279
  print_error Morpheus::Terminal.angry_prompt
274
- puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
280
+ puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
275
281
  return 1
276
282
  end
277
283
  connect(options)
@@ -284,10 +290,16 @@ class Morpheus::Cli::LibraryContainerScriptsCommand
284
290
  payload = nil
285
291
  if options[:payload]
286
292
  payload = options[:payload]
293
+ params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
294
+ payload.deep_merge!({'containerScript' => params}) unless params.empty?
287
295
  else
288
- # merge -O options into normally parsed options
296
+ # update without prompting
289
297
  params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
290
- payload = {'containerScript' => params}
298
+ script_payload = params
299
+ if script_payload.empty?
300
+ raise_command_error "Specify at least one option to update.\n#{optparse}"
301
+ end
302
+ payload = {'containerScript' => script_payload}
291
303
  end
292
304
  @container_scripts_interface.setopts(options)
293
305
  if options[:dry_run]