morpheus-cli 3.3.1.4 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/api_client.rb +28 -0
  3. data/lib/morpheus/api/instance_types_interface.rb +12 -10
  4. data/lib/morpheus/api/instances_interface.rb +4 -0
  5. data/lib/morpheus/api/library_container_scripts_interface.rb +49 -0
  6. data/lib/morpheus/api/library_container_templates_interface.rb +49 -0
  7. data/lib/morpheus/api/library_container_types_interface.rb +65 -0
  8. data/lib/morpheus/api/library_container_upgrades_interface.rb +66 -0
  9. data/lib/morpheus/api/library_instance_types_interface.rb +59 -0
  10. data/lib/morpheus/api/library_layouts_interface.rb +65 -0
  11. data/lib/morpheus/api/servers_interface.rb +4 -0
  12. data/lib/morpheus/api/user_sources_interface.rb +120 -0
  13. data/lib/morpheus/api/virtual_images_interface.rb +7 -0
  14. data/lib/morpheus/cli.rb +12 -1
  15. data/lib/morpheus/cli/accounts.rb +35 -9
  16. data/lib/morpheus/cli/cli_command.rb +82 -2
  17. data/lib/morpheus/cli/curl_command.rb +1 -1
  18. data/lib/morpheus/cli/echo_command.rb +1 -1
  19. data/lib/morpheus/cli/hosts.rb +40 -14
  20. data/lib/morpheus/cli/instance_types.rb +106 -64
  21. data/lib/morpheus/cli/instances.rb +39 -15
  22. data/lib/morpheus/cli/library.rb +1 -1184
  23. data/lib/morpheus/cli/library_container_scripts_command.rb +437 -0
  24. data/lib/morpheus/cli/library_container_templates_command.rb +397 -0
  25. data/lib/morpheus/cli/library_container_types_command.rb +653 -0
  26. data/lib/morpheus/cli/library_instance_types_command.rb +491 -0
  27. data/lib/morpheus/cli/library_layouts_command.rb +650 -0
  28. data/lib/morpheus/cli/library_option_lists_command.rb +476 -0
  29. data/lib/morpheus/cli/library_option_types_command.rb +549 -0
  30. data/lib/morpheus/cli/library_upgrades_command.rb +604 -0
  31. data/lib/morpheus/cli/mixins/library_helper.rb +123 -0
  32. data/lib/morpheus/cli/mixins/print_helper.rb +21 -22
  33. data/lib/morpheus/cli/mixins/provisioning_helper.rb +56 -11
  34. data/lib/morpheus/cli/network_services_command.rb +1 -1
  35. data/lib/morpheus/cli/option_types.rb +12 -2
  36. data/lib/morpheus/cli/power_scheduling_command.rb +1 -1
  37. data/lib/morpheus/cli/shell.rb +120 -22
  38. data/lib/morpheus/cli/sleep_command.rb +45 -0
  39. data/lib/morpheus/cli/user_sources_command.rb +963 -0
  40. data/lib/morpheus/cli/users.rb +33 -2
  41. data/lib/morpheus/cli/version.rb +1 -1
  42. data/lib/morpheus/cli/version_command.rb +1 -1
  43. data/lib/morpheus/cli/virtual_images.rb +93 -39
  44. data/lib/morpheus/formatters.rb +37 -27
  45. data/lib/morpheus/terminal.rb +1 -1
  46. metadata +20 -2
@@ -0,0 +1,549 @@
1
+ require 'io/console'
2
+ require 'optparse'
3
+ require 'filesize'
4
+ require 'morpheus/cli/cli_command'
5
+ require 'morpheus/cli/mixins/library_helper'
6
+
7
+ class Morpheus::Cli::LibraryOptionTypesCommand
8
+ include Morpheus::Cli::CliCommand
9
+ include Morpheus::Cli::LibraryHelper
10
+
11
+ set_command_name :'library-option-types'
12
+ register_subcommands :list, :get, :add, :update, :remove
13
+
14
+ def initialize()
15
+ # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
16
+ end
17
+
18
+ def connect(opts)
19
+ @api_client = establish_remote_appliance_connection(opts)
20
+ @library_instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).library_instance_types
21
+ @provision_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).provision_types
22
+ @option_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_types
23
+ @option_type_lists_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_type_lists
24
+ end
25
+
26
+ def handle(args)
27
+ handle_subcommand(args)
28
+ end
29
+
30
+ def list(args)
31
+ options = {}
32
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
33
+ opts.banner = subcommand_usage()
34
+ build_common_options(opts, options, [:list, :query, :dry_run, :json, :remote])
35
+ opts.footer = "List option types."
36
+ end
37
+ optparse.parse!(args)
38
+ connect(options)
39
+ begin
40
+ params = {}
41
+ params.merge!(parse_list_options(options))
42
+ if options[:dry_run]
43
+ print_dry_run @option_types_interface.dry.list(params)
44
+ return
45
+ end
46
+
47
+ json_response = @option_types_interface.list(params)
48
+
49
+ if options[:json]
50
+ print JSON.pretty_generate(json_response), "\n"
51
+ return
52
+ end
53
+
54
+ option_types = json_response['optionTypes']
55
+ subtitles = []
56
+ subtitles += parse_list_subtitles(options)
57
+ print_h1 "Morpheus Option Types", subtitles
58
+ if option_types.empty?
59
+ print cyan,"No option types found.",reset,"\n"
60
+ else
61
+ rows = option_types.collect do |option_type|
62
+ {
63
+ id: option_type['id'],
64
+ name: option_type['name'],
65
+ type: option_type['type'],
66
+ fieldLabel: option_type['fieldLabel'],
67
+ fieldName: option_type['fieldName'],
68
+ default: option_type['defaultValue'],
69
+ required: option_type['required'] ? 'yes' : 'no'
70
+ }
71
+ end
72
+ print cyan
73
+ tp rows, [
74
+ :id,
75
+ :name,
76
+ :type,
77
+ {:fieldLabel => {:display_name => "Field Label"} },
78
+ {:fieldName => {:display_name => "Field Name"} },
79
+ :default,
80
+ :required
81
+ ]
82
+ print reset
83
+ print_results_pagination(json_response)
84
+ end
85
+ print reset,"\n"
86
+ rescue RestClient::Exception => e
87
+ print_rest_exception(e, options)
88
+ exit 1
89
+ end
90
+ end
91
+
92
+ def get(args)
93
+ options = {}
94
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
95
+ opts.banner = subcommand_usage("[name]")
96
+ build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
97
+ end
98
+ optparse.parse!(args)
99
+ if args.count < 1
100
+ puts optparse
101
+ return 1
102
+ end
103
+ connect(options)
104
+ id_list = parse_id_list(args)
105
+ return run_command_for_each_arg(id_list) do |arg|
106
+ _get(arg, options)
107
+ end
108
+ end
109
+
110
+ def _get(id, options)
111
+ begin
112
+ if options[:dry_run]
113
+ if id.to_s =~ /\A\d{1,}\Z/
114
+ print_dry_run @option_types_interface.dry.get(id.to_i)
115
+ else
116
+ print_dry_run @option_types_interface.dry.list({name: id})
117
+ end
118
+ return
119
+ end
120
+ option_type = find_option_type_by_name_or_id(id)
121
+ exit 1 if option_type.nil?
122
+
123
+ if options[:include_fields]
124
+ json_response = {"optionType" => filter_data(json_response["optionType"], options[:include_fields]) }
125
+ end
126
+ if options[:json]
127
+ puts as_json(json_response, options)
128
+ return 0
129
+ elsif options[:yaml]
130
+ puts as_yaml(json_response, options)
131
+ return 0
132
+ elsif options[:csv]
133
+ puts records_as_csv([json_response['optionType']], options)
134
+ return 0
135
+ end
136
+
137
+ print_h1 "Option Type Details"
138
+ print cyan
139
+ print_description_list({
140
+ "ID" => 'id',
141
+ "Name" => 'name',
142
+ "Description" => 'description',
143
+ "Field Label" => 'fieldLabel',
144
+ # "Field Context" => 'fieldContext',
145
+ # "Field Name" => 'fieldName',
146
+ "Full Field Name" => lambda {|it| [it['fieldContext'], it['fieldName']].select {|it| !it.to_s.empty? }.join('.') },
147
+ "Type" => lambda {|it| it['type'].to_s.capitalize },
148
+ "Placeholder" => 'placeHolder',
149
+ "Default Value" => 'defaultValue'
150
+ }, option_type)
151
+ print reset,"\n"
152
+
153
+ rescue RestClient::Exception => e
154
+ print_rest_exception(e, options)
155
+ exit 1
156
+ end
157
+ end
158
+
159
+ def add(args)
160
+ # JD: this is annoying because our option_types (for prompting and help)
161
+ # are the same type of object being managed here.., options options options
162
+ options = {}
163
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
164
+ opts.banner = subcommand_usage("[options]")
165
+ build_option_type_options(opts, options, new_option_type_option_types)
166
+ build_common_options(opts, options, [:options, :json, :dry_run, :remote])
167
+ end
168
+ optparse.parse!(args)
169
+ connect(options)
170
+ begin
171
+ params = Morpheus::Cli::OptionTypes.prompt(new_option_type_option_types, options[:options], @api_client, options[:params])
172
+ if params.key?('required')
173
+ params['required'] = ['on','true'].include?(params['required'].to_s)
174
+ end
175
+ option_type_payload = params
176
+ payload = {optionType: option_type_payload}
177
+ if options[:dry_run]
178
+ print_dry_run @option_types_interface.dry.create(payload)
179
+ return
180
+ end
181
+ json_response = @option_types_interface.create(payload)
182
+ if options[:json]
183
+ print JSON.pretty_generate(json_response), "\n"
184
+ return
185
+ end
186
+ option_type = json_response['optionType']
187
+ print_green_success "Added Option Type #{option_type['name']}"
188
+ #list([])
189
+ get([option_type['id']])
190
+ rescue RestClient::Exception => e
191
+ print_rest_exception(e, options)
192
+ exit 1
193
+ end
194
+ end
195
+
196
+ def update(args)
197
+ # JD: this is annoying because our option_types (for prompting and help)
198
+ # are the same type of object being managed here.., options options options
199
+ options = {}
200
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
201
+ opts.banner = subcommand_usage("[name] [options]")
202
+ build_option_type_options(opts, options, update_option_type_option_types)
203
+ build_common_options(opts, options, [:options, :json, :dry_run, :remote])
204
+ end
205
+ optparse.parse!(args)
206
+ connect(options)
207
+ begin
208
+ option_type = find_option_type_by_name_or_id(args[0])
209
+ exit 1 if option_type.nil?
210
+
211
+ #params = options[:options] || {}
212
+ params = Morpheus::Cli::OptionTypes.no_prompt(update_option_type_option_types, options[:options], @api_client, options[:params])
213
+ if params.empty?
214
+ print_red_alert "Specify atleast one option to update"
215
+ puts optparse
216
+ exit 1
217
+ end
218
+ if params.key?('required')
219
+ params['required'] = ['on','true'].include?(params['required'].to_s)
220
+ end
221
+ option_type_payload = params
222
+ payload = {optionType: option_type_payload}
223
+ if options[:dry_run]
224
+ print_dry_run @option_types_interface.dry.update(option_type['id'], payload)
225
+ return
226
+ end
227
+ json_response = @option_types_interface.update(option_type['id'], payload)
228
+ if options[:json]
229
+ print JSON.pretty_generate(json_response), "\n"
230
+ return
231
+ end
232
+ print_green_success "Updated Option Type #{option_type_payload['name']}"
233
+ #list([])
234
+ get([option_type['id']])
235
+ rescue RestClient::Exception => e
236
+ print_rest_exception(e, options)
237
+ exit 1
238
+ end
239
+ end
240
+
241
+ def remove(args)
242
+ options = {}
243
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
244
+ opts.banner = subcommand_usage("[name]")
245
+ build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
246
+ end
247
+ optparse.parse!(args)
248
+ if args.count < 1
249
+ puts optparse
250
+ exit 1
251
+ end
252
+ connect(options)
253
+
254
+ begin
255
+ option_type = find_option_type_by_name_or_id(args[0])
256
+ exit 1 if option_type.nil?
257
+
258
+ unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the option type #{option_type['name']}?", options)
259
+ exit
260
+ end
261
+ if options[:dry_run]
262
+ print_dry_run @option_types_interface.dry.destroy(option_type['id'])
263
+ return
264
+ end
265
+ json_response = @option_types_interface.destroy(option_type['id'])
266
+
267
+ if options[:json]
268
+ print JSON.pretty_generate(json_response), "\n"
269
+ return
270
+ end
271
+
272
+ print_green_success "Removed Option Type #{option_type['name']}"
273
+ #list([])
274
+ rescue RestClient::Exception => e
275
+ print_rest_exception(e, options)
276
+ exit 1
277
+ end
278
+ end
279
+
280
+
281
+ private
282
+
283
+ def find_instance_type_by_name_or_id(val)
284
+ if val.to_s =~ /\A\d{1,}\Z/
285
+ return find_instance_type_by_id(val)
286
+ else
287
+ return find_instance_type_by_name(val)
288
+ end
289
+ end
290
+
291
+ def find_instance_type_by_id(id)
292
+ begin
293
+ json_response = @library_instance_types_interface.get(id.to_i)
294
+ return json_response['instanceType']
295
+ rescue RestClient::Exception => e
296
+ if e.response && e.response.code == 404
297
+ print_red_alert "Instance Type not found by id #{id}"
298
+ else
299
+ raise e
300
+ end
301
+ end
302
+ end
303
+
304
+ def find_instance_type_by_name(name)
305
+ json_response = @library_instance_types_interface.list({name: name.to_s})
306
+ instance_types = json_response['instanceTypes']
307
+ if instance_types.empty?
308
+ print_red_alert "Instance Type not found by name #{name}"
309
+ return nil
310
+ elsif instance_types.size > 1
311
+ print_red_alert "#{instance_types.size} instance types found by name #{name}"
312
+ print_instance_types_table(instance_types, {color: red})
313
+ print_red_alert "Try using ID instead"
314
+ print reset,"\n"
315
+ return nil
316
+ else
317
+ return instance_types[0]
318
+ end
319
+ end
320
+
321
+ def print_instance_types_table(instance_types, opts={})
322
+ columns = [
323
+ {"ID" => lambda {|instance_type| instance_type['id'] } },
324
+ {"NAME" => lambda {|instance_type| instance_type['name'] } },
325
+ {"CODE" => lambda {|instance_type| instance_type['code'] } },
326
+ {"TECHNOLOGY" => lambda {|instance_type| format_instance_type_technology(instance_type) } },
327
+ {"CATEGORY" => lambda {|instance_type| instance_type['category'].to_s.capitalize } },
328
+ {"FEATURED" => lambda {|instance_type| format_boolean instance_type['featured'] } },
329
+ {"OWNER" => lambda {|instance_type| instance_type['account'] ? instance_type['account']['name'] : '' } },
330
+ ]
331
+ if opts[:include_fields]
332
+ columns = opts[:include_fields]
333
+ end
334
+ print as_pretty_table(instance_types, columns, opts)
335
+ end
336
+
337
+ def format_instance_type_technology(instance_type)
338
+ if instance_type
339
+ instance_type['provisionTypeCode'].to_s.capitalize
340
+ else
341
+ ""
342
+ end
343
+ end
344
+
345
+ def add_instance_type_option_types
346
+ [
347
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
348
+ {'fieldName' => 'code', 'fieldLabel' => 'Code', 'type' => 'text', 'required' => true, 'displayOrder' => 2, 'description' => 'Useful shortcode for provisioning naming schemes and export reference.'},
349
+ {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 3},
350
+ {'fieldName' => 'category', 'fieldLabel' => 'Category', 'type' => 'select', 'optionSource' => 'categories', 'required' => true, 'displayOrder' => 4},
351
+ {'fieldName' => 'logo', 'fieldLabel' => 'Icon File', 'type' => 'text', 'displayOrder' => 5},
352
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 6},
353
+ {'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.'},
354
+ {'fieldName' => 'hasSettings', 'fieldLabel' => 'Enable Settings', 'type' => 'checkbox', 'displayOrder' => 8},
355
+ {'fieldName' => 'hasAutoScale', 'fieldLabel' => 'Enable Scaling (Horizontal)', 'type' => 'checkbox', 'displayOrder' => 9},
356
+ {'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.'}
357
+ ]
358
+ end
359
+
360
+ def update_instance_type_option_types(instance_type=nil)
361
+ opts = add_instance_type_option_types
362
+ opts = opts.reject {|it| ["logo"].include? it['fieldName'] }
363
+ if instance_type
364
+ opts = add_instance_type_option_types
365
+ opts.find {|opt| opt['fieldName'] == 'name'}['defaultValue'] = instance_type['name']
366
+ end
367
+ opts
368
+ end
369
+
370
+ def load_balance_protocols
371
+ [
372
+ {'name' => 'None', 'value' => ''},
373
+ {'name' => 'HTTP', 'value' => 'HTTP'},
374
+ {'name' => 'HTTPS', 'value' => 'HTTPS'},
375
+ {'name' => 'TCP', 'value' => 'TCP'}
376
+ ]
377
+ end
378
+
379
+ # Prompts user for exposed ports array
380
+ # returns array of port objects
381
+ def prompt_exposed_ports(options={}, api_client=nil, api_params={})
382
+ #puts "Configure ports:"
383
+ no_prompt = (options[:no_prompt] || (options[:options] && options[:options][:no_prompt]))
384
+
385
+ ports = []
386
+ port_index = 0
387
+ has_another_port = options[:options] && options[:options]["exposedPort#{port_index}"]
388
+ add_another_port = has_another_port || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add an exposed port?"))
389
+ while add_another_port do
390
+ field_context = "exposedPort#{port_index}"
391
+
392
+ port = {}
393
+ #port['name'] ||= "Port #{port_index}"
394
+ port_label = port_index == 0 ? "Port" : "Port [#{port_index+1}]"
395
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "#{port_label} Name", 'required' => false, 'description' => 'Choose a name for this port.', 'defaultValue' => port['name']}], options[:options])
396
+ port['name'] = v_prompt[field_context]['name']
397
+
398
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'port', 'type' => 'number', 'fieldLabel' => "#{port_label} Number", 'required' => true, 'description' => 'A port number. eg. 8001', 'defaultValue' => (port['port'] ? port['port'].to_i : nil)}], options[:options])
399
+ port['port'] = v_prompt[field_context]['port']
400
+
401
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'loadBalanceProtocol', 'type' => 'select', 'fieldLabel' => "#{port_label} LB", 'selectOptions' => load_balance_protocols, 'required' => false, 'skipSingleOption' => true, 'description' => 'Choose a load balance protocol.', 'defaultValue' => port['loadBalanceProtocol']}], options[:options])
402
+ port['loadBalanceProtocol'] = v_prompt[field_context]['loadBalanceProtocol']
403
+
404
+ ports << port
405
+ port_index += 1
406
+ has_another_port = options[:options] && options[:options]["exposedPort#{port_index}"]
407
+ add_another_port = has_another_port || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another exposed port?"))
408
+
409
+ end
410
+
411
+
412
+ return ports
413
+ end
414
+
415
+ def find_option_type_by_name_or_id(val)
416
+ if val.to_s =~ /\A\d{1,}\Z/
417
+ return find_option_type_by_id(val)
418
+ else
419
+ return find_option_type_by_name(val)
420
+ end
421
+ end
422
+
423
+ def find_option_type_by_id(id)
424
+ begin
425
+ json_response = @option_types_interface.get(id.to_i)
426
+ return json_response['optionType']
427
+ rescue RestClient::Exception => e
428
+ if e.response && e.response.code == 404
429
+ print_red_alert "Option Type not found by id #{id}"
430
+ exit 1
431
+ else
432
+ raise e
433
+ end
434
+ end
435
+ end
436
+
437
+ def find_option_type_by_name(name)
438
+ json_results = @option_types_interface.list({name: name.to_s})
439
+ if json_results['optionTypes'].empty?
440
+ print_red_alert "Option Type not found by name #{name}"
441
+ exit 1
442
+ end
443
+ option_type = json_results['optionTypes'][0]
444
+ return option_type
445
+ end
446
+
447
+ # lol
448
+ def new_option_type_option_types
449
+ [
450
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
451
+ {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
452
+ {'fieldName' => 'fieldName', 'fieldLabel' => 'Field Name', 'type' => 'text', 'required' => true, 'description' => 'This is the input fieldName property that the value gets assigned to.', 'displayOrder' => 3},
453
+ {'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Text', 'value' => 'text'}, {'name' => 'Password', 'value' => 'password'}, {'name' => 'Number', 'value' => 'number'}, {'name' => 'Checkbox', 'value' => 'checkbox'}, {'name' => 'Select', 'value' => 'select'}, {'name' => 'Hidden', 'value' => 'hidden'}], 'defaultValue' => 'text', 'required' => true, 'displayOrder' => 4},
454
+ {'fieldName' => 'fieldLabel', 'fieldLabel' => 'Field Label', 'type' => 'text', 'required' => true, 'description' => 'This is the input label that shows typically to the left of a custom option.', 'displayOrder' => 5},
455
+ {'fieldName' => 'placeHolder', 'fieldLabel' => 'Placeholder', 'type' => 'text', 'displayOrder' => 6},
456
+ {'fieldName' => 'defaultValue', 'fieldLabel' => 'Default Value', 'type' => 'text', 'displayOrder' => 7},
457
+ {'fieldName' => 'required', 'fieldLabel' => 'Required', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 8},
458
+ ]
459
+ end
460
+
461
+ def update_option_type_option_types
462
+ list = new_option_type_option_types
463
+ list.each {|it|
464
+ it.delete('required')
465
+ it.delete('defaultValue')
466
+ it.delete('skipSingleOption')
467
+ }
468
+ list
469
+ end
470
+
471
+ # def find_option_type_list_by_name_or_id(val)
472
+ # if val.to_s =~ /\A\d{1,}\Z/
473
+ # return find_option_type_list_by_id(val)
474
+ # else
475
+ # return find_option_type_list_by_name(val)
476
+ # end
477
+ # end
478
+
479
+ # def find_option_type_list_by_id(id)
480
+ # begin
481
+ # json_response = @option_type_lists_interface.get(id.to_i)
482
+ # return json_response['optionTypeList']
483
+ # rescue RestClient::Exception => e
484
+ # if e.response && e.response.code == 404
485
+ # print_red_alert "Option List not found by id #{id}"
486
+ # exit 1
487
+ # else
488
+ # raise e
489
+ # end
490
+ # end
491
+ # end
492
+
493
+ # def find_option_type_list_by_name(name)
494
+ # json_results = @option_type_lists_interface.list({name: name.to_s})
495
+ # if json_results['optionTypeLists'].empty?
496
+ # print_red_alert "Option List not found by name #{name}"
497
+ # exit 1
498
+ # end
499
+ # option_type_list = json_results['optionTypeLists'][0]
500
+ # return option_type_list
501
+ # end
502
+
503
+ # def get_available_option_list_types
504
+ # [
505
+ # {'name' => 'Rest', 'value' => 'rest'},
506
+ # {'name' => 'Manual', 'value' => 'manual'}
507
+ # ]
508
+ # end
509
+
510
+ # def find_option_list_type(code)
511
+ # get_available_option_list_types.find {|it| code == it['value'] || code == it['name'] }
512
+ # end
513
+
514
+ # def new_option_type_list_option_types(list_type='rest')
515
+ # if list_type.to_s.downcase == 'rest'
516
+ # [
517
+ # {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
518
+ # {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
519
+ # #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
520
+ # {'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},
521
+ # {'fieldName' => 'ignoreSSLErrors', 'fieldLabel' => 'Ignore SSL Errors', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 5},
522
+ # {'fieldName' => 'sourceMethod', 'fieldLabel' => 'Source Method', 'type' => 'select', 'selectOptions' => [{'name' => 'GET', 'value' => 'GET'}, {'name' => 'POST', 'value' => 'POST'}], 'defaultValue' => 'GET', 'required' => true, 'displayOrder' => 6},
523
+ # {'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' => 7},
524
+ # {'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' => 8},
525
+ # ]
526
+ # elsif list_type.to_s.downcase == 'manual'
527
+ # [
528
+ # {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
529
+ # {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
530
+ # #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
531
+ # {'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},
532
+ # ]
533
+ # else
534
+ # print_red_alert "Unknown Option List type '#{list_type}'"
535
+ # exit 1
536
+ # end
537
+ # end
538
+
539
+ # def update_option_type_list_option_types(list_type='rest')
540
+ # list = new_option_type_list_option_types(list_type)
541
+ # list.each {|it|
542
+ # it.delete('required')
543
+ # it.delete('defaultValue')
544
+ # it.delete('skipSingleOption')
545
+ # }
546
+ # list
547
+ # end
548
+
549
+ end