Class: Morpheus::Cli::LibraryOperatingSystemsCommand

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

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from WhoamiHelper

#current_account, #current_user, #current_user_permissions, included, #is_master_account, #load_whoami

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

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_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, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #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

#initializeLibraryOperatingSystemsCommand

Returns a new instance of LibraryOperatingSystemsCommand.



12
13
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 12

def initialize()
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
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 112

def _get(id, options)
  begin
    @library_operating_systems_interface.setopts(options)

    if options[:dry_run]
        print_dry_run @library_operating_systems_interface.dry.get(id)
      return
    end
    os_type = find_os_type_by_id(id)
    if os_type.nil?
      return 1
    end

    json_response = {'osType' => os_type}

    if options[:json]
      puts as_json(json_response, options, "osType")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "osType")
      return 0
    elsif options[:csv]
      puts records_as_csv([json_response['osType']], options)
      return 0
    end

    print_h1 "OsType Details"
    print cyan
    description_cols = {
      "ID" => lambda {|it| it['id'] },
      "Name" => lambda {|it| it['name'] },
      "Code" => lambda {|it| it['code']},
      "Platform" => lambda {|it| it['platform']},
      "Category" => lambda {|it|it['category']},
      "Vendor" => lambda {|it| it['vendor']},
      "Family" => lambda {|it| it['osFamily']},
      "Os Name" => lambda {|it| it['osName'] },
      "Install Agent" => lambda {|it| format_boolean(it['installAgent'])},
      "Bit Count" => lambda {|it| it['bitCount'] },
      "Owner" => lambda { |it| it['owner']}
    }
    if 
      description_cols["Visibility"] = lambda {|it| it['visibility']}
    end

    print_description_list(description_cols, os_type)
    title = "OsType - Images"
    print_h2 title
      if os_type['images'].empty?
        print cyan,"No images found.",reset,"\n"
      else
        rows = os_type['images'].collect do |image|
          {
              id: image['id'],
              virtual_image_id: image['virtualImageId'],
              virtual_image_name: image['virtualImageName'],
              account: image['account'],
              cloud: image['zone']
          }
        end
        print as_pretty_table(rows, [:id, :virtual_image_id, :virtual_image_name, :account, :cloud], options)
      end

    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#_get_image(id) ⇒ Object



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
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 205

def _get_image(id)
  begin
    image = find_os_type_image_by_id(id)

    if image.nil?
      return 1
    end

    json_response = {'osTypeImage' => image}
  
    
    print_h1 "OsTypeImage Details"
    print cyan
    description_cols = {
      "ID" => lambda {|it| it['id'] },
      "VirtualImage ID" => lambda {|it| it['virtualImageId'] },
      "VirtualImage Name" => lambda {|it| it['virtualImageName'] },
      "Account" => lambda {|it| it['account']},
      "Provision Type" => lambda {|it| it['provisionType']},
      "Cloud" => lambda {|it|it['zone']}
    }

    print_description_list(description_cols, image)

    print reset,"\n"
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#add(args) ⇒ Object



237
238
239
240
241
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
341
342
343
344
345
346
347
348
349
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 237

def add(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name] [options]")
    opts.on('-n', '--name VALUE', String, "Name of OsType") do |val|
      params['name'] = val
    end
    opts.on('-c', '--code VALUE', String, "Code of OsType") do |val|
      params['code'] = val
    end
    opts.on('-p', '--platform VALUE', String, "Platform of OsType") do |val|
      params['platform'] = val
    end
    opts.on('-v', '--vendor VALUE', String, "Vendor of OsType") do |val|
      params['vendor'] = val
    end
    opts.on('-ca', '--category VALUE', String, "Category of OsType") do |val|
      params['category'] = val
    end
    opts.on('-o', '--osName VALUE', String, "OsName of OsType") do |val|
      params['osName'] = val
    end
    opts.on('-ov', '--osVersion VALUE', String, "OsVersion of OsType") do |val|
      params['osVersion'] = val
    end
    opts.on('-oc', '--osCodename VALUE', String, "OsCodename of OsType") do |val|
      params['osCodename'] = val
    end
    opts.on('-of', '--osFamily VALUE', String, "OsFamily of OsType") do |val|
      params['osFamily'] = val
    end
    opts.on('-b', '--bitCount VALUE', Integer, "BitCount of OsType") do |val|
      params['bitCount'] = val
    end
    opts.on('-i', '--cloudInitVersion VALUE', Integer, "CloudInitVersion of OsType") do |val|
      params['cloudInitVersion'] = val
    end
    opts.on('-d', '--description VALUE', String, "Description of OsType") do |val|
      params['description'] = val
    end
    opts.on('--install-agent [on|off]', String, "Install Agent? Pass true to install agent. Default is false.") do |val|
      params['installAgent'] = !['false','off','0'].include?(val.to_s)
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Create an OsType."
  end
  optparse.parse!(args)
  connect(options)
  if args.count > 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
    return 1
  end

  begin
    if options[:payload]
      payload = options[:payload]
    else
      # support the old -O OPTION switch
      params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
      
      # prompt for options
      prompt_if_nil(params, options, 'name', 'Name', true)
      prompt_if_nil(params, options, 'code', 'Code', true)
      prompt_if_nil(params, options, 'description', 'Description')
      prompt_if_nil(params, options, 'category', 'Category')

      if params['platform'].nil?
          v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'platform', 'fieldLabel' => 'Platform', 'type' => 'select', 'optionSource' => 'platforms', 'description' => 'Platform', 'required' => true}], options, @api_client, {})
          params['platform'] = v_prompt['platform']
      end

      prompt_if_nil(params, options, 'vendor', 'Vendor')
      prompt_if_nil(params, options, 'osName', 'OsName')
      prompt_if_nil(params, options, 'osVersion', 'OsVersion')
      prompt_if_nil(params, options, 'osCodename', 'OsCodename')
      prompt_if_nil(params, options, 'osFamily', 'OsFamily')

      if params['bitCount'].nil?
        params['bitCount'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'bitCount', 'type' => 'number', 'fieldLabel' => 'BitCount', 'required' => true, 'description' => 'BitCount.'}],options[:options],@api_client,{})['bitCount']
      end

      if params['cloudInitVersion'].nil?
        params['cloudInitVersion'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloudInitVersion', 'type' => 'number', 'fieldLabel' => 'CloudInitVersion', 'required' => false, 'description' => 'CloudInitVersion.'}],options[:options],@api_client,{})['cloudInitVersion']
      end

      if params['installAgent'].nil?
         params['installAgent'] = Morpheus::Cli::OptionTypes.confirm("Install Agent?", {:default => false})
      end

      payload = {'osType' => params}
    end

    @library_operating_systems_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_operating_systems_interface.dry.create(payload)
      return
    end

    json_response = @library_operating_systems_interface.create(payload)

    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return
    end
    print_green_success "Added Os Type"
    _get(json_response['id'], {})
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#add_image(args) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
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
520
521
522
523
524
525
526
527
528
529
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 452

def add_image(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[name] [options]")
    opts.on('-o', '--osType VALUE', String, "Id of OsType") do |val|
      params['osType'] = val
    end
    opts.on('-v', '--virtualImage VALUE', String, "Id of Virtual Image") do |val|
      params['virtualImage'] = val
    end
    opts.on('-p', '--provisionType VALUE', String, "Provision Type") do |val|
      params['provisionType'] = val
    end
    opts.on('-z', '--zone VALUE', String, "Zone") do |val|
      params['zone'] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Create an OsType Image."
  end
  optparse.parse!(args)
  connect(options)
  if args.count > 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
    return 1
  end
  if args[0]
    params['osType'] = args[0]
  end
  begin
    if options[:payload]
      payload = options[:payload]
    else
      # support the old -O OPTION switch
      params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
      
      # prompt for options
      if params['osType'].nil?
          params['osType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'osType', 'type' => 'select', 'fieldLabel' => 'Os Type', 'required' => true, 'optionSource' => 'osTypes'}], options[:options], @api_client,{})['osType']
      end

      if params['provisionType'].nil?
          params['provisionType'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'provisionType', 'type' => 'select', 'fieldLabel' => 'Provision Type', 'required' => false, 'optionSource' => 'provisionTypes'}], options[:options], @api_client,{'cli' => true})['provisionType']
      end

      if params['zone'].nil?
          params['zone'] = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'zone', 'type' => 'select', 'fieldLabel' => 'Cloud', 'required' => false, 'optionSource' => 'clouds'}], options[:options], @api_client,{'provisionTypeIds' => params['provisionType']})['zone']
      end

      if params['virtualImage'].nil?
          virtual_image = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'virtualImage', 'fieldLabel' => 'Virtual Image', 'type' => 'select', 'required' => true, 'optionSource' => 'osTypeVirtualImage'}], options[:options], @api_client, {'osTypeImage' => params})['virtualImage']

          params['virtualImage'] = virtual_image
      end

      payload = {'osTypeImage' => params}
    end

    @library_operating_systems_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_operating_systems_interface.dry.create_image(payload)
      return
    end

    json_response = @library_operating_systems_interface.create_image(payload)

    if options[:json]
      print JSON.pretty_generate(json_response), "\n"
      return
    end
    print_green_success "Added Os Type Image"
    _get_image(json_response['id'])
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



15
16
17
18
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 15

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @library_operating_systems_interface = @api_client.library_operating_systems
end

#get(args) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 89

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[osType]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Display osType details." + "\n" +
                  "[osType] is required. This is the id of an osType."
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return 1
  end
  connect(options)
  id_list = parse_id_list(args)
  id_list.each do |id|

  end
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, options)
  end
end

#get_image(args) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 182

def get_image(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[osTypeImage]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Display osTypeImage details." + "\n" +
                  "[osTypeImage] is required. This is the id of an osTypeImage."
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return 1
  end
  connect(options)
  id_list = parse_id_list(args)
  id_list.each do |id|

  end
  return run_command_for_each_arg(id_list) do |arg|
    _get_image(arg)
  end
end

#handle(args) ⇒ Object



20
21
22
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 20

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



24
25
26
27
28
29
30
31
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
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 24

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List os 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_operating_systems_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_operating_systems_interface.dry.list_os_types(params)
      return
    end
    # do it
    json_response = @library_operating_systems_interface.list_os_types(params)
    # print and/or return result
    # return 0 if options[:quiet]
    if options[:json]
      puts as_json(json_response, options, "osTypes")
      return 0
    elsif options[:csv]
      puts records_as_csv(json_response['osTypes'], options)
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "osTypes")
      return 0
    end
    os_types = json_response['osTypes']
    title = "Morpheus Library - OS Types"
    subtitles = parse_list_subtitles(options)
    print_h1 title, subtitles
    if os_types.empty?
      print cyan,"No os types found.",reset,"\n"
    else
      rows = os_types.collect do |os_type|
        {
            id: os_type['id'],
            name: os_type['name'],
            code: os_type['code'],
            platform: os_type['platform'],
            vendor: os_type['vendor'],
            category: os_type['category'],
            family: os_type['osFamily'],
            owner: os_type['owner']['name'] ? os_type['owner']['name'] : 'System'
        }
      end
      print as_pretty_table(rows, [:id, :name, :code, :platform, :vendor, :category, :family, :owner], options)
      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



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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 531

def remove(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[osType]")
    build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
    opts.footer = "Delete an Os Type." + "\n" +
                  "[osType] is required. This is the id of an osType."
  end
  optparse.parse!(args)

  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
    return 1
  end

  connect(options)

  begin
    os_type = find_os_type_by_id(args[0])
    if os_type.nil?
      return 1
    end

    unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the OsType?", options)
      exit
    end

    @library_operating_systems_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_operating_systems_interface.dry.destroy(os_type['id'])
      return
    end
    json_response = @library_operating_systems_interface.destroy(os_type['id'])

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      if json_response['success']
        print_green_success "Removed the OsType"
      else
        print_red_alert "Error removing osType: #{json_response['msg'] || json_response['errors']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#remove_image(args) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 584

def remove_image(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage("[osTypeImage]")
    build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
    opts.footer = "Delete an Os Type Image." + "\n" +
                  "[osTypeImage] is required. This is the id of an osTypeImage."
  end
  optparse.parse!(args)

  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
    return 1
  end

  connect(options)

  begin
    os_type_image = find_os_type_image_by_id(args[0])
    if os_type_image.nil?
      return 1
    end

    unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the OsTypeImage?", options)
      exit
    end

    @library_operating_systems_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @library_operating_systems_interface.dry.destroy_image(os_type_image['id'])
      return
    end
    json_response = @library_operating_systems_interface.destroy_image(os_type_image['id'])

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      if json_response['success']
        print_green_success "Removed the OsTypeImage"
      else
        print_red_alert "Error removing osTypeImage: #{json_response['msg'] || json_response['errors']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update(args) ⇒ Object



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
420
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
# File 'lib/morpheus/cli/commands/library_operating_systems_command.rb', line 352

def update(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[osType] [options]")
    opts.on('-n', '--name VALUE', String, "Name of OsType") do |val|
      params['name'] = val
    end
    opts.on('-c', '--code VALUE', String, "Code of OsType") do |val|
      params['code'] = val
    end
    opts.on('-p', '--platform VALUE', String, "Platform of OsType") do |val|
      params['platform'] = val
    end
    opts.on('-v', '--vendor VALUE', String, "Vendor of OsType") do |val|
      params['vendor'] = val
    end
    opts.on('-ca', '--category VALUE', String, "Category of OsType") do |val|
      params['category'] = val
    end
    opts.on('-o', '--osName VALUE', String, "OsName of OsType") do |val|
      params['osName'] = val
    end
    opts.on('-ov', '--osVersion VALUE', String, "OsVersion of OsType") do |val|
      params['osVersion'] = val
    end
    opts.on('-oc', '--osCodename VALUE', String, "OsCodename of OsType") do |val|
      params['osCodename'] = val
    end
    opts.on('-of', '--osFamily VALUE', String, "OsFamily of OsType") do |val|
      params['osFamily'] = val
    end
    opts.on('-b', '--bitCount VALUE', Integer, "BitCount of OsType") do |val|
      params['bitCount'] = val
    end
    opts.on('-i', '--cloudInitVersion VALUE', Integer, "CloudInitVersion of OsType") do |val|
      params['cloudInitVersion'] = val
    end
    opts.on('-d', '--description VALUE', String, "Description of OsType") do |val|
      params['description'] = val
    end
    opts.on('--install-agent [on|off]', String, "Install Agent? Pass true to install agent. Default is false.") do |val|
      params['installAgent'] = !['false','off','0'].include?(val.to_s)
    end

    build_common_options(opts, options, [:options, :json, :dry_run, :remote])
    opts.footer = "Update an osType." + "\n" +
                  "[osType] is required. This is the id of an osType."
  end
  optparse.parse!(args)
  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
    return 1
  end
  connect(options)

  begin
    os_type = find_os_type_by_id(args[0])
    return 1 if os_type.nil?
    
    payload = {
      'osType' => {}
    }

    # no prompting, just collect all user passed options
    params.deep_merge!(options.reject {|k,v| k.is_a?(Symbol) })
    params.deep_merge!(options[:options]) if options[:options]

    if params.empty?
      print_error Morpheus::Terminal.angry_prompt
      puts_error  "Specify at least one option to update\n#{optparse}"
      return 1
    end
    payload['osType'].deep_merge!(params)


    @library_operating_systems_interface.setopts(options)
    if options[:dry_run]
        print_dry_run @library_operating_systems_interface.dry.update(os_type["id"], payload)
      return
    end

    json_response = @library_operating_systems_interface.update(os_type["id"], payload)

    if options[:json]
      puts as_json(json_response)
    else
      print_green_success "Updated osType #{os_type['id']}"
      get([os_type['id']])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end