Class: Morpheus::Cli::LibraryInstanceTypesCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, LibraryHelper
Defined in:
lib/morpheus/cli/library_instance_types_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from LibraryHelper

#api_client, #find_container_type_by_id, #find_container_type_by_name, #find_container_type_by_name_or_id, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_option_type_by_id, #find_option_type_by_name, #find_option_type_by_name_or_id, #find_option_type_list_by_id, #find_option_type_list_by_name, #find_option_type_list_by_name_or_id, #find_spec_template_by_id, #find_spec_template_by_name, #find_spec_template_by_name_or_id, #find_spec_template_type_by_id, #find_spec_template_type_by_name_or_code, #find_spec_template_type_by_name_or_code_id, #format_container_type_technology, #format_instance_type_technology, #get_all_spec_template_types, included, #load_balance_protocols_dropdown, #print_container_types_table, #print_instance_types_table, #print_resource_specs_table, #prompt_exposed_ports, #prompt_for_container_types, #prompt_for_option_types, #prompt_for_spec_templates

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Constructor Details

#initializeLibraryInstanceTypesCommand

Returns a new instance of LibraryInstanceTypesCommand.



16
17
18
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 16

def initialize()
  # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end

Instance Method Details

#_get(id, options) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 112

def _get(id, options)

  begin
    instance_type = find_instance_type_by_name_or_id(id)
    if instance_type.nil?
      return 1
    end
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.get(instance_type['id'])
      return
    end
    json_response = nil
    if id.to_s =~ /\A\d{1,}\Z/
      json_response = {'instanceType' => instance_type}
    else
      json_response = @library_instance_types_interface.get(instance_type['id'])
      instance_type = json_response['instanceType']
    end
    
    if options[:json]
      puts as_json(json_response, options, "instanceType")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "instanceType")
      return 0
    elsif options[:csv]
      puts records_as_csv([json_response['instanceType']], options)
      return 0
    end

    print_h1 "Instance Type Details"
    print cyan
    description_cols = {
      "ID" => lambda {|it| it['id'] },
      "Name" => lambda {|it| it['name'] },
      "Code" => lambda {|it| it['code'] },
      "Description" => lambda {|it| it['description'] },
      "Technology" => lambda {|it| format_instance_type_technology(it) },
      "Category" => lambda {|it| it['category'].to_s.capitalize },
      # "Logo" => lambda {|it| it['logo'].to_s },
      "Visiblity" => lambda {|it| it['visibility'].to_s.capitalize },
      "Environment Prefix" => lambda {|it| it['environmentPrefix'] },
      "Enable Settings" => lambda {|it| format_boolean it['hasSettings'] },
      "Enable Scaling" => lambda {|it| format_boolean it['hasAutoScale'] },
      "Supports Deployments" => lambda {|it| format_boolean it['hasDeployment'] },
      "Featured" => lambda {|it| format_boolean it['featured'] },
      "Owner" => lambda {|it| it['account'] ? it['account']['name'] : '' },
      # "Active" => lambda {|it| format_boolean it['active'] },
      # "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
      # "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
    }
    print_description_list(description_cols, instance_type)

    instance_type_option_types = instance_type['optionTypes']
    if instance_type_option_types && instance_type_option_types.size > 0
      print_h2 "Option Types"
      columns = [
        {"ID" => lambda {|it| it['id'] } },
        {"NAME" => lambda {|it| it['name'] } },
        {"TYPE" => lambda {|it| it['type'] } },
        {"FIELD NAME" => lambda {|it| it['fieldName'] } },
        {"FIELD LABEL" => lambda {|it| it['fieldLabel'] } },
        {"DEFAULT" => lambda {|it| it['defaultValue'] } },
        {"REQUIRED" => lambda {|it| format_boolean it['required'] } },
      ]
      print as_pretty_table(instance_type_option_types, columns)
    else
      # print cyan,"No option types found for this layout.","\n",reset
    end

    instance_type_evars = instance_type['environmentVariables']
    if instance_type_evars && instance_type_evars.size > 0
      print_h2 "Environment Variables"
      evar_columns = [
        {"NAME" => lambda {|it| it['name'] } },
        {"VALUE" => lambda {|it| it['defaultValue'] } },
        {"TYPE" => lambda {|it| it['valueType'].to_s.capitalize } },
        {"EXPORT" => lambda {|it| format_boolean it['export'] } },
        {"MASKED" => lambda {|it| format_boolean it['mask'] } },
      ]
      print as_pretty_table(instance_type_evars, evar_columns)
    else
      # print cyan,"No environment variables found for this instance type.","\n",reset
    end

    print_h2 "Layouts"

    instance_type_layouts = instance_type['instanceTypeLayouts']
    
    if instance_type_layouts && instance_type_layouts.size > 0
      # match UI sorting [version desc, name asc]
      # or use something simpler like one of these
      # instance_type_layouts = instance_type_layouts.sort { |a,b| a['name'] <=> b['name'] }
      # instance_type_layouts = instance_type_layouts.sort { |a,b| a['sortOrder'] <=> b['sortOrder'] }
      instance_type_layouts = instance_type_layouts.sort do |a,b|
        a_array = a['instanceVersion'].to_s.split('.').collect {|vn| vn.to_i * -1 }
        while a_array.size < 5
          a_array << 0
        end
        a_array << a['name']
        b_array = b['instanceVersion'].to_s.split('.').collect {|vn| vn.to_i * -1 }
        while b_array.size < 5
          b_array << 0
        end
        b_array << b['name']
        a_array <=> b_array
      end
      layout_columns = [
        {"ID" => lambda {|layout| layout['id'] } },
        {"NAME" => lambda {|layout| layout['name'] } },
        {"VERSION" => lambda {|layout| layout['instanceVersion'] } },
        {"TECHNOLOGY" => lambda {|layout| 
          layout['provisionType'] ? layout['provisionType']['name'] : ''
        } },
        {"DESCRIPTION" => lambda {|layout| layout['description'] } }
      ]
      print as_pretty_table(instance_type_layouts, layout_columns)
    else
      print cyan,"No layouts found for this instance type.","\n",reset
    end

    print reset,"\n"

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#add(args) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 242

def add(args)
  options = {}
  params = {}
  logo_file = nil
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name]")
    build_option_type_options(opts, options, add_instance_type_option_types())
    opts.on('--option-types [x,y,z]', Array, "List of Option Type IDs") do |list|
      if list.nil?
        params['optionTypes'] = []
      else
        params['optionTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Create a new instance type."
  end
  optparse.parse!(args)
  if args.count > 1
    raise_command_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args}\n#{optparse}"
  end
  if args[0]
    #params["name"] = args[0]
    options[:options]["name"] = args[0]
  end
  connect(options)
  begin
    passed_options = (options[:options] || {}).reject {|k,v| k.is_a?(Symbol) }
    payload = nil
    if options[:payload]
      payload = options[:payload]
      # merge -O options
      payload.deep_merge!({'instanceType' => passed_options}) unless passed_options.empty?
    else
      # merge -O options
      params.deep_merge!(passed_options) unless passed_options.empty?
      # prompt
      v_prompt = Morpheus::Cli::OptionTypes.prompt(add_instance_type_option_types, options[:options], @api_client, options[:params])
      params.deep_merge!(v_prompt)
      if params['logo']
        filename = File.expand_path(params['logo'])
        if !File.exists?(filename)
          print_red_alert "File not found: #{filename}"
          exit 1
        end
        logo_file = File.new(filename, 'rb')
        params.delete('logo')
      end
      params['hasSettings'] = ['on','true','1'].include?(params['hasSettings'].to_s) if params.key?('hasSettings')
      params['hasAutoScale'] = ['on','true','1'].include?(params['hasAutoScale'].to_s) if params.key?('hasAutoScale')
      params['hasDeployment'] = ['on','true','1'].include?(params['hasDeployment'].to_s) if params.key?('hasDeployment')

      # OPTION TYPES
      if params['optionTypes']
        prompt_results = prompt_for_option_types(params, options, @api_client)
        if prompt_results[:success]
          params['optionTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
        else
          return 1
        end
      end

      payload = {instanceType: params}
      @library_instance_types_interface.setopts(options)
      if options[:dry_run]
        print_dry_run @library_instance_types_interface.dry.create(payload)
        if logo_file
          print_dry_run @library_instance_types_interface.dry.(":id", logo_file)
        end
        return
      end
    end

    json_response = @library_instance_types_interface.create(payload)

    if json_response['success']
      if logo_file
        begin
          @library_instance_types_interface.(json_response['instanceType']['id'], logo_file)
        rescue RestClient::Exception => e
          print_red_alert "Failed to save logo!"
          print_rest_exception(e, options)
        end
      end
    end

    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return
    end

    print_green_success "Added Instance Type #{params['name']}"
    _get(json_response['instanceType']['id'], options)
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#connect(opts) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 20

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @library_instance_types_interface = @api_client.library_instance_types
  @provision_types_interface = @api_client.provision_types
  @option_types_interface = @api_client.option_types
  @option_type_lists_interface = @api_client.option_type_lists
end

#get(args) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 94

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return 1
  end
  connect(options)
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, options)
  end
end

#handle(args) ⇒ Object



28
29
30
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 28

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 32

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on('--category VALUE', String, "Filter by category") do |val|
      params['category'] = val
    end
    opts.on('--code VALUE', String, "Filter by code") do |val|
      params['code'] = val
    end
    opts.on('--technology VALUE', String, "Filter by technology") do |val|
      params['provisionTypeCode'] = val
    end
    build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List instance types."
  end
  optparse.parse!(args)
  # verify_args!(args:args, optparse:optparse, count:0)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  connect(options)
  begin
    # construct payload
    params.merge!(parse_list_options(options))
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.list(params)
      return
    end
    # do it
    json_response = @library_instance_types_interface.list(params)
    if options[:json]
      puts as_json(json_response, options, "instanceTypes")
      return 0
    elsif options[:csv]
      puts records_as_csv(json_response['instanceTypes'], options)
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "instanceTypes")
      return 0
    end
    instance_types = json_response['instanceTypes']
    title = "Morpheus Library - Instance Types"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles
    if instance_types.empty?
      print cyan,"No instance types found.",reset,"\n"
    else
      print_instance_types_table(instance_types, options)
      print_results_pagination(json_response, {:label => "instance type", :n_label => "instance types"})
      # print_results_pagination(json_response)
    end
    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#remove(args) ⇒ Object



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 521

def remove(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
    opts.footer = "Delete an instance type."
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)

  begin
    instance_type = find_instance_type_by_name_or_id(args[0])
    exit 1 if instance_type.nil?

    unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the instance type #{instance_type['name']}?", options)
      exit
    end
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.destroy(instance_type['id'])
      return
    end
    json_response = @library_instance_types_interface.destroy(instance_type['id'])

    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return
    end

    print_green_success "Removed Instance Type #{instance_type['name']}"
    #list([])
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end


421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 421

def toggle_featured(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name] [options]")
    # opts.on('--featured [on|off]', String, "Featured flag") do |val|
    #   params['featured'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
    # end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Toggle featured flag for an instance type." + "\n" +
                  "[name] is required. This is the name or id of a instance type."
  end
  optparse.parse!(args)
  if args.count < 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
  end
  connect(options)
  begin
    instance_type = find_instance_type_by_name_or_id(args[0])
    return 1 if instance_type.nil?
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      instance_type_payload = {}
      instance_type_payload.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
      payload = {'instanceType' => instance_type_payload}
    end
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.toggle_featured(instance_type['id'], params, payload)
      return 0
    end
    
    json_response = @library_instance_types_interface.toggle_featured(instance_type['id'], params, payload)
    
    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return 0
    end
    print_green_success "Updated Instance Type #{params['name'] || instance_type['name']}"
    _get(instance_type['id'], options)
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#update(args) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 342

def update(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name] [options]")
    build_option_type_options(opts, options, update_instance_type_option_types())
    build_common_options(opts, options, [:options, :json, :dry_run, :remote])
    opts.on('--option-types [x,y,z]', Array, "List of Option Type IDs") do |list|
      if list.nil?
        params['optionTypes'] = []
      else
        params['optionTypes'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.footer = "Update an instance type." + "\n" +
                  "[name] is required. This is the name or id of a instance type."
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  begin
    instance_type = find_instance_type_by_name_or_id(args[0])
    exit 1 if instance_type.nil?
    passed_options = (options[:options] || {}).reject {|k,v| k.is_a?(Symbol) }
    payload = nil
    if options[:payload]
      payload = options[:payload]
      # merge -O options
      payload.deep_merge!({'instanceType' => passed_options}) unless passed_options.empty?
    else
      # merge -O options
      params.deep_merge!(passed_options) unless passed_options.empty?
      # option_types = update_instance_type_option_types(instance_type)
      # params = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
      params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
      params['hasSettings'] = ['on','true','1'].include?(params['hasSettings'].to_s) if params.key?('hasSettings')
      params['hasAutoScale'] = ['on','true','1'].include?(params['hasAutoScale'].to_s) if params.key?('hasAutoScale')
      params['hasDeployment'] = ['on','true','1'].include?(params['hasDeployment'].to_s) if params.key?('hasDeployment')
      if params['optionTypes']
        prompt_results = prompt_for_option_types(params, options, @api_client)
        if prompt_results[:success]
          params['optionTypes'] = prompt_results[:data] unless prompt_results[:data].nil?
        else
          return 1
        end
      end
      if params.empty?
        puts optparse
        #option_lines = update_instance_type_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
        #puts "\nAvailable Options:\n#{option_lines}\n\n"
        exit 1
      end
      payload = {'instanceType' => params}
    end
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.update(instance_type['id'], payload)
      return 0
    end
    
    json_response = @library_instance_types_interface.update(instance_type['id'], payload)
    
    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return 0
    end

    print_green_success "Updated Instance Type #{params['name'] || instance_type['name']}"
    _get(json_response['instanceType']['id'], options)
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#update_logo(args) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/morpheus/cli/library_instance_types_command.rb', line 470

def (args)
  options = {}
  params = {}
  filename = nil
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name] [file]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Update the logo for an instance type." + "\n" +
                  "[name] is required. This is the name or id of a instance type." + "\n" +
                  "[file] is required. This is the path of the logo file"
  end
  optparse.parse!(args)
  if args.count < 2
    puts optparse
    exit 1
  end
  connect(options)
  layout_id = args[0]
  filename = args[1]
  begin
    instance_type = find_instance_type_by_name_or_id(layout_id)
    exit 1 if instance_type.nil?
    logo_file = nil
    if filename == 'null'
      filename = 'null' # clear it
    else
      filename = File.expand_path(filename)
      if !File.exists?(filename)
        print_red_alert "File not found: #{filename}"
        exit 1
      end
      logo_file = File.new(filename, 'rb')
    end
    @library_instance_types_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_instance_types_interface.dry.(instance_type['id'], logo_file)
      return
    end
    json_response = @library_instance_types_interface.(instance_type['id'], logo_file)
    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return 0
    end
    print_green_success "Updated Instance Type #{instance_type['name']} logo"
    _get(instance_type['id'], options)
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end